Struct MenuItem
pub struct MenuItem { /* private fields */ }
dep_fltk
only.Expand description
Creates a menu item
Implementations§
§impl MenuItem
impl MenuItem
pub unsafe fn as_ptr(&self) -> *mut Fl_Menu_Item
pub unsafe fn as_ptr(&self) -> *mut Fl_Menu_Item
Returns the inner pointer from a MenuItem
§Safety
Can return multiple mutable pointers to the same item
pub fn new(choices: &[&'static str]) -> MenuItem
pub fn new(choices: &[&'static str]) -> MenuItem
Initializes a new menu item. This will allocate a static MenuItem, that is expected to live for the entirety of the program.
pub fn popup(&self, x: i32, y: i32) -> Option<MenuItem> ⓘ
pub fn popup(&self, x: i32, y: i32) -> Option<MenuItem> ⓘ
Creates a popup menu at the specified coordinates and returns its choice
pub fn pulldown(
&self,
x: i32,
y: i32,
w: i32,
h: i32,
picked: Option<MenuItem>,
menu: Option<&impl MenuExt>,
) -> Option<MenuItem> ⓘ
pub fn pulldown( &self, x: i32, y: i32, w: i32, h: i32, picked: Option<MenuItem>, menu: Option<&impl MenuExt>, ) -> Option<MenuItem> ⓘ
Creates a pulldown menu at the specified coordinates and returns its choice
pub fn label_type(&self) -> LabelType
pub fn label_type(&self) -> LabelType
Returns the label type of the menu item
pub fn set_label_type(&mut self, typ: LabelType)
pub fn set_label_type(&mut self, typ: LabelType)
Sets the label type of the menu item
pub fn label_color(&self) -> Color
pub fn label_color(&self) -> Color
Returns the label color of the menu item
pub fn set_label_color(&mut self, color: Color)
pub fn set_label_color(&mut self, color: Color)
Sets the label color of the menu item
pub fn label_font(&self) -> Font
pub fn label_font(&self) -> Font
Returns the label font of the menu item
pub fn set_label_font(&mut self, font: Font)
pub fn set_label_font(&mut self, font: Font)
Sets the label font of the menu item
pub fn label_size(&self) -> i32
pub fn label_size(&self) -> i32
Returns the label size of the menu item
pub fn set_label_size(&mut self, sz: i32)
pub fn set_label_size(&mut self, sz: i32)
Sets the label size of the menu item
pub fn set(&mut self)
pub fn set(&mut self)
Sets the menu item
pub fn clear(&mut self)
pub fn clear(&mut self)
Turns the check or radio item “off” for the menu item
pub fn activate(&mut self)
pub fn activate(&mut self)
Activates the menu item
pub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Deactivates the menu item
Returns whether a menu item is a submenu
pub fn is_checkbox(&self) -> bool
pub fn is_checkbox(&self) -> bool
Returns whether a menu item is a checkbox
pub fn show(&mut self)
pub fn show(&mut self)
Shows the menu item
pub fn hide(&mut self)
pub fn hide(&mut self)
Hides the menu item
Get the submenu count
pub unsafe fn user_data(&self) -> Option<Box<dyn FnMut()>> ⓘ
pub unsafe fn user_data(&self) -> Option<Box<dyn FnMut()>> ⓘ
Get the user data
§Safety
Can return multiple mutable instances of the user data, which has a different lifetime than the object
pub fn set_callback<F>(&mut self, cb: F)
pub fn set_callback<F>(&mut self, cb: F)
Set a callback for the menu item
pub fn do_callback<W>(&mut self, w: &W)where
W: MenuExt,
pub fn do_callback<W>(&mut self, w: &W)where
W: MenuExt,
Run the menu item’s callback
pub fn was_deleted(&self) -> bool
pub fn was_deleted(&self) -> bool
Check if a menu item was deleted
pub fn draw<M>(&self, x: i32, y: i32, w: i32, h: i32, menu: &M, selected: bool)where
M: MenuExt,
pub fn draw<M>(&self, x: i32, y: i32, w: i32, h: i32, menu: &M, selected: bool)where
M: MenuExt,
Draw a box around the menu item. Requires the call to be made inside a MenuExt-implementing widget’s own draw method
pub fn add_image<I>(&mut self, image: Option<I>, on_left: bool)where
I: ImageExt,
pub fn add_image<I>(&mut self, image: Option<I>, on_left: bool)where
I: ImageExt,
Add an image to a menu item
use fltk::{prelude::*, *};
const PXM: &[&str] = &[
"13 11 3 1",
" c None",
"x c #d8d833",
"@ c #808011",
" ",
" @@@@ ",
" @xxxx@ ",
"@@@@@xxxx@@ ",
"@xxxxxxxxx@ ",
"@xxxxxxxxx@ ",
"@xxxxxxxxx@ ",
"@xxxxxxxxx@ ",
"@xxxxxxxxx@ ",
"@xxxxxxxxx@ ",
"@@@@@@@@@@@ "
];
let image = image::Pixmap::new(PXM).unwrap();
let mut menu = menu::MenuBar::default();
menu.add(
"&File/Open...\t",
enums::Shortcut::Ctrl | 'o',
menu::MenuFlag::Normal,
|_| println!("Opened file!"),
);
if let Some(mut item) = menu.find_item("&File/Open...\t") {
item.add_image(Some(image), true);
}
pub fn add<F>(
&mut self,
name: &str,
shortcut: Shortcut,
flag: MenuFlag,
cb: F,
) -> i32
pub fn add<F>( &mut self, name: &str, shortcut: Shortcut, flag: MenuFlag, cb: F, ) -> i32
Add a menu item
pub fn insert<F>(
&mut self,
idx: i32,
name: &str,
shortcut: Shortcut,
flag: MenuFlag,
cb: F,
) -> i32
pub fn insert<F>( &mut self, idx: i32, name: &str, shortcut: Shortcut, flag: MenuFlag, cb: F, ) -> i32
Insert a menu item
pub fn add_emit<T>(
&mut self,
label: &str,
shortcut: Shortcut,
flag: MenuFlag,
sender: Sender<T>,
msg: T,
) -> i32
pub fn add_emit<T>( &mut self, label: &str, shortcut: Shortcut, flag: MenuFlag, sender: Sender<T>, msg: T, ) -> i32
Add a menu item along with an emit (sender and message).
pub fn insert_emit<T>(
&mut self,
idx: i32,
label: &str,
shortcut: Shortcut,
flag: MenuFlag,
sender: Sender<T>,
msg: T,
) -> i32
pub fn insert_emit<T>( &mut self, idx: i32, label: &str, shortcut: Shortcut, flag: MenuFlag, sender: Sender<T>, msg: T, ) -> i32
Insert a menu item along with an emit (sender and message).
pub fn set_shortcut(&mut self, shortcut: Shortcut)
pub fn set_shortcut(&mut self, shortcut: Shortcut)
Set the menu item’s shortcut
Trait Implementations§
§impl IntoIterator for MenuItem
impl IntoIterator for MenuItem
impl Eq for MenuItem
impl Send for MenuItem
impl Sync for MenuItem
Auto Trait Implementations§
impl Freeze for MenuItem
impl RefUnwindSafe for MenuItem
impl Unpin for MenuItem
impl UnwindSafe for MenuItem
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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