diff options
-rw-r--r-- | core/src/widget/text.rs | 2 | ||||
-rw-r--r-- | runtime/src/task.rs | 2 | ||||
-rw-r--r-- | widget/src/checkbox.rs | 2 | ||||
-rw-r--r-- | widget/src/container.rs | 2 | ||||
-rw-r--r-- | widget/src/lazy.rs | 57 | ||||
-rw-r--r-- | widget/src/lazy/component.rs | 78 | ||||
-rw-r--r-- | widget/src/lazy/responsive.rs | 17 | ||||
-rw-r--r-- | widget/src/overlay/menu.rs | 2 | ||||
-rw-r--r-- | widget/src/pick_list.rs | 2 | ||||
-rw-r--r-- | widget/src/progress_bar.rs | 2 | ||||
-rw-r--r-- | widget/src/radio.rs | 2 | ||||
-rw-r--r-- | widget/src/rule.rs | 4 | ||||
-rw-r--r-- | widget/src/scrollable.rs | 6 | ||||
-rw-r--r-- | widget/src/slider.rs | 8 | ||||
-rw-r--r-- | widget/src/stack.rs | 6 | ||||
-rw-r--r-- | widget/src/text_editor.rs | 2 | ||||
-rw-r--r-- | widget/src/text_input.rs | 2 | ||||
-rw-r--r-- | widget/src/toggler.rs | 2 |
18 files changed, 113 insertions, 85 deletions
diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs index 8b02f8c2..b34c5632 100644 --- a/core/src/widget/text.rs +++ b/core/src/widget/text.rs @@ -389,7 +389,7 @@ where } /// The appearance of some text. -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct Style { /// The [`Color`] of the text. /// diff --git a/runtime/src/task.rs b/runtime/src/task.rs index 3f97d134..4554c74b 100644 --- a/runtime/src/task.rs +++ b/runtime/src/task.rs @@ -117,7 +117,7 @@ impl<T> Task<T> { match self.0 { None => task, Some(first) => match task.0 { - None => Task::none(), + None => Task(Some(first)), Some(second) => Task(Some(boxed_stream(first.chain(second)))), }, } diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index 4b2f6075..819f0d9d 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -481,7 +481,7 @@ pub enum Status { } /// The style of a checkbox. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the checkbox. pub background: Background, diff --git a/widget/src/container.rs b/widget/src/container.rs index b256540c..f4993ac9 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -572,7 +572,7 @@ pub fn visible_bounds(id: Id) -> Task<Option<Rectangle>> { } /// The appearance of a container. -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct Style { /// The text [`Color`] of the container. pub text_color: Option<Color>, diff --git a/widget/src/lazy.rs b/widget/src/lazy.rs index 221f9de3..6642c986 100644 --- a/widget/src/lazy.rs +++ b/widget/src/lazy.rs @@ -270,29 +270,40 @@ where renderer: &Renderer, translation: Vector, ) -> Option<overlay::Element<'_, Message, Theme, Renderer>> { - let overlay = Overlay(Some( - InnerBuilder { - cell: self.element.borrow().as_ref().unwrap().clone(), - element: self - .element - .borrow() - .as_ref() - .unwrap() - .borrow_mut() - .take() - .unwrap(), - tree: &mut tree.children[0], - overlay_builder: |element, tree| { - element - .as_widget_mut() - .overlay(tree, layout, renderer, translation) - .map(|overlay| RefCell::new(Nested::new(overlay))) - }, - } - .build(), - )); - - Some(overlay::Element::new(Box::new(overlay))) + let overlay = InnerBuilder { + cell: self.element.borrow().as_ref().unwrap().clone(), + element: self + .element + .borrow() + .as_ref() + .unwrap() + .borrow_mut() + .take() + .unwrap(), + tree: &mut tree.children[0], + overlay_builder: |element, tree| { + element + .as_widget_mut() + .overlay(tree, layout, renderer, translation) + .map(|overlay| RefCell::new(Nested::new(overlay))) + }, + } + .build(); + + #[allow(clippy::redundant_closure_for_method_calls)] + if overlay.with_overlay(|overlay| overlay.is_some()) { + Some(overlay::Element::new(Box::new(Overlay(Some(overlay))))) + } else { + let heads = overlay.into_heads(); + + // - You may not like it, but this is what peak performance looks like + // - TODO: Get rid of ouroboros, for good + // - What?! + *self.element.borrow().as_ref().unwrap().borrow_mut() = + Some(heads.element); + + None + } } } diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index 2bdfa2c0..c7bc1264 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -446,44 +446,48 @@ where ) -> Option<overlay::Element<'b, Message, Theme, Renderer>> { self.rebuild_element_if_necessary(); - let tree = tree - .state - .downcast_mut::<Rc<RefCell<Option<Tree>>>>() - .borrow_mut() - .take() - .unwrap(); - - let overlay = Overlay(Some( - InnerBuilder { - instance: self, - tree, - types: PhantomData, - overlay_builder: |instance, tree| { - instance.state.get_mut().as_mut().unwrap().with_element_mut( - move |element| { - element - .as_mut() - .unwrap() - .as_widget_mut() - .overlay( - &mut tree.children[0], - layout, - renderer, - translation, - ) - .map(|overlay| { - RefCell::new(Nested::new(overlay)) - }) - }, - ) - }, - } - .build(), - )); + let state = tree.state.downcast_mut::<Rc<RefCell<Option<Tree>>>>(); + let tree = state.borrow_mut().take().unwrap(); + + let overlay = InnerBuilder { + instance: self, + tree, + types: PhantomData, + overlay_builder: |instance, tree| { + instance.state.get_mut().as_mut().unwrap().with_element_mut( + move |element| { + element + .as_mut() + .unwrap() + .as_widget_mut() + .overlay( + &mut tree.children[0], + layout, + renderer, + translation, + ) + .map(|overlay| RefCell::new(Nested::new(overlay))) + }, + ) + }, + } + .build(); + + #[allow(clippy::redundant_closure_for_method_calls)] + if overlay.with_overlay(|overlay| overlay.is_some()) { + Some(overlay::Element::new(Box::new(OverlayInstance { + overlay: Some(Overlay(Some(overlay))), // Beautiful, I know + }))) + } else { + let heads = overlay.into_heads(); + + // - You may not like it, but this is what peak performance looks like + // - TODO: Get rid of ouroboros, for good + // - What?! + *state.borrow_mut() = Some(heads.tree); - Some(overlay::Element::new(Box::new(OverlayInstance { - overlay: Some(overlay), - }))) + None + } } } diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs index dbf281f3..a7a99f56 100644 --- a/widget/src/lazy/responsive.rs +++ b/widget/src/lazy/responsive.rs @@ -320,7 +320,11 @@ where } .build(); - Some(overlay::Element::new(Box::new(overlay))) + if overlay.with_overlay(|(overlay, _layout)| overlay.is_some()) { + Some(overlay::Element::new(Box::new(overlay))) + } else { + None + } } } @@ -453,4 +457,15 @@ where }) .unwrap_or_default() } + + fn operate( + &mut self, + layout: Layout<'_>, + renderer: &Renderer, + operation: &mut dyn widget::Operation, + ) { + let _ = self.with_overlay_mut_maybe(|overlay| { + overlay.operate(layout, renderer, operation); + }); + } } diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs index f05ae40a..b641e8f5 100644 --- a/widget/src/overlay/menu.rs +++ b/widget/src/overlay/menu.rs @@ -562,7 +562,7 @@ where } /// The appearance of a [`Menu`]. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the menu. pub background: Background, diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index ff54fe8a..4f1e9da9 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -828,7 +828,7 @@ pub enum Status { } /// The appearance of a pick list. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The text [`Color`] of the pick list. pub text_color: Color, diff --git a/widget/src/progress_bar.rs b/widget/src/progress_bar.rs index 8c665c8c..9d2b30f4 100644 --- a/widget/src/progress_bar.rs +++ b/widget/src/progress_bar.rs @@ -208,7 +208,7 @@ where } /// The appearance of a progress bar. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the progress bar. pub background: Background, diff --git a/widget/src/radio.rs b/widget/src/radio.rs index 300318fd..d2a3bd6a 100644 --- a/widget/src/radio.rs +++ b/widget/src/radio.rs @@ -471,7 +471,7 @@ pub enum Status { } /// The appearance of a radio button. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the radio button. pub background: Background, diff --git a/widget/src/rule.rs b/widget/src/rule.rs index 92199ca9..24577683 100644 --- a/widget/src/rule.rs +++ b/widget/src/rule.rs @@ -187,7 +187,7 @@ where } /// The appearance of a rule. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The color of the rule. pub color: Color, @@ -200,7 +200,7 @@ pub struct Style { } /// The fill mode of a rule. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum FillMode { /// Fill the whole length of the container. Full, diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 6d7f251e..528d63c1 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -1856,7 +1856,7 @@ pub enum Status { } /// The appearance of a scrollable. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`container::Style`] of a scrollable. pub container: container::Style, @@ -1869,7 +1869,7 @@ pub struct Style { } /// The appearance of the scrollbar of a scrollable. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Rail { /// The [`Background`] of a scrollbar. pub background: Option<Background>, @@ -1880,7 +1880,7 @@ pub struct Rail { } /// The appearance of the scroller of a scrollable. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Scroller { /// The [`Color`] of the scroller. pub color: Color, diff --git a/widget/src/slider.rs b/widget/src/slider.rs index 9477958d..31aa0e0c 100644 --- a/widget/src/slider.rs +++ b/widget/src/slider.rs @@ -562,7 +562,7 @@ pub enum Status { } /// The appearance of a slider. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The colors of the rail of the slider. pub rail: Rail, @@ -582,7 +582,7 @@ impl Style { } /// The appearance of a slider rail -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Rail { /// The backgrounds of the rail of the slider. pub backgrounds: (Background, Background), @@ -593,7 +593,7 @@ pub struct Rail { } /// The appearance of the handle of a slider. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Handle { /// The shape of the handle. pub shape: HandleShape, @@ -606,7 +606,7 @@ pub struct Handle { } /// The shape of the handle of a slider. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum HandleShape { /// A circular handle. Circle { diff --git a/widget/src/stack.rs b/widget/src/stack.rs index 9ccaa274..6a44c328 100644 --- a/widget/src/stack.rs +++ b/widget/src/stack.rs @@ -215,9 +215,7 @@ where shell: &mut Shell<'_, Message>, viewport: &Rectangle, ) -> event::Status { - let is_over_scroll = - matches!(event, Event::Mouse(mouse::Event::WheelScrolled { .. })) - && cursor.is_over(layout.bounds()); + let is_over = cursor.is_over(layout.bounds()); self.children .iter_mut() @@ -236,7 +234,7 @@ where viewport, ); - if is_over_scroll && cursor != mouse::Cursor::Unavailable { + if is_over && cursor != mouse::Cursor::Unavailable { let interaction = child.as_widget().mouse_interaction( state, layout, cursor, viewport, renderer, ); diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 3676d02f..a298252a 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -1228,7 +1228,7 @@ pub enum Status { } /// The appearance of a text input. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the text input. pub background: Background, diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 5bbf76f5..ff413779 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -1541,7 +1541,7 @@ pub enum Status { } /// The appearance of a text input. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the text input. pub background: Background, diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 3b412081..fdd2e68c 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -489,7 +489,7 @@ pub enum Status { } /// The appearance of a toggler. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The background [`Color`] of the toggler. pub background: Color, |