wip rebase updates
This commit is contained in:
parent
86dcf8af6c
commit
e10459fb37
68 changed files with 1776 additions and 1544 deletions
|
|
@ -213,7 +213,7 @@ impl<'a, Message: Clone + 'a> Overlay<'a, Message> {
|
|||
}
|
||||
}
|
||||
|
||||
fn _layout(&self, renderer: &crate::Renderer, bounds: Size) -> layout::Node {
|
||||
fn _layout(&mut self, renderer: &crate::Renderer, bounds: Size) -> layout::Node {
|
||||
let space_below = bounds.height - (self.position.y + self.target_height);
|
||||
let space_above = self.position.y;
|
||||
|
||||
|
|
@ -242,19 +242,19 @@ impl<'a, Message: Clone + 'a> Overlay<'a, Message> {
|
|||
})
|
||||
}
|
||||
|
||||
fn _on_event(
|
||||
fn _update(
|
||||
&mut self,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &crate::Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
) -> event::Status {
|
||||
) {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
self.state.with_data_mut(|tree| {
|
||||
self.container.on_event(
|
||||
self.container.update(
|
||||
tree, event, layout, cursor, renderer, clipboard, shell, &bounds,
|
||||
)
|
||||
})
|
||||
|
|
@ -293,6 +293,7 @@ impl<'a, Message: Clone + 'a> Overlay<'a, Message> {
|
|||
radius: appearance.border_radius,
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
appearance.background,
|
||||
);
|
||||
|
|
@ -311,26 +312,25 @@ impl<'a, Message: Clone + 'a> iced_core::Overlay<Message, crate::Theme, crate::R
|
|||
self._layout(renderer, bounds)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &crate::Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
) -> event::Status {
|
||||
self._on_event(event, layout, cursor, renderer, clipboard, shell)
|
||||
) {
|
||||
self._update(event, layout, cursor, renderer, clipboard, shell)
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
viewport: &Rectangle,
|
||||
renderer: &crate::Renderer,
|
||||
) -> mouse::Interaction {
|
||||
self._mouse_interaction(layout, cursor, viewport, renderer)
|
||||
self._mouse_interaction(layout, cursor, &layout.bounds(), renderer)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -353,7 +353,7 @@ impl<'a, Message: Clone + 'a> crate::widget::Widget<Message, crate::Theme, crate
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
_tree: &mut iced_core::widget::Tree,
|
||||
renderer: &crate::Renderer,
|
||||
limits: &iced::Limits,
|
||||
|
|
@ -375,18 +375,18 @@ impl<'a, Message: Clone + 'a> crate::widget::Widget<Message, crate::Theme, crate
|
|||
self._mouse_interaction(layout, cursor, viewport, renderer)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
_tree: &mut Tree,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &crate::Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
self._on_event(event, layout, cursor, renderer, clipboard, shell)
|
||||
) {
|
||||
self._update(event, layout, cursor, renderer, clipboard, shell)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -435,7 +435,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
_tree: &mut Tree,
|
||||
renderer: &crate::Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -452,7 +452,7 @@ where
|
|||
let size = {
|
||||
let intrinsic = Size::new(
|
||||
0.0,
|
||||
(f32::from(text_line_height) + self.padding.vertical()) * self.options.len() as f32,
|
||||
(f32::from(text_line_height) + self.padding.y()) * self.options.len() as f32,
|
||||
);
|
||||
|
||||
limits.resolve(Length::Fill, Length::Shrink, intrinsic)
|
||||
|
|
@ -461,17 +461,17 @@ where
|
|||
layout::Node::new(size)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
_state: &mut Tree,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &crate::Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
) {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
let hovered_guard = self.hovered_option.lock().unwrap();
|
||||
|
|
@ -481,7 +481,8 @@ where
|
|||
if let Some(close_on_selected) = self.close_on_selected.as_ref() {
|
||||
shell.publish(close_on_selected.clone());
|
||||
}
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -493,7 +494,7 @@ where
|
|||
|
||||
let option_height =
|
||||
f32::from(self.text_line_height.to_absolute(Pixels(text_size)))
|
||||
+ self.padding.vertical();
|
||||
+ self.padding.y();
|
||||
|
||||
let new_hovered_option = (cursor_position.y / option_height) as usize;
|
||||
let mut hovered_guard = self.hovered_option.lock().unwrap();
|
||||
|
|
@ -515,7 +516,7 @@ where
|
|||
|
||||
let option_height =
|
||||
f32::from(self.text_line_height.to_absolute(Pixels(text_size)))
|
||||
+ self.padding.vertical();
|
||||
+ self.padding.y();
|
||||
let mut hovered_guard = self.hovered_option.lock().unwrap();
|
||||
|
||||
*hovered_guard = Some((cursor_position.y / option_height) as usize);
|
||||
|
|
@ -525,14 +526,13 @@ where
|
|||
if let Some(close_on_selected) = self.close_on_selected.as_ref() {
|
||||
shell.publish(close_on_selected.clone());
|
||||
}
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
|
|
@ -568,8 +568,8 @@ where
|
|||
let text_size = self
|
||||
.text_size
|
||||
.unwrap_or_else(|| text::Renderer::default_size(renderer).0);
|
||||
let option_height = f32::from(self.text_line_height.to_absolute(Pixels(text_size)))
|
||||
+ self.padding.vertical();
|
||||
let option_height =
|
||||
f32::from(self.text_line_height.to_absolute(Pixels(text_size))) + self.padding.y();
|
||||
|
||||
let offset = viewport.y - bounds.y;
|
||||
let start = (offset / option_height) as usize;
|
||||
|
|
@ -605,6 +605,7 @@ where
|
|||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
appearance.selected_background,
|
||||
);
|
||||
|
|
@ -614,16 +615,13 @@ where
|
|||
.color(appearance.selected_text_color)
|
||||
.border_radius(appearance.border_radius);
|
||||
|
||||
svg::Renderer::draw_svg(
|
||||
renderer,
|
||||
svg_handle,
|
||||
Rectangle {
|
||||
x: item_x + item_width - 16.0 - 8.0,
|
||||
y: bounds.y + (bounds.height / 2.0 - 8.0),
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
},
|
||||
);
|
||||
let bounds = Rectangle {
|
||||
x: item_x + item_width - 16.0 - 8.0,
|
||||
y: bounds.y + (bounds.height / 2.0 - 8.0),
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
};
|
||||
svg::Renderer::draw_svg(renderer, svg_handle, bounds, bounds);
|
||||
|
||||
(appearance.selected_text_color, crate::font::semibold())
|
||||
} else if *hovered_guard == Some(i) {
|
||||
|
|
@ -642,6 +640,7 @@ where
|
|||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
appearance.hovered_background,
|
||||
);
|
||||
|
|
@ -678,8 +677,8 @@ where
|
|||
size: Pixels(text_size),
|
||||
line_height: self.text_line_height,
|
||||
font,
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Center,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Center,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
|
|||
|
|
@ -56,12 +56,12 @@ pub fn popup_dropdown<
|
|||
dropdown
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that closes the [`Dropdown`].
|
||||
pub fn close<Message: 'static>(id: Id) -> iced_runtime::Task<Message> {
|
||||
iced_runtime::task::effect(iced_runtime::Action::Widget(Box::new(operation::close(id))))
|
||||
}
|
||||
// /// Produces a [`Task`] that closes the [`Dropdown`].
|
||||
// pub fn close<Message: 'static>(id: Id) -> iced_runtime::Task<Message> {
|
||||
// iced_runtime::task::effect(iced_runtime::Action::Widget(Box::new(operation::close(id))))
|
||||
// }
|
||||
|
||||
/// Produces a [`Task`] that opens the [`Dropdown`].
|
||||
pub fn open<Message: 'static>(id: Id) -> iced_runtime::Task<Message> {
|
||||
iced_runtime::task::effect(iced_runtime::Action::Widget(Box::new(operation::open(id))))
|
||||
}
|
||||
// /// Produces a [`Task`] that opens the [`Dropdown`].
|
||||
// pub fn open<Message: 'static>(id: Id) -> iced_runtime::Task<Message> {
|
||||
// iced_runtime::task::effect(iced_runtime::Action::Widget(Box::new(operation::open(id))))
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -209,18 +209,18 @@ impl<Message> iced_core::Overlay<Message, crate::Theme, crate::Renderer> for Ove
|
|||
})
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &crate::Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
) -> event::Status {
|
||||
) {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
self.container.on_event(
|
||||
self.container.update(
|
||||
self.state, event, layout, cursor, renderer, clipboard, shell, &bounds,
|
||||
)
|
||||
}
|
||||
|
|
@ -229,11 +229,10 @@ impl<Message> iced_core::Overlay<Message, crate::Theme, crate::Renderer> for Ove
|
|||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
viewport: &Rectangle,
|
||||
renderer: &crate::Renderer,
|
||||
) -> mouse::Interaction {
|
||||
self.container
|
||||
.mouse_interaction(self.state, layout, cursor, viewport, renderer)
|
||||
.mouse_interaction(self.state, layout, cursor, &layout.bounds(), renderer)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -256,6 +255,7 @@ impl<Message> iced_core::Overlay<Message, crate::Theme, crate::Renderer> for Ove
|
|||
radius: appearance.border_radius,
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
appearance.background,
|
||||
);
|
||||
|
|
@ -287,7 +287,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
_tree: &mut Tree,
|
||||
renderer: &crate::Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -309,7 +309,7 @@ where
|
|||
)
|
||||
});
|
||||
|
||||
let vertical_padding = self.padding.vertical();
|
||||
let vertical_padding = self.padding.y();
|
||||
let text_line_height = f32::from(text_line_height);
|
||||
|
||||
let size = {
|
||||
|
|
@ -328,17 +328,17 @@ where
|
|||
layout::Node::new(size)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
_state: &mut Tree,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &crate::Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
) {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
match event {
|
||||
|
|
@ -346,7 +346,8 @@ where
|
|||
if cursor.is_over(bounds) {
|
||||
if let Some(item) = self.hovered_option.as_ref() {
|
||||
shell.publish((self.on_selected)(item.clone()));
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -361,7 +362,7 @@ where
|
|||
|
||||
let heights = self
|
||||
.options
|
||||
.element_heights(self.padding.vertical(), text_line_height);
|
||||
.element_heights(self.padding.y(), text_line_height);
|
||||
|
||||
let mut current_offset = 0.0;
|
||||
|
||||
|
|
@ -408,7 +409,7 @@ where
|
|||
|
||||
let heights = self
|
||||
.options
|
||||
.element_heights(self.padding.vertical(), text_line_height);
|
||||
.element_heights(self.padding.y(), text_line_height);
|
||||
|
||||
let mut current_offset = 0.0;
|
||||
|
||||
|
|
@ -446,8 +447,6 @@ where
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
|
|
@ -490,7 +489,7 @@ where
|
|||
let text_line_height = f32::from(self.text_line_height.to_absolute(Pixels(text_size)));
|
||||
|
||||
let visible_options = self.options.visible_options(
|
||||
self.padding.vertical(),
|
||||
self.padding.y(),
|
||||
text_line_height,
|
||||
offset,
|
||||
viewport.height,
|
||||
|
|
@ -528,24 +527,23 @@ where
|
|||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
appearance.selected_background,
|
||||
);
|
||||
|
||||
let svg_bounds = Rectangle {
|
||||
x: item_x + item_width - 16.0 - 8.0,
|
||||
y: bounds.y + (bounds.height / 2.0 - 8.0),
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
};
|
||||
|
||||
let svg_handle =
|
||||
svg::Svg::new(crate::widget::common::object_select().clone())
|
||||
.color(appearance.selected_text_color)
|
||||
.border_radius(appearance.border_radius);
|
||||
svg::Renderer::draw_svg(
|
||||
renderer,
|
||||
svg_handle,
|
||||
Rectangle {
|
||||
x: item_x + item_width - 16.0 - 8.0,
|
||||
y: bounds.y + (bounds.height / 2.0 - 8.0),
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
},
|
||||
);
|
||||
svg::Renderer::draw_svg(renderer, svg_handle, svg_bounds, svg_bounds);
|
||||
|
||||
(appearance.selected_text_color, crate::font::semibold())
|
||||
} else if self.hovered_option.as_ref() == Some(item) {
|
||||
|
|
@ -566,6 +564,7 @@ where
|
|||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
appearance.hovered_background,
|
||||
);
|
||||
|
|
@ -590,8 +589,8 @@ where
|
|||
size: iced::Pixels(text_size),
|
||||
line_height: self.text_line_height,
|
||||
font,
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Center,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Center,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
@ -611,7 +610,7 @@ where
|
|||
})
|
||||
.move_to(Point {
|
||||
x: bounds.x,
|
||||
y: bounds.y + (self.padding.vertical() / 2.0) - 4.0,
|
||||
y: bounds.y + (self.padding.y() / 2.0) - 4.0,
|
||||
});
|
||||
|
||||
Widget::<Message, crate::Theme, crate::Renderer>::draw(
|
||||
|
|
@ -640,8 +639,8 @@ where
|
|||
size: iced::Pixels(text_size),
|
||||
line_height: text::LineHeight::Absolute(Pixels(text_line_height + 4.0)),
|
||||
font: crate::font::default(),
|
||||
horizontal_alignment: alignment::Horizontal::Center,
|
||||
vertical_alignment: alignment::Vertical::Center,
|
||||
align_x: text::Alignment::Center,
|
||||
align_y: alignment::Vertical::Center,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static>
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &crate::Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -116,17 +116,17 @@ impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static>
|
|||
)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
_renderer: &crate::Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
) {
|
||||
update(
|
||||
&event,
|
||||
layout,
|
||||
|
|
@ -183,8 +183,9 @@ impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static>
|
|||
fn overlay<'b>(
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
layout: Layout<'b>,
|
||||
renderer: &crate::Renderer,
|
||||
_viewport: &Rectangle,
|
||||
translation: Vector,
|
||||
) -> Option<overlay::Element<'b, Message, crate::Theme, crate::Renderer>> {
|
||||
let state = tree.state.downcast_mut::<State<Item>>();
|
||||
|
|
@ -275,8 +276,8 @@ pub fn layout(
|
|||
size: iced::Pixels(text_size),
|
||||
line_height: text_line_height,
|
||||
font: font.unwrap_or_else(crate::font::default),
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Top,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
@ -314,7 +315,7 @@ pub fn update<'a, S: AsRef<str>, Message, Item: Clone + PartialEq + 'static + 'a
|
|||
on_selected: &dyn Fn(Item) -> Message,
|
||||
selections: &super::Model<S, Item>,
|
||||
state: impl FnOnce() -> &'a mut State<Item>,
|
||||
) -> event::Status {
|
||||
) {
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
|
||||
| Event::Touch(touch::Event::FingerPressed { .. }) => {
|
||||
|
|
@ -325,14 +326,12 @@ pub fn update<'a, S: AsRef<str>, Message, Item: Clone + PartialEq + 'static + 'a
|
|||
// bounds or on the drop-down, either way we close the overlay.
|
||||
state.is_open = false;
|
||||
|
||||
event::Status::Captured
|
||||
shell.capture_event();
|
||||
} else if cursor.is_over(layout.bounds()) {
|
||||
state.is_open = true;
|
||||
state.hovered_option = selections.selected.clone();
|
||||
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
shell.capture_event();
|
||||
}
|
||||
}
|
||||
Event::Mouse(mouse::Event::WheelScrolled {
|
||||
|
|
@ -348,19 +347,15 @@ pub fn update<'a, S: AsRef<str>, Message, Item: Clone + PartialEq + 'static + 'a
|
|||
shell.publish((on_selected)(option.1.clone()));
|
||||
}
|
||||
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
shell.capture_event();
|
||||
}
|
||||
}
|
||||
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
|
||||
let state = state();
|
||||
|
||||
state.keyboard_modifiers = *modifiers;
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
_ => event::Status::Ignored,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -420,8 +415,8 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static
|
|||
size: iced::Pixels(text_size),
|
||||
line_height,
|
||||
font: font.unwrap_or_else(crate::font::default),
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Top,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
@ -430,7 +425,7 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static
|
|||
};
|
||||
|
||||
let mut desc_count = 0;
|
||||
padding.horizontal().mul_add(
|
||||
padding.x().mul_add(
|
||||
2.0,
|
||||
selections
|
||||
.elements()
|
||||
|
|
@ -517,22 +512,20 @@ pub fn draw<'a, S, Item: Clone + PartialEq + 'static>(
|
|||
bounds,
|
||||
border: style.border,
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
style.background,
|
||||
);
|
||||
|
||||
if let Some(handle) = state.icon.as_ref() {
|
||||
let svg_handle = iced_core::Svg::new(handle.clone()).color(style.text_color);
|
||||
svg::Renderer::draw_svg(
|
||||
renderer,
|
||||
svg_handle,
|
||||
Rectangle {
|
||||
x: bounds.x + bounds.width - gap - 16.0,
|
||||
y: bounds.center_y() - 8.0,
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
},
|
||||
);
|
||||
let svg_bounds = Rectangle {
|
||||
x: bounds.x + bounds.width - gap - 16.0,
|
||||
y: bounds.center_y() - 8.0,
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
};
|
||||
svg::Renderer::draw_svg(renderer, svg_handle, svg_bounds, svg_bounds);
|
||||
}
|
||||
|
||||
if let Some(content) = selected.map(AsRef::as_ref) {
|
||||
|
|
@ -541,7 +534,7 @@ pub fn draw<'a, S, Item: Clone + PartialEq + 'static>(
|
|||
let bounds = Rectangle {
|
||||
x: bounds.x + padding.left,
|
||||
y: bounds.center_y(),
|
||||
width: bounds.width - padding.horizontal(),
|
||||
width: bounds.width - padding.x(),
|
||||
height: f32::from(text_line_height.to_absolute(Pixels(text_size))),
|
||||
};
|
||||
|
||||
|
|
@ -553,8 +546,8 @@ pub fn draw<'a, S, Item: Clone + PartialEq + 'static>(
|
|||
line_height: text_line_height,
|
||||
font,
|
||||
bounds: bounds.size(),
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Center,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Center,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
|
|||
|
|
@ -11,62 +11,62 @@ pub trait Dropdown {
|
|||
fn open(&mut self);
|
||||
}
|
||||
|
||||
/// Produces a [`Task`] that closes a [`Dropdown`] popup.
|
||||
pub fn close<T>(id: Id) -> impl Operation<T> {
|
||||
struct Close(Id);
|
||||
// /// Produces a [`Task`] that closes a [`Dropdown`] popup.
|
||||
// pub fn close<T>(id: Id) -> impl Operation<T> {
|
||||
// struct Close(Id);
|
||||
|
||||
impl<T> Operation<T> for Close {
|
||||
fn custom(&mut self, state: &mut dyn std::any::Any, id: Option<&Id>) {
|
||||
if id.map_or(true, |id| id != &self.0) {
|
||||
return;
|
||||
}
|
||||
// impl<T> Operation<T> for Close {
|
||||
// fn custom(&mut self, state: &mut dyn std::any::Any, id: Option<&Id>) {
|
||||
// if id.map_or(true, |id| id != &self.0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
let Some(state) = state.downcast_mut::<State>() else {
|
||||
return;
|
||||
};
|
||||
// let Some(state) = state.downcast_mut::<State>() else {
|
||||
// return;
|
||||
// };
|
||||
|
||||
state.close();
|
||||
}
|
||||
// state.close();
|
||||
// }
|
||||
|
||||
fn container(
|
||||
&mut self,
|
||||
_id: Option<&Id>,
|
||||
_bounds: Rectangle,
|
||||
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
|
||||
) {
|
||||
operate_on_children(self)
|
||||
}
|
||||
}
|
||||
// fn container(
|
||||
// &mut self,
|
||||
// _id: Option<&Id>,
|
||||
// _bounds: Rectangle,
|
||||
// operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
|
||||
// ) {
|
||||
// operate_on_children(self)
|
||||
// }
|
||||
// }
|
||||
|
||||
Close(id)
|
||||
}
|
||||
// Close(id)
|
||||
// }
|
||||
|
||||
/// Produces a [`Task`] that opens a [`Dropdown`] popup.
|
||||
pub fn open<T>(id: Id) -> impl Operation<T> {
|
||||
struct Open(Id);
|
||||
// /// Produces a [`Task`] that opens a [`Dropdown`] popup.
|
||||
// pub fn open<T>(id: Id) -> impl Operation<T> {
|
||||
// struct Open(Id);
|
||||
|
||||
impl<T> Operation<T> for Open {
|
||||
fn custom(&mut self, state: &mut dyn std::any::Any, id: Option<&Id>) {
|
||||
if id.map_or(true, |id| id != &self.0) {
|
||||
return;
|
||||
}
|
||||
// impl<T> Operation<T> for Open {
|
||||
// fn custom(&mut self, state: &mut dyn std::any::Any, id: Option<&Id>) {
|
||||
// if id.map_or(true, |id| id != &self.0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
let Some(state) = state.downcast_mut::<State>() else {
|
||||
return;
|
||||
};
|
||||
// let Some(state) = state.downcast_mut::<State>() else {
|
||||
// return;
|
||||
// };
|
||||
|
||||
state.open();
|
||||
}
|
||||
// state.open();
|
||||
// }
|
||||
|
||||
fn container(
|
||||
&mut self,
|
||||
_id: Option<&Id>,
|
||||
_bounds: Rectangle,
|
||||
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
|
||||
) {
|
||||
operate_on_children(self)
|
||||
}
|
||||
}
|
||||
// fn container(
|
||||
// &mut self,
|
||||
// _id: Option<&Id>,
|
||||
// _bounds: Rectangle,
|
||||
// operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
|
||||
// ) {
|
||||
// operate_on_children(self)
|
||||
// }
|
||||
// }
|
||||
|
||||
Open(id)
|
||||
}
|
||||
// Open(id)
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -203,13 +203,13 @@ where
|
|||
state.hashes[i] = text_hash;
|
||||
state.selections[i].update(Text {
|
||||
content: selection.as_ref(),
|
||||
bounds: Size::INFINITY,
|
||||
bounds: Size::INFINITE,
|
||||
// TODO use the renderer default size
|
||||
size: iced::Pixels(self.text_size.unwrap_or(14.0)),
|
||||
line_height: self.text_line_height,
|
||||
font: self.font.unwrap_or_else(crate::font::default),
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Top,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
@ -227,7 +227,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &crate::Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -252,17 +252,17 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
_renderer: &crate::Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
_viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
) {
|
||||
update::<S, Message, AppMessage>(
|
||||
&event,
|
||||
layout,
|
||||
|
|
@ -327,21 +327,23 @@ where
|
|||
}
|
||||
|
||||
fn operate(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
_layout: Layout<'_>,
|
||||
_renderer: &crate::Renderer,
|
||||
operation: &mut dyn iced_core::widget::Operation,
|
||||
) {
|
||||
let state = tree.state.downcast_mut::<State>();
|
||||
operation.custom(state, self.id.as_ref());
|
||||
// TODO: double check operation handling
|
||||
// let state = tree.state.downcast_mut::<State>();
|
||||
// operation.custom(state, self.id.as_ref());
|
||||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
layout: Layout<'b>,
|
||||
renderer: &crate::Renderer,
|
||||
viewport: &Rectangle,
|
||||
translation: Vector,
|
||||
) -> Option<overlay::Element<'b, Message, crate::Theme, crate::Renderer>> {
|
||||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||
|
|
@ -469,24 +471,38 @@ pub fn layout(
|
|||
let max_width = match width {
|
||||
Length::Shrink => {
|
||||
let measure = move |(label, paragraph): (_, Option<&mut crate::Plain>)| -> f32 {
|
||||
let text = Text {
|
||||
content: label,
|
||||
bounds: Size::new(f32::MAX, f32::MAX),
|
||||
size: iced::Pixels(text_size),
|
||||
line_height: text_line_height,
|
||||
font: font.unwrap_or_else(crate::font::default),
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
};
|
||||
let paragraph = match paragraph {
|
||||
Some(p) => {
|
||||
let text = Text {
|
||||
content: label,
|
||||
bounds: Size::new(f32::MAX, f32::MAX),
|
||||
size: iced::Pixels(text_size),
|
||||
line_height: text_line_height,
|
||||
font: font.unwrap_or_else(crate::font::default),
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Top,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
};
|
||||
p.update(text);
|
||||
p
|
||||
}
|
||||
None => &mut crate::Plain::new(text),
|
||||
None => {
|
||||
let text = Text {
|
||||
content: label.to_string(),
|
||||
bounds: Size::new(f32::MAX, f32::MAX),
|
||||
size: iced::Pixels(text_size),
|
||||
line_height: text_line_height,
|
||||
font: font.unwrap_or_else(crate::font::default),
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Top,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
};
|
||||
&mut crate::Plain::new(text)
|
||||
}
|
||||
};
|
||||
paragraph.min_width().round()
|
||||
};
|
||||
|
|
@ -544,7 +560,7 @@ pub fn update<
|
|||
text_size: Option<f32>,
|
||||
font: Option<crate::font::Font>,
|
||||
selected_option: Option<usize>,
|
||||
) -> event::Status {
|
||||
) {
|
||||
let state = state();
|
||||
|
||||
let open = |shell: &mut Shell<'_, Message>,
|
||||
|
|
@ -575,7 +591,7 @@ pub fn update<
|
|||
let measure = |_label: &str, selection_paragraph: &crate::Paragraph| -> f32 {
|
||||
selection_paragraph.min_width().round()
|
||||
};
|
||||
let pad_width = padding.horizontal().mul_add(2.0, 16.0);
|
||||
let pad_width = padding.x().mul_add(2.0, 16.0);
|
||||
|
||||
let selections_width = selections
|
||||
.iter()
|
||||
|
|
@ -669,12 +685,10 @@ pub fn update<
|
|||
if let Some(on_close) = on_surface_action {
|
||||
shell.publish(on_close(surface::action::destroy_popup(state.popup_id)));
|
||||
}
|
||||
event::Status::Captured
|
||||
shell.capture_event();
|
||||
} else if cursor.is_over(layout.bounds()) {
|
||||
open(shell, state, on_selected);
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
shell.capture_event();
|
||||
}
|
||||
}
|
||||
Event::Mouse(mouse::Event::WheelScrolled {
|
||||
|
|
@ -689,17 +703,13 @@ pub fn update<
|
|||
shell.publish((on_selected)(next_index));
|
||||
}
|
||||
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
shell.capture_event();
|
||||
}
|
||||
}
|
||||
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
|
||||
state.keyboard_modifiers = *modifiers;
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
_ => event::Status::Ignored,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -746,7 +756,7 @@ where
|
|||
.zip(state.selections.iter())
|
||||
.map(|(label, selection)| measure(label.as_ref(), selection.raw()))
|
||||
.fold(0.0, |next, current| current.max(next));
|
||||
let pad_width = padding.horizontal().mul_add(2.0, 16.0);
|
||||
let pad_width = padding.x().mul_add(2.0, 16.0);
|
||||
|
||||
let width = selections_width + gap + pad_width + icon_width;
|
||||
let is_open = state.is_open.clone();
|
||||
|
|
@ -822,7 +832,7 @@ where
|
|||
selection_paragraph.min_width().round()
|
||||
};
|
||||
|
||||
let pad_width = padding.horizontal().mul_add(2.0, 16.0);
|
||||
let pad_width = padding.x().mul_add(2.0, 16.0);
|
||||
|
||||
let icon_width = if icons.is_empty() { 0.0 } else { 24.0 };
|
||||
|
||||
|
|
@ -883,23 +893,20 @@ pub fn draw<'a, S>(
|
|||
bounds,
|
||||
border: style.border,
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
},
|
||||
style.background,
|
||||
);
|
||||
|
||||
if let Some(handle) = state.icon.clone() {
|
||||
let svg_handle = svg::Svg::new(handle).color(style.text_color);
|
||||
|
||||
svg::Renderer::draw_svg(
|
||||
renderer,
|
||||
svg_handle,
|
||||
Rectangle {
|
||||
x: bounds.x + bounds.width - gap - 16.0,
|
||||
y: bounds.center_y() - 8.0,
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
},
|
||||
);
|
||||
let bounds = Rectangle {
|
||||
x: bounds.x + bounds.width - gap - 16.0,
|
||||
y: bounds.center_y() - 8.0,
|
||||
width: 16.0,
|
||||
height: 16.0,
|
||||
};
|
||||
svg::Renderer::draw_svg(renderer, svg_handle, bounds, bounds);
|
||||
}
|
||||
|
||||
if let Some(content) = selected.map(AsRef::as_ref).or(placeholder) {
|
||||
|
|
@ -908,7 +915,7 @@ pub fn draw<'a, S>(
|
|||
let mut bounds = Rectangle {
|
||||
x: bounds.x + padding.left,
|
||||
y: bounds.center_y(),
|
||||
width: bounds.width - padding.horizontal(),
|
||||
width: bounds.width - padding.x(),
|
||||
height: f32::from(text_line_height.to_absolute(Pixels(text_size))),
|
||||
};
|
||||
|
||||
|
|
@ -932,8 +939,8 @@ pub fn draw<'a, S>(
|
|||
line_height: text_line_height,
|
||||
font,
|
||||
bounds: bounds.size(),
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Center,
|
||||
align_x: text::Alignment::Left,
|
||||
align_y: alignment::Vertical::Center,
|
||||
shaping: text::Shaping::Advanced,
|
||||
wrapping: text::Wrapping::default(),
|
||||
ellipsize: text::Ellipsize::default(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue