refactor(color-picker): allow custom size for the icon
This commit is contained in:
parent
7d0ad7abc8
commit
242ece1749
3 changed files with 14 additions and 13 deletions
|
|
@ -520,7 +520,7 @@ impl State {
|
||||||
.on_input(Message::InputChanged)
|
.on_input(Message::InputChanged)
|
||||||
.into(),
|
.into(),
|
||||||
self.color_picker_model
|
self.color_picker_model
|
||||||
.picker_button(Message::ColorPickerUpdate)
|
.picker_button(Message::ColorPickerUpdate, None)
|
||||||
.width(Length::Fixed(128.0))
|
.width(Length::Fixed(128.0))
|
||||||
.height(Length::Fixed(128.0))
|
.height(Length::Fixed(128.0))
|
||||||
.into(),
|
.into(),
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 13b5a947df963232cafb938de62e81b1df0dbac8
|
Subproject commit ed4af4e6431e30702f6de8031f3a3a11b82da3f0
|
||||||
|
|
@ -122,10 +122,12 @@ impl ColorPickerModel {
|
||||||
pub fn picker_button<'a, Message: 'static, T: Fn(ColorPickerUpdate) -> Message>(
|
pub fn picker_button<'a, Message: 'static, T: Fn(ColorPickerUpdate) -> Message>(
|
||||||
&self,
|
&self,
|
||||||
f: T,
|
f: T,
|
||||||
|
icon_portion: Option<u16>,
|
||||||
) -> crate::widget::Button<'a, Message, crate::Renderer> {
|
) -> crate::widget::Button<'a, Message, crate::Renderer> {
|
||||||
color_button(
|
color_button(
|
||||||
Some(f(ColorPickerUpdate::ToggleColorPicker)),
|
Some(f(ColorPickerUpdate::ToggleColorPicker)),
|
||||||
self.applied_color,
|
self.applied_color,
|
||||||
|
Length::FillPortion(icon_portion.unwrap_or(12)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,7 +360,8 @@ where
|
||||||
.leading_icon(
|
.leading_icon(
|
||||||
color_button(
|
color_button(
|
||||||
None,
|
None,
|
||||||
Some(Color::from(palette::Srgb::from_color(self.active_color)))
|
Some(Color::from(palette::Srgb::from_color(self.active_color))),
|
||||||
|
Length::FillPortion(12)
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
)
|
)
|
||||||
|
|
@ -415,6 +418,7 @@ where
|
||||||
color_button(
|
color_button(
|
||||||
Some(on_update(ColorPickerUpdate::ActiveColor(hsv))),
|
Some(on_update(ColorPickerUpdate::ActiveColor(hsv))),
|
||||||
Some(*c),
|
Some(*c),
|
||||||
|
Length::FillPortion(12),
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
|
|
@ -744,6 +748,7 @@ fn color_to_string(c: palette::Hsv, is_hex: bool) -> String {
|
||||||
fn color_button<'a, Message: 'static>(
|
fn color_button<'a, Message: 'static>(
|
||||||
on_press: Option<Message>,
|
on_press: Option<Message>,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
|
icon_portion: Length,
|
||||||
) -> crate::widget::Button<'a, Message, crate::Renderer> {
|
) -> crate::widget::Button<'a, Message, crate::Renderer> {
|
||||||
let spacing = THEME.with(|t| t.borrow().cosmic().spacing);
|
let spacing = THEME.with(|t| t.borrow().cosmic().spacing);
|
||||||
|
|
||||||
|
|
@ -751,27 +756,23 @@ fn color_button<'a, Message: 'static>(
|
||||||
Element::from(vertical_space(Length::Fixed(f32::from(spacing.space_s))))
|
Element::from(vertical_space(Length::Fixed(f32::from(spacing.space_s))))
|
||||||
} else {
|
} else {
|
||||||
Element::from(column![
|
Element::from(column![
|
||||||
vertical_space(Length::FillPortion(1)),
|
vertical_space(Length::FillPortion(6)),
|
||||||
vertical_space(Length::FillPortion(1)),
|
|
||||||
row![
|
row![
|
||||||
horizontal_space(Length::FillPortion(1)),
|
horizontal_space(Length::FillPortion(6)),
|
||||||
horizontal_space(Length::FillPortion(1)),
|
|
||||||
Icon::from(
|
Icon::from(
|
||||||
icon::from_name("list-add-symbolic")
|
icon::from_name("list-add-symbolic")
|
||||||
.prefer_svg(true)
|
.prefer_svg(true)
|
||||||
.symbolic(true)
|
.symbolic(true)
|
||||||
.size(64)
|
.size(64)
|
||||||
)
|
)
|
||||||
.width(Length::FillPortion(2))
|
.width(icon_portion)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.content_fit(iced_core::ContentFit::Contain),
|
.content_fit(iced_core::ContentFit::Contain),
|
||||||
horizontal_space(Length::FillPortion(1)),
|
horizontal_space(Length::FillPortion(6)),
|
||||||
horizontal_space(Length::FillPortion(1)),
|
|
||||||
]
|
]
|
||||||
.height(Length::FillPortion(2))
|
.height(icon_portion)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
vertical_space(Length::FillPortion(1)),
|
vertical_space(Length::FillPortion(6)),
|
||||||
vertical_space(Length::FillPortion(1)),
|
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.width(Length::Fixed(f32::from(spacing.space_s)))
|
.width(Length::Fixed(f32::from(spacing.space_s)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue