Skip to content

Commit

Permalink
Work around issues with derive(Default)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Apr 23, 2024
1 parent 9a0c338 commit f081161
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/widget/color_picker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<Message> ColorPickerModel<Message> {
&self,
f: T,
icon_portion: Option<u16>,
) -> crate::widget::Button<'a, Message, crate::Theme, crate::Renderer> {
) -> crate::widget::Button<'a, Message, crate::Theme, crate::Renderer> where Message: 'static {
color_button(
Some(f(ColorPickerUpdate::ToggleColorPicker)),
self.applied_color,
Expand Down
8 changes: 7 additions & 1 deletion src/widget/segmented_button/model/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ use crate::widget::icon::Icon;
use std::borrow::Cow;

/// A builder for a [`Model`].
#[derive(Default)]
pub struct ModelBuilder<SelectionMode: Default, Message>(Model<SelectionMode, Message>);

//TODO: Default derive ends up requiring Message to implement Default
impl<SelectionMode: Default, Message> Default for ModelBuilder<SelectionMode, Message> {
fn default() -> Self {
Self(Model::default())
}
}

/// Constructs a new item for the [`ModelBuilder`].
pub struct BuilderEntity<SelectionMode: Default, Message> {
model: ModelBuilder<SelectionMode, Message>,
Expand Down
17 changes: 16 additions & 1 deletion src/widget/segmented_button/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub type MultiSelectEntityMut<'a, Message> = EntityMut<'a, MultiSelect, Message>
pub(super) struct Storage(HashMap<TypeId, SecondaryMap<Entity, Box<dyn Any>>>);

/// The model held by the application, containing the unique IDs and data of each inserted item.
#[derive(Default)]
pub struct Model<SelectionMode: Default, Message> {
/// The content used for drawing segmented items.
pub(super) items: SlotMap<Entity, Settings>,
Expand All @@ -80,6 +79,22 @@ pub struct Model<SelectionMode: Default, Message> {
pub(super) storage: Storage,
}

//TODO: Default derive ends up requiring Message to implement Default
impl<SelectionMode: Default, Message> Default for Model<SelectionMode, Message> {
fn default() -> Self {
Self {
items: SlotMap::default(),
elements: SecondaryMap::default(),
icons: SecondaryMap::default(),
indents: SecondaryMap::default(),
text: SecondaryMap::default(),
order: VecDeque::default(),
selection: SelectionMode::default(),
storage: Storage::default(),
}
}
}

impl<SelectionMode: Default, Message> Model<SelectionMode, Message>
where
Self: Selectable,
Expand Down

0 comments on commit f081161

Please sign in to comment.