refactor: icon styling and headerbar icon styling
Headerbar icons are transparent when their window is not focused, but otherwise share the same style as icons with selection. This updates the icon styles to match figma when selected.
This commit is contained in:
parent
6f6eeec0e7
commit
e47684ffdb
11 changed files with 121 additions and 115 deletions
|
|
@ -16,12 +16,14 @@ pub type Button<'a, Message> = Builder<'a, Message, Icon>;
|
|||
pub struct Icon {
|
||||
handle: Handle,
|
||||
vertical: bool,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
pub fn icon<'a, Message>(handle: impl Into<Handle>) -> Button<'a, Message> {
|
||||
Button::new(Icon {
|
||||
handle: handle.into(),
|
||||
vertical: false,
|
||||
selected: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +126,11 @@ impl<'a, Message> Button<'a, Message> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn selected(mut self, selected: bool) -> Self {
|
||||
self.variant.selected = selected;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn vertical(mut self, vertical: bool) -> Self {
|
||||
self.variant.vertical = vertical;
|
||||
self.style = Style::IconVertical;
|
||||
|
|
@ -179,6 +186,7 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
|
|||
.padding(0)
|
||||
.id(builder.id)
|
||||
.on_press_maybe(builder.on_press)
|
||||
.selected(builder.variant.selected)
|
||||
.style(builder.style);
|
||||
|
||||
if builder.tooltip.is_empty() {
|
||||
|
|
|
|||
|
|
@ -68,21 +68,21 @@ pub trait StyleSheet {
|
|||
type Style: Default;
|
||||
|
||||
/// Produces the active [`Appearance`] of a button.
|
||||
fn active(&self, focused: bool, style: &Self::Style) -> Appearance;
|
||||
fn active(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// Produces the disabled [`Appearance`] of a button.
|
||||
fn disabled(&self, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// [`Appearance`] when the button is the target of a DND operation.
|
||||
fn drop_target(&self, style: &Self::Style) -> Appearance {
|
||||
self.hovered(false, style)
|
||||
self.hovered(false, false, style)
|
||||
}
|
||||
|
||||
/// Produces the hovered [`Appearance`] of a button.
|
||||
fn hovered(&self, focused: bool, style: &Self::Style) -> Appearance;
|
||||
fn hovered(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// Produces the pressed [`Appearance`] of a button.
|
||||
fn pressed(&self, focused: bool, style: &Self::Style) -> Appearance;
|
||||
fn pressed(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// Background color of the selection indicator
|
||||
fn selection_background(&self) -> Background;
|
||||
|
|
|
|||
|
|
@ -528,10 +528,10 @@ where
|
|||
}
|
||||
|
||||
if self.on_press.is_none() {
|
||||
node.set_disabled()
|
||||
node.set_disabled();
|
||||
}
|
||||
if is_hovered {
|
||||
node.set_hovered()
|
||||
node.set_hovered();
|
||||
}
|
||||
node.set_default_action_verb(DefaultActionVerb::Click);
|
||||
|
||||
|
|
@ -696,12 +696,12 @@ where
|
|||
style_sheet.disabled(style)
|
||||
} else if is_mouse_over {
|
||||
if state.is_pressed {
|
||||
style_sheet.pressed(state.is_focused || is_selected, style)
|
||||
style_sheet.pressed(state.is_focused, is_selected, style)
|
||||
} else {
|
||||
style_sheet.hovered(state.is_focused || is_selected, style)
|
||||
style_sheet.hovered(state.is_focused, is_selected, style)
|
||||
}
|
||||
} else {
|
||||
style_sheet.active(state.is_focused || is_selected, style)
|
||||
style_sheet.active(state.is_focused, is_selected, style)
|
||||
};
|
||||
|
||||
let doubled_border_width = styling.border_width * 2.0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue