Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 19, 2025
1 parent 28f1d4c commit 49d7478
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 81 deletions.
7 changes: 3 additions & 4 deletions crates/hooks/src/use_focus.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;


use dioxus_core::{
prelude::consume_context,
use_hook,
AttributeValue,
prelude::consume_context
};
use dioxus_hooks::{
use_context,
Expand Down Expand Up @@ -103,7 +102,7 @@ impl UseFocus {

/// Create a focus manager for a node.
pub fn use_focus() -> UseFocus {
let id = use_hook(|| UseFocus::new_id());
let id = use_hook(UseFocus::new_id);

use_focus_from_id(id)
}
Expand All @@ -128,4 +127,4 @@ pub fn use_focus_from_id(id: AccessibilityId) -> UseFocus {
navigation_mark,
platform,
})
}
}
159 changes: 82 additions & 77 deletions examples/delegated_focus.rs
Original file line number Diff line number Diff line change
@@ -1,77 +1,82 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use freya::prelude::*;
use freya_core::{prelude::EventMessage, types::AccessibilityId};

fn main() {
launch_with_props(app, "Controlled Focus", (400.0, 350.0));
}

fn app() -> Element {
let nodes = use_hook(|| [
UseFocus::new_id(),
UseFocus::new_id(),
UseFocus::new_id(),
UseFocus::new_id()
]);
let mut current = use_signal(|| 0);

let onwheel = move |_| {
current += 1;
if current() == 4 {
current.set(0);
}
};

use_effect(move || {
let platform = UsePlatform::new();
platform
.send(EventMessage::FocusAccessibilityNode(nodes[current()]))
.ok();
});

rsx!(
rect {
height: "100%",
width: "100%",
background: "black",
color: "white",
direction: "horizontal",
main_align: "center",
cross_align: "center",
onwheel,
for (i, id) in nodes.iter().enumerate() {
Card {
key: "{i}",
id: *id,
index: i
}
}
}
)
}

#[component]
fn Card(index: usize, id: AccessibilityId) -> Element {
let focus = use_focus_from_id(id);
let background = if focus.is_focused() {
"rgb(0, 119, 182)"
} else {
"black"
};

rsx!(
rect {
height: "100",
width: "100",
a11y_id: focus.attribute(),
background,
label {
"Card {index}"
}
}
)
}
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use freya::prelude::*;
use freya_core::{
prelude::EventMessage,
types::AccessibilityId,
};

fn main() {
launch_with_props(app, "Controlled Focus", (400.0, 350.0));
}

fn app() -> Element {
let nodes = use_hook(|| {
[
UseFocus::new_id(),
UseFocus::new_id(),
UseFocus::new_id(),
UseFocus::new_id(),
]
});
let mut current = use_signal(|| 0);

let onwheel = move |_| {
current += 1;
if current() == 4 {
current.set(0);
}
};

use_effect(move || {
let platform = UsePlatform::new();
platform
.send(EventMessage::FocusAccessibilityNode(nodes[current()]))
.ok();
});

rsx!(
rect {
height: "100%",
width: "100%",
background: "black",
color: "white",
direction: "horizontal",
main_align: "center",
cross_align: "center",
onwheel,
for (i, id) in nodes.iter().enumerate() {
Card {
key: "{i}",
id: *id,
index: i
}
}
}
)
}

#[component]
fn Card(index: usize, id: AccessibilityId) -> Element {
let focus = use_focus_from_id(id);
let background = if focus.is_focused() {
"rgb(0, 119, 182)"
} else {
"black"
};

rsx!(
rect {
height: "100",
width: "100",
a11y_id: focus.attribute(),
background,
label {
"Card {index}"
}
}
)
}

0 comments on commit 49d7478

Please sign in to comment.