pub struct MenuBar {
pub items: Vec<MenuItem>,
pub area: Option<Rect>,
pub normal_style: Style,
pub selected_style: Style,
pub hover_style: Style,
pub selected_hover_style: Style,
}Expand description
A horizontal menu bar with selectable items
Fields§
§items: Vec<MenuItem>§area: Option<Rect>§normal_style: Style§selected_style: Style§hover_style: Style§selected_hover_style: StyleImplementations§
Source§impl MenuBar
impl MenuBar
pub fn new(items: Vec<MenuItem>) -> Self
pub fn with_selected(self, index: usize) -> Self
pub fn normal_style(self, style: Style) -> Self
pub fn selected_style(self, style: Style) -> Self
pub fn hover_style(self, style: Style) -> Self
pub fn selected_hover_style(self, style: Style) -> Self
Source§impl MenuBar
impl MenuBar
Sourcepub fn apply_theme(&mut self, theme: &AppTheme)
pub fn apply_theme(&mut self, theme: &AppTheme)
Applies theme colors to the menu bar in place.
Unlike with_theme which consumes self, this method updates
the menu bar’s styles without consuming it. Useful for updating
the theme dynamically at runtime.
§Arguments
theme- The application theme to apply
§Example
use ratatui_toolkit::{MenuBar, MenuItem, AppTheme};
let theme = AppTheme::default();
let mut menu_bar = MenuBar::new(vec![
MenuItem::new("File", 0),
MenuItem::new("Edit", 1),
]);
menu_bar.apply_theme(&theme);Source§impl MenuBar
impl MenuBar
Sourcepub fn with_theme(self, theme: &AppTheme) -> Self
pub fn with_theme(self, theme: &AppTheme) -> Self
Applies theme colors to the menu bar.
This method configures all menu bar styles based on the provided theme, ensuring consistent styling across the application.
§Arguments
theme- The application theme to apply
§Returns
Self with theme colors applied for method chaining.
§Example
use ratatui_toolkit::{MenuBar, MenuItem, AppTheme};
let theme = AppTheme::default();
let menu_bar = MenuBar::new(vec![
MenuItem::new("File", 0),
MenuItem::new("Edit", 1),
])
.with_theme(&theme);Source§impl MenuBar
impl MenuBar
pub fn update_hover(&mut self, column: u16, row: u16)
pub fn handle_click(&mut self, column: u16, row: u16) -> Option<usize>
pub fn selected(&self) -> Option<usize>
Sourcepub fn render(&mut self, frame: &mut Frame<'_>, area: Rect)
pub fn render(&mut self, frame: &mut Frame<'_>, area: Rect)
Render the menu bar as a connected series of items with rounded border
Sourcepub fn render_with_offset(
&mut self,
frame: &mut Frame<'_>,
area: Rect,
left_offset: u16,
)
pub fn render_with_offset( &mut self, frame: &mut Frame<'_>, area: Rect, left_offset: u16, )
Render the menu bar with a left offset to make room for other components
Sourcepub fn render_centered(&mut self, frame: &mut Frame<'_>, area: Rect)
pub fn render_centered(&mut self, frame: &mut Frame<'_>, area: Rect)
Render with a centered layout (useful for menu bars)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MenuBar
impl RefUnwindSafe for MenuBar
impl Send for MenuBar
impl Sync for MenuBar
impl Unpin 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&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<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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().