Skip to content

Commit

Permalink
fix(dropdown): bolden selected menu option
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Oct 24, 2023
1 parent a12af36 commit 79da230
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
26 changes: 3 additions & 23 deletions src/widget/dropdown/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ where
padding: Padding,
text_size: Option<f32>,
text_line_height: text::LineHeight,
font: Option<crate::font::Font>,
style: (),
}

Expand All @@ -60,7 +59,6 @@ impl<'a, S: AsRef<str>, Message: 'a> Menu<'a, S, Message> {
padding: Padding::ZERO,
text_size: None,
text_line_height: text::LineHeight::default(),
font: None,
style: Default::default(),
}
}
Expand Down Expand Up @@ -89,12 +87,6 @@ impl<'a, S: AsRef<str>, Message: 'a> Menu<'a, S, Message> {
self
}

/// Sets the font of the [`Menu`].
pub fn font(mut self, font: impl Into<crate::font::Font>) -> Self {
self.font = Some(font.into());
self
}

/// Turns the [`Menu`] into an overlay [`Element`] at the given target
/// position.
///
Expand Down Expand Up @@ -152,7 +144,6 @@ impl<'a, Message: 'a> Overlay<'a, Message> {
on_option_hovered,
width,
padding,
font,
text_size,
text_line_height,
style,
Expand All @@ -166,7 +157,6 @@ impl<'a, Message: 'a> Overlay<'a, Message> {
selected_option,
on_selected,
on_option_hovered,
font,
text_size,
text_line_height,
padding,
Expand Down Expand Up @@ -287,7 +277,6 @@ struct List<'a, S: AsRef<str>, Message> {
padding: Padding,
text_size: Option<f32>,
text_line_height: text::LineHeight,
font: Option<crate::font::Font>,
selected_icon: Option<svg::Handle>,
}

Expand Down Expand Up @@ -471,10 +460,7 @@ impl<'a, S: AsRef<str>, Message> Widget<Message, crate::Renderer> for List<'a, S
);
}

(
appearance.selected_text_color,
self.font.unwrap_or(crate::font::FONT_SEMIBOLD),
)
(appearance.selected_text_color, crate::font::FONT_SEMIBOLD)
} else if *self.hovered_option == Some(i) {
let item_x = bounds.x + appearance.border_width;
let item_width = bounds.width - appearance.border_width * 2.0;
Expand All @@ -493,15 +479,9 @@ impl<'a, S: AsRef<str>, Message> Widget<Message, crate::Renderer> for List<'a, S
appearance.hovered_background,
);

(
appearance.hovered_text_color,
self.font.unwrap_or(crate::font::FONT),
)
(appearance.hovered_text_color, crate::font::FONT)
} else {
(
appearance.text_color,
self.font.unwrap_or(crate::font::FONT),
)
(appearance.text_color, crate::font::FONT)
};

text::Renderer::fill_text(
Expand Down
10 changes: 4 additions & 6 deletions src/widget/dropdown/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ impl<'a, S: AsRef<str>, Message: 'a> Widget<Message, crate::Renderer> for Dropdo
self.gap,
self.padding,
self.text_size.unwrap_or(14.0),
self.font
.unwrap_or_else(|| text::Renderer::default_font(renderer)),
self.font,
self.selections,
self.selected,
&self.on_selected,
Expand Down Expand Up @@ -360,15 +359,15 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a>(
gap: f32,
padding: Padding,
text_size: f32,
font: crate::font::Font,
font: Option<crate::font::Font>,
selections: &'a [S],
selected_option: Option<usize>,
on_selected: &'a dyn Fn(usize) -> Message,
) -> Option<overlay::Element<'a, Message, crate::Renderer>> {
if state.is_open {
let bounds = layout.bounds();

let menu = Menu::new(
let mut menu = Menu::new(
&mut state.menu,
selections,
&mut state.hovered_option,
Expand All @@ -386,7 +385,7 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a>(
renderer,
label,
text_size,
font,
crate::font::FONT,
text::Shaping::Advanced,
);

Expand All @@ -403,7 +402,6 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a>(
+ padding.horizontal()
})
.padding(padding)
.font(font)
.text_size(text_size);

Some(menu.overlay(layout.position(), bounds.height))
Expand Down

0 comments on commit 79da230

Please sign in to comment.