mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
Upgrade winit to 0.30.2 (#4849)
* Closes https://github.com/emilk/egui/issues/1918 * Closes https://github.com/emilk/egui/issues/4437 * Closes https://github.com/emilk/egui/issues/4709 * [x] I have followed the instructions in the PR template Hiya, I need new winit for a specific fix for a android_native_actvity. There are already two PRs, but both don't seem to have a lot of movement, or are entirely complete: https://github.com/emilk/egui/pull/4466 Seems to have gone stale & is missing some bits. https://github.com/emilk/egui/pull/4702 Also seems stale (if less so), and is missing a refactor to run_on_demand. I also *think* the accesskit integration has a mistake and can't be enabled. I've marked them as a co-author on this as I started from this branch. (I think! Haven't done that on git before...). Sorry for the wall of text but just dumping some details / thoughts here: - There's an issue with creating child windows in winit 0.30.1 and up on macOS. The multiple_viewports, "create immediate viewport" example crashes on anything later 0.30.1, with a stack overflow in unsafe code. I've create [a winit issue](https://github.com/rust-windowing/winit/issues/3800), it *might* already be fixed in 0.31.0 but I can't test as 0.31 will likely require another refactoring. For now I have just pinned things to 0.30.0 exatly. - Winit has deprecated run_on_demand, instead requiring the ApplicationHandler interface. In 0.31.0 run_on_demand is removed. I've refactored both the integration and the WinitApp trait to follow this pattern. I've left user_events a bit more opaque, as it seems 0.31.0 is doing a rework of UserEvents too. - I've used the new lazy init approach for access kit from this branch https://github.com/mwcampbell/egui/tree/accesskit-new-lazy-init and marked Matt as co-author, thanks Matt! - There was very similair but not quite the same code for run_and_return and run_and_exit. I've merged them, but looking at the github issues graveyard it seems vey finnicky. I *hope* this is more robust than before but it's a bit scary. - when receiving new_events this also used to check the redraw timing dictionary. That doesn't seem necesarry so left this out, but that is a slight behaviour change? - I have reeneabled serial_windows on macOS. I wondered whether it was fixed after this PR and does seem to be! However, even before this PR it seems to work, so maybe winit has sorted things out before that... Windows also works fine now without the extra hack. - I've done a very basic test of AccessKit on Windows and screen reader seems ok but I'm really not knowleadgable enough to say whether it's all good or not. - I've tested cargo tests & all examples on Windows & macOS, and ran a basic Android app. Still, testing native platforms is wel... hard so if anyone can test linux / iOs / older mac versions / windows 10 would probably be a good idea! - For consistencys sake I've made all event like functions in WinitApp return a `Result<EventResult>`. There's quite a bit of Ok-wrapping now, maybe too annoying? Not sure. Thank you for having a look! # Tested on * [x] macOS * [x] Windows * [x] Wayland (thanks [SiebenCorgie](https://github.com/SiebenCorgie)) * [x] X11 (thanks [crumblingstatue](https://github.com/crumblingstatue)!, [SiebenCorgie](https://github.com/SiebenCorgie)) # TODO * [x] Fix "follow system theme" not working on initial startup (winit issue, pinning to 0.30.2 for now). * [x] Fix `request_repaint_after` --------- Co-authored-by: mwcampbell <mattcampbell@pobox.com> Co-authored-by: j-axa <josef.axa@gmail.com> Co-authored-by: DataTriny <datatriny@gmail.com> Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -86,7 +86,7 @@ ahash.workspace = true
|
||||
nohash-hasher.workspace = true
|
||||
|
||||
#! ### Optional dependencies
|
||||
accesskit = { version = "0.12", optional = true }
|
||||
accesskit = { version = "0.16", optional = true }
|
||||
|
||||
backtrace = { workspace = true, optional = true }
|
||||
|
||||
|
||||
@@ -396,8 +396,6 @@ struct ContextImpl {
|
||||
|
||||
#[cfg(feature = "accesskit")]
|
||||
is_accesskit_enabled: bool,
|
||||
#[cfg(feature = "accesskit")]
|
||||
accesskit_node_classes: accesskit::NodeClassSet,
|
||||
|
||||
loaders: Arc<Loaders>,
|
||||
}
|
||||
@@ -2016,12 +2014,7 @@ impl ContextImpl {
|
||||
state
|
||||
.node_builders
|
||||
.into_iter()
|
||||
.map(|(id, builder)| {
|
||||
(
|
||||
id.accesskit_id(),
|
||||
builder.build(&mut self.accesskit_node_classes),
|
||||
)
|
||||
})
|
||||
.map(|(id, builder)| (id.accesskit_id(), builder.build()))
|
||||
.collect()
|
||||
};
|
||||
let focus_id = self
|
||||
@@ -2909,37 +2902,15 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Enable generation of AccessKit tree updates in all future frames.
|
||||
///
|
||||
/// If it's practical for the egui integration to immediately run the egui
|
||||
/// application when it is either initializing the AccessKit adapter or
|
||||
/// being called by the AccessKit adapter to provide the initial tree update,
|
||||
/// then it should do so, to provide a complete AccessKit tree to the adapter
|
||||
/// immediately. Otherwise, it should enqueue a repaint and use the
|
||||
/// placeholder tree update from [`Context::accesskit_placeholder_tree_update`]
|
||||
/// in the meantime.
|
||||
#[cfg(feature = "accesskit")]
|
||||
pub fn enable_accesskit(&self) {
|
||||
self.write(|ctx| ctx.is_accesskit_enabled = true);
|
||||
}
|
||||
|
||||
/// Return a tree update that the egui integration should provide to the
|
||||
/// AccessKit adapter if it cannot immediately run the egui application
|
||||
/// to get a full tree update after running [`Context::enable_accesskit`].
|
||||
/// Disable generation of AccessKit tree updates in all future frames.
|
||||
#[cfg(feature = "accesskit")]
|
||||
pub fn accesskit_placeholder_tree_update(&self) -> accesskit::TreeUpdate {
|
||||
crate::profile_function!();
|
||||
|
||||
use accesskit::{NodeBuilder, Role, Tree, TreeUpdate};
|
||||
|
||||
let root_id = crate::accesskit_root_id().accesskit_id();
|
||||
self.write(|ctx| TreeUpdate {
|
||||
nodes: vec![(
|
||||
root_id,
|
||||
NodeBuilder::new(Role::Window).build(&mut ctx.accesskit_node_classes),
|
||||
)],
|
||||
tree: Some(Tree::new(root_id)),
|
||||
focus: root_id,
|
||||
})
|
||||
pub fn disable_accesskit(&self) {
|
||||
self.write(|ctx| ctx.is_accesskit_enabled = false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -964,11 +964,11 @@ impl Response {
|
||||
info: crate::WidgetInfo,
|
||||
) {
|
||||
use crate::WidgetType;
|
||||
use accesskit::{Checked, Role};
|
||||
use accesskit::{Role, Toggled};
|
||||
|
||||
self.fill_accesskit_node_common(builder);
|
||||
builder.set_role(match info.typ {
|
||||
WidgetType::Label => Role::StaticText,
|
||||
WidgetType::Label => Role::Label,
|
||||
WidgetType::Link => Role::Link,
|
||||
WidgetType::TextEdit => Role::TextInput,
|
||||
WidgetType::Button | WidgetType::ImageButton | WidgetType::CollapsingHeader => {
|
||||
@@ -976,7 +976,7 @@ impl Response {
|
||||
}
|
||||
WidgetType::Checkbox => Role::CheckBox,
|
||||
WidgetType::RadioButton => Role::RadioButton,
|
||||
WidgetType::SelectableLabel => Role::ToggleButton,
|
||||
WidgetType::SelectableLabel => Role::Button,
|
||||
WidgetType::ComboBox => Role::ComboBox,
|
||||
WidgetType::Slider => Role::Slider,
|
||||
WidgetType::DragValue => Role::SpinButton,
|
||||
@@ -997,14 +997,14 @@ impl Response {
|
||||
builder.set_numeric_value(value);
|
||||
}
|
||||
if let Some(selected) = info.selected {
|
||||
builder.set_checked(if selected {
|
||||
Checked::True
|
||||
builder.set_toggled(if selected {
|
||||
Toggled::True
|
||||
} else {
|
||||
Checked::False
|
||||
Toggled::False
|
||||
});
|
||||
} else if matches!(info.typ, WidgetType::Checkbox) {
|
||||
// Indeterminate state
|
||||
builder.set_checked(Checked::Mixed);
|
||||
builder.set_toggled(Toggled::Mixed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ fn paint_selection(
|
||||
ui.ctx(),
|
||||
_response.id,
|
||||
cursor_range,
|
||||
accesskit::Role::StaticText,
|
||||
accesskit::Role::Label,
|
||||
galley_pos,
|
||||
galley,
|
||||
);
|
||||
|
||||
@@ -94,7 +94,7 @@ fn toggle_button_node() {
|
||||
let (_, toggle) = output
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| node.role() == Role::ToggleButton)
|
||||
.find(|(_, node)| node.role() == Role::Button)
|
||||
.expect("Toggle button should exist in the accesskit output");
|
||||
|
||||
assert_eq!(toggle.name(), Some(button_text));
|
||||
|
||||
Reference in New Issue
Block a user