Skip to content

Commit

Permalink
Merge branch 'pop-os:master' into resize-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
netraptor authored Dec 1, 2024
2 parents f5b01df + aee94ca commit 9419237
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 235 deletions.
198 changes: 104 additions & 94 deletions core/src/widget/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::id::{Id, Internal};
use crate::Widget;
use std::any::{self, Any};
use std::borrow::{Borrow, BorrowMut, Cow};
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
use std::hash::Hash;
use std::{fmt, mem};

Expand Down Expand Up @@ -164,93 +164,102 @@ impl Tree {
{
let borrowed: &mut dyn Widget<Message, Theme, Renderer> =
new.borrow_mut();
let mut needs_reset = false;
let tag_match = self.tag == borrowed.tag();
if let Some(Id(Internal::Custom(_, n))) = borrowed.id() {
if let Some((mut state, children)) = NAMED
.with(|named| named.borrow_mut().remove(&n))
.or_else(|| {
//check self.id
if let Some(Id(Internal::Custom(_, ref name))) = self.id {
if name == &n {
Some((
mem::replace(&mut self.state, State::None),
self.children
.iter_mut()
.map(|s| {
// take the data
mem::replace(
s,
Tree {
id: s.id.clone(),
tag: s.tag,
..Tree::empty()
},
)
})
.enumerate()
.collect(),
))

let mut tag_match = self.tag == borrowed.tag();
if tag_match {
if let Some(Id(Internal::Custom(_, n))) = borrowed.id() {
if let Some((mut state, children)) = NAMED
.with(|named| named.borrow_mut().remove(&n))
.or_else(|| {
//check self.id
if let Some(Id(Internal::Custom(_, ref name))) = self.id
{
if name == &n {
Some((
mem::replace(&mut self.state, State::None),
self.children
.iter_mut()
.map(|s| {
// take the data
mem::replace(
s,
Tree {
id: s.id.clone(),
tag: s.tag,
..Tree::empty()
},
)
})
.enumerate()
.collect(),
))
} else {
None
}
} else {
None
}
})
{
std::mem::swap(&mut self.state, &mut state);
let widget_children = borrowed.children();
if !tag_match
|| self.children.len() != widget_children.len()
{
self.children = borrowed.children();
} else {
None
}
})
{
std::mem::swap(&mut self.state, &mut state);
let widget_children = borrowed.children();
if !tag_match || self.children.len() != widget_children.len() {
self.children = borrowed.children();
} else {
for (old_i, mut old) in children {
let Some(my_state) = self.children.get_mut(old_i)
else {
continue;
};
if my_state.tag != old.tag || {
!match (&old.id, &my_state.id) {
(
Some(Id(Internal::Custom(_, ref old_name))),
Some(Id(Internal::Custom(_, ref my_name))),
) => old_name == my_name,
(
Some(Id(Internal::Set(a))),
Some(Id(Internal::Set(b))),
) => a.len() == b.len(),
(
Some(Id(Internal::Unique(_))),
Some(Id(Internal::Unique(_))),
) => true,
(None, None) => true,
_ => false,
for (old_i, mut old) in children {
let Some(my_state) = self.children.get_mut(old_i)
else {
continue;
};
if my_state.tag != old.tag || {
!match (&old.id, &my_state.id) {
(
Some(Id(Internal::Custom(
_,
ref old_name,
))),
Some(Id(Internal::Custom(
_,
ref my_name,
))),
) => old_name == my_name,
(
Some(Id(Internal::Set(a))),
Some(Id(Internal::Set(b))),
) => a.len() == b.len(),
(
Some(Id(Internal::Unique(_))),
Some(Id(Internal::Unique(_))),
) => true,
(None, None) => true,
_ => false,
}
} {
continue;
}
} {
continue;
}

mem::swap(my_state, &mut old);
mem::swap(my_state, &mut old);
}
}
} else {
tag_match = false;
}
} else {
needs_reset = true;
}
} else if tag_match {
if let Some(id) = self.id.clone() {
borrowed.set_id(id);
}
if self.children.len() != borrowed.children().len() {
self.children = borrowed.children();
if let Some(id) = self.id.clone() {
borrowed.set_id(id);
}
if self.children.len() != borrowed.children().len() {
self.children = borrowed.children();
}
}
} else {
needs_reset = true;
}
if needs_reset {
*self = Self::new(borrowed);
let borrowed = new.borrow_mut();
if tag_match {
borrowed.diff(self);
} else {
*self = Self::new(borrowed);
let borrowed = new.borrow_mut();
borrowed.diff(self);
}
}
Expand All @@ -269,6 +278,7 @@ impl Tree {
new_children.iter().map(|c| c.borrow().id()).collect(),
|tree, widget| {
let borrowed: &mut dyn Widget<_, _, _> = widget.borrow_mut();

tree.diff(borrowed);
},
|widget| {
Expand All @@ -291,29 +301,26 @@ impl Tree {
self.children.truncate(new_children.len());
}

let len_changed = self.children.len() != new_children.len();

let children_len = self.children.len();
let (mut id_map, mut id_list): (
HashMap<String, &mut Tree>,
Vec<&mut Tree>,
) = self.children.iter_mut().fold(
(HashMap::new(), Vec::with_capacity(children_len)),
|(mut id_map, mut id_list), c| {
VecDeque<(usize, &mut Tree)>,
) = self.children.iter_mut().enumerate().fold(
(HashMap::new(), VecDeque::with_capacity(children_len)),
|(mut id_map, mut id_list), (i, c)| {
if let Some(id) = c.id.as_ref() {
if let Internal::Custom(_, ref name) = id.0 {
let _ = id_map.insert(name.to_string(), c);
} else {
id_list.push(c);
id_list.push_back((i, c));
}
} else {
id_list.push(c);
id_list.push_back((i, c));
}
(id_map, id_list)
},
);

let mut child_state_i = 0;
let mut new_trees: Vec<(Tree, usize)> =
Vec::with_capacity(new_children.len());
for (i, (new, new_id)) in
Expand All @@ -327,17 +334,20 @@ impl Tree {
}
}) {
c
} else if child_state_i < id_list.len()
&& !matches!(
id_list[child_state_i].id,
Some(Id(Internal::Custom(_, _)))
)
{
let c = &mut id_list[child_state_i];
if len_changed {
c.id.clone_from(new_id);
} else if let Some(i) = {
let mut found = None;
for c_i in 0..id_list.len() {
if id_list[c_i].0 == i {
found = Some(c_i);
break;
}
if i < c_i {
break;
}
}
child_state_i += 1;
found
} {
let c = id_list.remove(i).unwrap().1;
c
} else {
let mut my_new_state = new_state(new);
Expand Down
20 changes: 20 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ pub enum Action {
/// This enables mouse events for the window and stops mouse events
/// from being passed to whatever is underneath.
DisableMousePassthrough(Id),

/// Enable window blur.
EnableBlur(Id),

/// Disable window blur.
DisableBlur(Id),
}

/// Subscribes to the frames of the window of the running application.
Expand Down Expand Up @@ -456,3 +462,17 @@ pub fn enable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
pub fn disable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::DisableMousePassthrough(id)))
}

/// Enable the blur effect for a window.
///
/// This is only supported on platforms that support window blur.
pub fn enable_blur<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::EnableBlur(id)))
}

/// Disable the blur effect for a window.
///
/// This is only supported on platforms that support window blur.
pub fn disable_blur<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::DisableBlur(id)))
}
1 change: 1 addition & 0 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub trait Program: Sized {
default_text_size: settings.default_text_size,
antialiasing: settings.antialiasing,
exit_on_close_request: settings.exit_on_close_request,
is_daemon: settings.exit_on_close_request,
}
.into(),
renderer_settings,
Expand Down
5 changes: 5 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub struct Settings {

/// If set to true the application will exit when the main window is closed.
pub exit_on_close_request: bool,

/// Whether the application is a daemon
pub is_daemon: bool,
}

impl Default for Settings {
Expand All @@ -46,6 +49,7 @@ impl Default for Settings {
default_text_size: Pixels(14.0),
antialiasing: false,
exit_on_close_request: false,
is_daemon: false,
}
}
}
Expand All @@ -56,6 +60,7 @@ impl From<Settings> for iced_winit::Settings {
iced_winit::Settings {
id: settings.id,
fonts: settings.fonts,
is_daemon: settings.is_daemon,
}
}
}
7 changes: 1 addition & 6 deletions widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,8 @@ where
cursor: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_layout = layout.children().next().unwrap();
let c_state = state.children.get(0);

