pub struct MenuBar {
pub id: WidgetId,
pub items: Vec<MenuBarItem>,
pub open_item: Option<usize>,
pub focused_item: Option<usize>,
}Expand description
Declarative description of a menu bar.
§Examples
use quadraui::{MenuBar, MenuBarHit, MenuBarItem, MenuBarItemMeasure, Rect, WidgetId};
let bar = MenuBar {
id: WidgetId::new("menubar:main"),
items: vec![MenuBarItem {
id: WidgetId::new("menu:file"),
label: "&File".to_string(),
disabled: false,
submenu: None,
}],
open_item: None,
focused_item: None,
};
let layout = bar.layout(Rect::new(0.0, 0.0, 80.0, 1.0), |_| MenuBarItemMeasure::new(6.0));
assert_eq!(layout.hit_test(2.0, 0.0), MenuBarHit::Item(0));Fields§
§id: WidgetId§items: Vec<MenuBarItem>§open_item: Option<usize>Index of the currently-open menu (if any). Backends use this to render the “pressed” visual on the active item.
focused_item: Option<usize>Keyboard-focused item (for Alt+navigation) — may differ from
open_item during arrow-key traversal.
Implementations§
Source§impl MenuBar
impl MenuBar
Sourcepub fn layout<F>(&self, bounds: Rect, measure_item: F) -> MenuBarLayout
pub fn layout<F>(&self, bounds: Rect, measure_item: F) -> MenuBarLayout
Compute item positions along the bar.
§Arguments
bounds— menu-bar row.measure_item(i)— width of itemi.
Sourcepub fn layout_with_leading<F>(
&self,
bounds: Rect,
leading_width: f32,
measure_item: F,
) -> MenuBarLayout
pub fn layout_with_leading<F>( &self, bounds: Rect, leading_width: f32, measure_item: F, ) -> MenuBarLayout
Like Self::layout, but reserves leading_width device units
at the start of bounds for a fixed-size leading element — an
app-logo crate::Image left of the first menu item, VS-Code
style — before laying out items.
The offset math is the key concern: a consumer that narrows
the rect it hands to a paint call but not the rect it hands to a
click-routing call (or vice versa) gets a menu bar whose visible
items and clickable items silently disagree. Centralizing the shift
here means both call sites can pass the same bounds +
leading_width pair instead of each independently computing a
narrowed rect.
leading_width <= 0.0 behaves exactly like Self::layout
called with bounds unchanged. MenuBarLayout::bounds on the
result still covers the full bounds (including the reserved
leading region) so MenuBarLayout::hit_test’s “inside the bar”
check keeps treating a click over the icon as MenuBarHit::Bar
rather than MenuBarHit::Outside — callers that want to
special-case a click on the icon itself compare the click x
against bounds.x + leading_width themselves, since the icon’s
own geometry isn’t a MenuBar concern.
Sourcepub fn find_alt_target(&self, ch: char) -> Option<usize>
pub fn find_alt_target(&self, ch: char) -> Option<usize>
Find the index of the item whose label contains the Alt-key
character ch (case-insensitive). The label’s & prefix marks
the activation character; if no &, the first character is
used.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MenuBar
impl<'de> Deserialize<'de> for MenuBar
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for MenuBar
impl StructuralPartialEq for MenuBar
Auto Trait Implementations§
impl Freeze for MenuBar
impl RefUnwindSafe for MenuBar
impl Send for MenuBar
impl Sync for MenuBar
impl Unpin for MenuBar
impl UnsafeUnpin for MenuBar
impl UnwindSafe for MenuBar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more