Skip to content

Commit

Permalink
Merge branch 'feat/updated-dioxus' into feat/reduce-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Jan 28, 2024
2 parents ad26a4d + 7d33498 commit 7981da0
Show file tree
Hide file tree
Showing 40 changed files with 859 additions and 895 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ dioxus-router = { git = "https://github.com/DioxusLabs/dioxus", rev = "53380c995
skia-safe = { version = "0.67.0", features = ["gl", "textlayout", "svg"] }

gl = "0.14.0"
glutin = "0.30.10"
glutin-winit = "0.3.0"
raw-window-handle = "0.5.1"
winit = "0.28.7"
glutin = "0.31.2"
glutin-winit = "0.4.2"
raw-window-handle = "0.5.2"
winit = "0.29.9"
tokio = { version = "1.33.0", features = ["sync", "rt-multi-thread", "time", "macros"] }
accesskit = { version = "0.11.0", features = ["serde"]}
accesskit_winit = "0.14.1"
accesskit = { version = "0.12.2", features = ["serde"]}
accesskit_winit = "0.18.0"

euclid = "0.22.9"
uuid = { version = "1.4.1", features = ["v4"]}
Expand Down
4 changes: 2 additions & 2 deletions book/src/guides/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn app() -> Element {

### padding

Specify the inner paddings of an element. You can do so by three different ways, just like in CSS.
Specify the inner paddings of an element. You can do so by three different ways.

```rust, no_run
fn app() -> Element {
Expand Down Expand Up @@ -209,7 +209,7 @@ fn app() -> Element {

### margin

Specify the margin of an element. You can do so by three different ways, just like in CSS.
Specify the margin of an element. You can do so by three different ways.

```rust, no_run
fn app() -> Element {
Expand Down
2 changes: 1 addition & 1 deletion book/src/guides/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Compatible elements: [`rect`](/guides/elements.html#rect)
The attributes that have colors as values can use the following syntax:

#### Static colors
- `rect`
- `red`
- `blue`
- `green`
- `yellow`
Expand Down
2 changes: 1 addition & 1 deletion book/src/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn test() {
let mut utils = launch_test_with_config(
our_component,
TestingConfig::default().with_size((500.0, 800.0).into()),
*TestingConfig::default().with_size((500.0, 800.0).into()),
);
let root = utils.root();
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/accordion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn Accordion(props: AccordionProps) -> Element {
let onmouseenter = {
to_owned![status, platform];
move |_| {
platform.set_cursor(CursorIcon::Hand);
platform.set_cursor(CursorIcon::Pointer);
status.set(AccordionStatus::Hovering);
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn Button(props: ButtonProps) -> Element {
let onmouseenter = {
to_owned![status, platform];
move |_| {
platform.set_cursor(CursorIcon::Hand);
platform.set_cursor(CursorIcon::Pointer);
status.set(ButtonStatus::Hovering);
}
};
Expand Down
4 changes: 2 additions & 2 deletions crates/components/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
let onmouseenter = {
to_owned![platform];
move |_| {
platform.set_cursor(CursorIcon::Hand);
platform.set_cursor(CursorIcon::Pointer);
status.set(DropdownItemStatus::Hovering);
}
};
Expand Down Expand Up @@ -240,7 +240,7 @@ where
let onmouseenter = {
to_owned![status, platform];
move |_| {
platform.set_cursor(CursorIcon::Hand);
platform.set_cursor(CursorIcon::Pointer);
status.set(DropdownStatus::Hovering);
}
};
Expand Down
3 changes: 3 additions & 0 deletions crates/components/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub fn Input(
}
};

let focus_id = focus.attribute();
let cursor_reference = editable.cursor_attr();
let highlights = editable.highlights_attr(0);

Expand Down Expand Up @@ -198,6 +199,8 @@ pub fn Input(
corner_radius: "10",
margin: "{margin}",
cursor_reference,
focus_id,
role: "textInput",
main_align: "center",
paragraph {
margin: "8 12",
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn Slider(
to_owned![status];
move |_: MouseEvent| {
*status.write() = SliderStatus::Hovering;
platform.set_cursor(CursorIcon::Hand);
platform.set_cursor(CursorIcon::Pointer);
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn Switch(props: SwitchProps) -> Element {

let onmouseenter = move |_: MouseEvent| {
*status.write() = SwitchStatus::Hovering;
platform.set_cursor(CursorIcon::Hand);
platform.set_cursor(CursorIcon::Pointer);
};

let onclick = {
Expand Down
203 changes: 203 additions & 0 deletions crates/core/src/accessibility/accessibility_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
use crate::accessibility::*;
use accesskit::{
Action, DefaultActionVerb, Node, NodeBuilder, NodeClassSet, NodeId as AccessibilityId, Rect,
Role, Tree, TreeUpdate,
};
use freya_dom::prelude::DioxusNode;
use freya_node_state::AccessibilityNodeState;
use std::sync::{Arc, Mutex};
use torin::prelude::NodeAreas;

pub type SharedAccessibilityManager = Arc<Mutex<AccessibilityManager>>;

pub const ACCESSIBILITY_ROOT_ID: AccessibilityId = AccessibilityId(0);

/// Manages the Accessibility integration.
pub struct AccessibilityManager {
/// Accessibility Nodes
pub nodes: Vec<(AccessibilityId, Node)>,
/// Accessibility tree
pub node_classes: NodeClassSet,
/// Current focused Accessibility Node.
pub focused_id: AccessibilityId,
}

impl AccessibilityManager {
pub fn new(focused_id: AccessibilityId) -> Self {
Self {
focused_id,
node_classes: NodeClassSet::default(),
nodes: Vec::default(),
}
}

/// Wrap it in a `Arc<Mutex<T>>`.
pub fn wrap(self) -> SharedAccessibilityManager {
Arc::new(Mutex::new(self))
}

/// Clear the Accessibility Nodes.
pub fn clear(&mut self) {
self.nodes.clear();
}

pub fn push_node(&mut self, id: AccessibilityId, node: Node) {
self.nodes.push((id, node))
}

/// Add a Node to the Accessibility Tree.
pub fn add_node(
&mut self,
dioxus_node: &DioxusNode,
node_areas: &NodeAreas,
accessibility_id: AccessibilityId,
node_accessibility: &AccessibilityNodeState,
) {
let mut builder = NodeBuilder::new(Role::Unknown);

// Set children
let children = dioxus_node.get_accessibility_children();
if !children.is_empty() {
builder.set_children(children);
}

// Set text value
if let Some(alt) = &node_accessibility.alt {
builder.set_value(alt.to_owned());
} else if let Some(value) = dioxus_node.get_inner_texts() {
builder.set_value(value);
}

// Set name
if let Some(name) = &node_accessibility.name {
builder.set_name(name.to_owned());
}

// Set role
if let Some(role) = node_accessibility.role {
builder.set_role(role);
}

// Set the area
let area = node_areas.area.to_f64();
builder.set_bounds(Rect {
x0: area.min_x(),
x1: area.max_x(),
y0: area.min_y(),
y1: area.max_y(),
});

// Set focusable action
if node_accessibility.focusable {
builder.add_action(Action::Focus);
} else {
builder.add_action(Action::Default);
builder.set_default_action_verb(DefaultActionVerb::Focus);
}

// Insert the node into the Tree
let node = builder.build(&mut self.node_classes);
self.push_node(accessibility_id, node);
}

/// Update the focused Node ID and generate a TreeUpdate if necessary.
pub fn set_focus_with_update(&mut self, new_focus_id: AccessibilityId) -> Option<TreeUpdate> {
self.focused_id = new_focus_id;

// Only focus the element if it exists
let node_focused_exists = self.nodes.iter().any(|node| node.0 == new_focus_id);
if node_focused_exists {
Some(TreeUpdate {
nodes: Vec::new(),
tree: None,
focus: self.focused_id,
})
} else {
None
}
}

/// Create the root Accessibility Node.
pub fn build_root(&mut self, root_name: &str) -> Node {
let mut builder = NodeBuilder::new(Role::Window);
builder.set_name(root_name.to_string());
builder.set_children(
self.nodes
.iter()
.map(|(id, _)| *id)
.collect::<Vec<AccessibilityId>>(),
);

builder.build(&mut self.node_classes)
}

/// Process the Nodes accessibility Tree
pub fn process(&mut self, root_id: AccessibilityId, root_name: &str) -> TreeUpdate {
let root = self.build_root(root_name);
let mut nodes = vec![(root_id, root)];
nodes.extend(self.nodes.clone());
nodes.reverse();

let focus = self
.nodes
.iter()
.find_map(|node| {
if node.0 == self.focused_id {
Some(node.0)
} else {
None
}
})
.unwrap_or(ACCESSIBILITY_ROOT_ID);

TreeUpdate {
nodes,
tree: Some(Tree::new(root_id)),
focus,
}
}

/// Focus the next/previous Node starting from the currently focused Node.
pub fn set_focus_on_next_node(&mut self, direction: AccessibilityFocusDirection) -> TreeUpdate {
let node_index = self
.nodes
.iter()
.enumerate()
.find(|(_, node)| node.0 == self.focused_id)
.map(|(i, _)| i);

let target_node = if direction == AccessibilityFocusDirection::Forward {
// Find the next Node
if let Some(node_index) = node_index {
if node_index == self.nodes.len() - 1 {
self.nodes.first()
} else {
self.nodes.get(node_index + 1)
}
} else {
self.nodes.first()
}
} else {
// Find the previous Node
if let Some(node_index) = node_index {
if node_index == 0 {
self.nodes.get(node_index - 1)
} else {
self.nodes.last()
}
} else {
self.nodes.last()
}
};

self.focused_id = target_node
.map(|(id, _)| *id)
.unwrap_or(ACCESSIBILITY_ROOT_ID);

TreeUpdate {
nodes: Vec::new(),
tree: None,
focus: self.focused_id,
}
}
}
Loading

0 comments on commit 7981da0

Please sign in to comment.