Skip to content

Commit

Permalink
fix: multiwindow a11y fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Aug 27, 2024
1 parent 63c3a73 commit 191a76c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 75 deletions.
10 changes: 9 additions & 1 deletion core/src/window/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ pub struct Id(u64);
static COUNT: AtomicU64 = AtomicU64::new(1);

impl Id {
/// No window will match this Id
pub const NONE: Id = Id(0);

/// Creates a new unique window [`Id`].
pub fn unique() -> Id {
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
let id = Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed));
if id.0 == 0 {
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
} else {
id
}
}
}
2 changes: 2 additions & 0 deletions examples/multi_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ publish = false

[dependencies]
iced = { path = "../..", features = [
"a11y",
"tokio",
"debug",
"winit",
"multi-window",
Expand Down
5 changes: 3 additions & 2 deletions examples/multi_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use iced::widget::{
text_input,
};
use iced::window;
use iced::Length::Fill;
use iced::{
id::Id, Alignment, Center, Element, Length, Point, Settings, Subscription,
Task, Theme, Vector,
Expand All @@ -28,7 +29,7 @@ struct Window {
scale_input: String,
current_scale: f64,
theme: Theme,
input_id: Id,
input_id: text_input::Id,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -166,7 +167,7 @@ impl Window {
scale_input: "1.0".to_string(),
current_scale: 1.0,
theme: Theme::ALL[count % Theme::ALL.len()].clone(),
input_id: Id::unique(),
input_id: text_input::Id::unique(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ where
action,
iced_accessibility::accesskit::Action::Default
))
.then(|| self.on_press.clone())
.then(|| self.on_press.as_ref())
{
state.is_pressed = false;
shell.publish(on_press);
shell.publish(on_press.get());
}
return event::Status::Captured;
}
Expand Down
5 changes: 1 addition & 4 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,7 @@ async fn run_instance<A, E, C>(
let mut viewport_version = state.viewport_version();
let physical_size = state.physical_size();

let mut clipboard = Clipboard::connect(
&window,
crate::proxy::Proxy::new(proxy.raw.clone()).0,
);
let mut clipboard = Clipboard::connect(&window, proxy.clone());
let mut cache = user_interface::Cache::default();

#[cfg(feature = "a11y")]
Expand Down
Loading

0 comments on commit 191a76c

Please sign in to comment.