pass clippy
This commit is contained in:
1 parent
dd7784d205
commit
5d5e7f55fd
3 files changed
+53
-52
No files matched your search
@@ -198,7 +198,7 @@ impl PersistantElementIter {
|
|||||||
} else {
|
} else {
|
||||||
*o_child_idx = o_child_idx.map(|i| i - 1);
|
*o_child_idx = o_child_idx.map(|i| i - 1);
|
||||||
if let NodePosition::InChild(child_idx) = o_child_idx {
|
if let NodePosition::InChild(child_idx) = o_child_idx {
|
||||||
if *child_idx >= children.len() || children.len() == 0 {
|
if *child_idx >= children.len() || children.is_empty() {
|
||||||
self.pop();
|
self.pop();
|
||||||
self.prev(rdom)
|
self.prev(rdom)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+50
-47
@@ -4,7 +4,7 @@ use dioxus_core::ElementId;
|
|||||||
use dioxus_native_core::utils::{ElementProduced, PersistantElementIter};
|
use dioxus_native_core::utils::{ElementProduced, PersistantElementIter};
|
||||||
use dioxus_native_core_macro::sorted_str_slice;
|
use dioxus_native_core_macro::sorted_str_slice;
|
||||||
|
|
||||||
use std::num::NonZeroU16;
|
use std::{cmp::Ordering, num::NonZeroU16};
|
||||||
|
|
||||||
use dioxus_native_core::{
|
use dioxus_native_core::{
|
||||||
node_ref::{AttributeMask, NodeMask, NodeView},
|
node_ref::{AttributeMask, NodeMask, NodeView},
|
||||||
@@ -12,7 +12,7 @@ use dioxus_native_core::{
|
|||||||
state::NodeDepState,
|
state::NodeDepState,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
pub(crate) enum FocusLevel {
|
pub(crate) enum FocusLevel {
|
||||||
Unfocusable,
|
Unfocusable,
|
||||||
Focusable,
|
Focusable,
|
||||||
@@ -45,6 +45,12 @@ impl PartialOrd for FocusLevel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ord for FocusLevel {
|
||||||
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
|
self.partial_cmp(other).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for FocusLevel {
|
impl Default for FocusLevel {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
FocusLevel::Unfocusable
|
FocusLevel::Unfocusable
|
||||||
@@ -70,26 +76,24 @@ impl NodeDepState for Focus {
|
|||||||
.any(|a| a.name == "dioxus-prevent-default" && a.value.trim() == "keydown"),
|
.any(|a| a.name == "dioxus-prevent-default" && a.value.trim() == "keydown"),
|
||||||
level: if let Some(a) = node.attributes().find(|a| a.name == "tabindex") {
|
level: if let Some(a) = node.attributes().find(|a| a.name == "tabindex") {
|
||||||
if let Ok(index) = a.value.parse::<i32>() {
|
if let Ok(index) = a.value.parse::<i32>() {
|
||||||
if index < 0 {
|
match index.cmp(&0) {
|
||||||
FocusLevel::Unfocusable
|
Ordering::Less => FocusLevel::Unfocusable,
|
||||||
} else if index == 0 {
|
Ordering::Equal => FocusLevel::Focusable,
|
||||||
FocusLevel::Focusable
|
Ordering::Greater => {
|
||||||
} else {
|
FocusLevel::Ordered(NonZeroU16::new(index as u16).unwrap())
|
||||||
FocusLevel::Ordered(NonZeroU16::new(index as u16).unwrap())
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FocusLevel::Unfocusable
|
FocusLevel::Unfocusable
|
||||||
}
|
}
|
||||||
|
} else if node
|
||||||
|
.listeners()
|
||||||
|
.iter()
|
||||||
|
.any(|l| FOCUS_EVENTS.binary_search(&l.event).is_ok())
|
||||||
|
{
|
||||||
|
FocusLevel::Focusable
|
||||||
} else {
|
} else {
|
||||||
if node
|
FocusLevel::Unfocusable
|
||||||
.listeners()
|
|
||||||
.iter()
|
|
||||||
.any(|l| FOCUS_EVENTS.binary_search(&l.event).is_ok())
|
|
||||||
{
|
|
||||||
FocusLevel::Focusable
|
|
||||||
} else {
|
|
||||||
FocusLevel::Unfocusable
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if *self != new {
|
if *self != new {
|
||||||
@@ -127,9 +131,9 @@ impl FocusState {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let new = if forward {
|
let new = if forward {
|
||||||
self.focus_iter.next(&rdom)
|
self.focus_iter.next(rdom)
|
||||||
} else {
|
} else {
|
||||||
self.focus_iter.prev(&rdom)
|
self.focus_iter.prev(rdom)
|
||||||
};
|
};
|
||||||
let new_id = new.id();
|
let new_id = new.id();
|
||||||
if let ElementProduced::Looped(_) = new {
|
if let ElementProduced::Looped(_) = new {
|
||||||
@@ -139,15 +143,16 @@ impl FocusState {
|
|||||||
// find the closest focusable element after the current level
|
// find the closest focusable element after the current level
|
||||||
rdom.traverse_depth_first(|n| {
|
rdom.traverse_depth_first(|n| {
|
||||||
let node_level = n.state.focus.level;
|
let node_level = n.state.focus.level;
|
||||||
if node_level != *focus_level && node_level.focusable() {
|
if node_level != *focus_level
|
||||||
if node_level > *focus_level {
|
&& node_level.focusable()
|
||||||
if let Some(level) = &mut closest_level {
|
&& node_level > *focus_level
|
||||||
if node_level < *level {
|
{
|
||||||
*level = node_level;
|
if let Some(level) = &mut closest_level {
|
||||||
}
|
if node_level < *level {
|
||||||
} else {
|
*level = node_level;
|
||||||
closest_level = Some(node_level);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
closest_level = Some(node_level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -155,15 +160,16 @@ impl FocusState {
|
|||||||
// find the closest focusable element before the current level
|
// find the closest focusable element before the current level
|
||||||
rdom.traverse_depth_first(|n| {
|
rdom.traverse_depth_first(|n| {
|
||||||
let node_level = n.state.focus.level;
|
let node_level = n.state.focus.level;
|
||||||
if node_level != *focus_level && node_level.focusable() {
|
if node_level != *focus_level
|
||||||
if node_level < *focus_level {
|
&& node_level.focusable()
|
||||||
if let Some(level) = &mut closest_level {
|
&& node_level < *focus_level
|
||||||
if node_level > *level {
|
{
|
||||||
*level = node_level;
|
if let Some(level) = &mut closest_level {
|
||||||
}
|
if node_level > *level {
|
||||||
} else {
|
*level = node_level;
|
||||||
closest_level = Some(node_level);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
closest_level = Some(node_level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -174,12 +180,10 @@ impl FocusState {
|
|||||||
|
|
||||||
if let Some(level) = closest_level {
|
if let Some(level) = closest_level {
|
||||||
*focus_level = level;
|
*focus_level = level;
|
||||||
|
} else if forward {
|
||||||
|
*focus_level = FocusLevel::Unfocusable;
|
||||||
} else {
|
} else {
|
||||||
if forward {
|
*focus_level = FocusLevel::Focusable;
|
||||||
*focus_level = FocusLevel::Unfocusable;
|
|
||||||
} else {
|
|
||||||
*focus_level = FocusLevel::Focusable;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,11 +202,10 @@ impl FocusState {
|
|||||||
} else {
|
} else {
|
||||||
current_level <= *focus_level
|
current_level <= *focus_level
|
||||||
};
|
};
|
||||||
if after_previous_focused && current_level.focusable() {
|
if after_previous_focused && current_level.focusable() && current_level == *focus_level
|
||||||
if current_level == *focus_level {
|
{
|
||||||
next_focus = Some(new_id);
|
next_focus = Some(new_id);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +215,7 @@ impl FocusState {
|
|||||||
rdom[old].state.focused = false;
|
rdom[old].state.focused = false;
|
||||||
}
|
}
|
||||||
// reset the position to the currently focused element
|
// reset the position to the currently focused element
|
||||||
while self.focus_iter.next(&rdom).id() != id {}
|
while self.focus_iter.next(rdom).id() != id {}
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -267,7 +270,7 @@ impl FocusState {
|
|||||||
state.focused = true;
|
state.focused = true;
|
||||||
self.focus_level = state.focus.level;
|
self.focus_level = state.focus.level;
|
||||||
// reset the position to the currently focused element
|
// reset the position to the currently focused element
|
||||||
while self.focus_iter.next(&rdom).id() != id {}
|
while self.focus_iter.next(rdom).id() != id {}
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -494,10 +494,8 @@ impl InnerInputState {
|
|||||||
let node_layout = layout.layout(node.state.layout.node.unwrap()).unwrap();
|
let node_layout = layout.layout(node.state.layout.node.unwrap()).unwrap();
|
||||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||||
|
|
||||||
if currently_contains {
|
if currently_contains && node.state.focus.level.focusable() {
|
||||||
if node.state.focus.level.focusable() {
|
focus_id = Some(node.id);
|
||||||
focus_id = Some(node.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if let Some(id) = focus_id {
|
if let Some(id) = focus_id {
|
||||||
|
|||||||
Reference in new issue
Block a user