Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
latidoremi committed Feb 23, 2024
1 parent 1f3f107 commit 6f7b7a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 55 deletions.
13 changes: 11 additions & 2 deletions examples/menu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use iced::widget::{column as col, vertical_space};
use iced::{alignment, theme, Application, Border, Color, Element, Length, Pixels, Size};

use iced_aw::graphics::icons::{BootstrapIcon, BOOTSTRAP_FONT, BOOTSTRAP_FONT_BYTES};
use iced_aw::menu::{Item, Menu};
use iced_aw::menu::{self, Item, Menu, StyleSheet};
use iced_aw::style::MenuBarStyle;
use iced_aw::{menu_bar, menu_items};
use iced_aw::{native::InnerBounds, quad};

Expand Down Expand Up @@ -428,7 +429,15 @@ impl Application for App {
(debug_button("MMNN").height(50))
)).width(slider_width * slider_count + (slider_count - 1) * spacing + pad)
})
);
)
.draw_path(menu::DrawPath::Backdrop)
.style(|theme:&iced::Theme| menu::Appearance{
path_border: Border{
radius: [6.0; 4].into(),
..Default::default()
},
..theme.appearance(&MenuBarStyle::Default)
});

let r = row![
horizontal_space().width(295),
Expand Down
8 changes: 4 additions & 4 deletions src/native/menu/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct CloseCondition {
///
/// ## FakeHovering:
///
/// Places cursors at the path items,
/// Places cursors at the path items,
/// useful when you want to customize the styling of each item in the path,
/// or you simple want the look of the items when they are hovered over.
///
Expand All @@ -32,9 +32,9 @@ pub struct CloseCondition {
/// useful when you want uniform path styling.
///
/// The downside is,
/// depend on the style you're going for,
/// oftentimes manually syncing the path's styling to the path items' is necessary
///
/// depending on the style you're going for,
/// oftentimes manually syncing the path's styling to the path items' is necessary,
/// the default styling simply can't cover most use cases.
pub enum DrawPath {
/// FakeHovering
FakeHovering,
Expand Down
6 changes: 6 additions & 0 deletions src/native/menu/menu_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ where
self.check_bounds_width = check_bounds_width;
self
}

/// Sets the draw path option of the [`MenuBar`]
pub fn draw_path(mut self, draw_path: DrawPath) -> Self {
self.draw_path = draw_path;
self
}

/// Sets the padding of the [`MenuBar`].
pub fn padding(mut self, padding: impl Into<Padding>) -> Self {
Expand Down
52 changes: 6 additions & 46 deletions src/native/menu/menu_bar_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ where
let active_tree = &mut self.tree.children[active];
let mut prev_bounds_list = vec![bar_bounds];

#[rustfmt::skip]
fn rec<'a, 'b, Message, Theme: StyleSheet, Renderer: renderer::Renderer>(
tree: &mut Tree,
item: &mut Item<'a, Message, Theme, Renderer>,
Expand Down Expand Up @@ -281,29 +282,13 @@ where
RecEvent::Event => RecEvent::Event,
RecEvent::Close => {
if cursor.is_over(prescroll) {
menu.on_event(
menu_tree,
event,
menu_layout,
cursor,
renderer,
clipboard,
shell,
viewport,
);
menu.on_event(menu_tree, event, menu_layout, cursor, renderer, clipboard, shell, viewport);
menu.open_event(menu_tree, menu_layout, cursor);
RecEvent::Event
} else if cursor.is_over(offset_bounds) {
RecEvent::Event
} else {
menu.close_event(
menu_tree,
menu_layout,
cursor,
parent_bounds,
prev_bounds_list,
prev,
);
menu.close_event(menu_tree, menu_layout, cursor, parent_bounds, prev_bounds_list, prev);
if prev.is_some() {
RecEvent::None
} else {
Expand All @@ -313,16 +298,7 @@ where
}
RecEvent::None => {
if cursor.is_over(prescroll) {
menu.on_event(
menu_tree,
event,
menu_layout,
cursor,
renderer,
clipboard,
shell,
viewport,
);
menu.on_event(menu_tree, event, menu_layout, cursor, renderer, clipboard, shell, viewport);
menu.open_event(menu_tree, menu_layout, cursor);
RecEvent::Event
} else if cursor.is_over(offset_bounds) {
Expand All @@ -336,29 +312,13 @@ where
prev_bounds_list.pop();

if cursor.is_over(prescroll) {
menu.on_event(
menu_tree,
event,
menu_layout,
cursor,
renderer,
clipboard,
shell,
viewport,
);
menu.on_event(menu_tree, event, menu_layout, cursor, renderer, clipboard, shell, viewport);
menu.open_event(menu_tree, menu_layout, cursor);
RecEvent::Event
} else if cursor.is_over(offset_bounds) {
RecEvent::Event
} else {
menu.close_event(
menu_tree,
menu_layout,
cursor,
parent_bounds,
prev_bounds_list,
prev,
);
menu.close_event(menu_tree, menu_layout, cursor, parent_bounds, prev_bounds_list, prev);
if prev.is_some() {
RecEvent::None
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/style/menu_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ pub enum MenuBarStyle {
Custom(Box<dyn StyleSheet<Style = Theme>>),
}

impl From<fn(&Theme) -> Appearance> for MenuBarStyle {
fn from(f: fn(&Theme) -> Appearance) -> Self {
impl<F: Fn(&Theme) -> Appearance + 'static> From<F> for MenuBarStyle {
fn from(f: F) -> Self {
Self::Custom(Box::new(f))
}
}

impl StyleSheet for fn(&Theme) -> Appearance {
impl<F: Fn(&Theme) -> Appearance> StyleSheet for F {
type Style = Theme;

fn appearance(&self, style: &Self::Style) -> Appearance {
Expand Down

0 comments on commit 6f7b7a6

Please sign in to comment.