self.content.as_widget().a11y_nodes(
c_layout,
c_state.unwrap_or(&Tree::empty()),
cursor,
)
self.content.as_widget().a11y_nodes(c_layout, state, cursor)
}

fn drag_destinations(
Expand Down
18 changes: 6 additions & 12 deletions widget/src/lazy/responsive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,12 @@ where
tree: &Tree,
cursor_position: mouse::Cursor,
) -> iced_accessibility::A11yTree {
use std::rc::Rc;

let tree = tree.state.downcast_ref::<Rc<RefCell<Option<Tree>>>>();
if let Some(tree) = tree.borrow().as_ref() {
self.content.borrow().element.as_widget().a11y_nodes(
layout,
&tree.children[0],
cursor_position,
)
} else {
iced_accessibility::A11yTree::default()
}
let state = tree.state.downcast_ref::<State>().tree.borrow();
self.content.borrow().element.as_widget().a11y_nodes(
layout,
&*state,
cursor_position,
)
}

fn id(&self) -> Option<core::widget::Id> {
Expand Down
17 changes: 17 additions & 0 deletions widget/src/mouse_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,23 @@ where
);
}
}

#[cfg(feature = "a11y")]
fn a11y_nodes(
&self,
layout: Layout<'_>,
state: &Tree,
cursor: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_state = state.children.get(0);

let ret = self.content.as_widget().a11y_nodes(
layout,
c_state.unwrap_or(&Tree::empty()),
cursor,
);
return ret;
}
}

impl<'a, Message, Theme, Renderer> From<MouseArea<'a, Message, Theme, Renderer>>
Expand Down
Loading

0 comments on commit 9419237

Please sign in to comment.