pub struct MenuAcceleratorLabel {
pub key: Option<KeyRef>,
pub label: String,
pub builder: MenuAcceleratorChildBuilder,
}Expand description
A widget that draws the label text for a menu item (typically a
MenuItemButton or SubmenuButton) and renders its child with information
about the currently active keyboard accelerator.
On platforms other than macOS and iOS, this widget listens for the Alt key
to be pressed, and when it is down, will update the label by calling the
builder again with the position of the accelerator in the label string.
While the Alt key is pressed, it registers a shortcut with the
ShortcutRegistry mapped to a VoidCallbackIntent containing the callback
defined by the nearest MenuAcceleratorCallbackBinding.
Because the accelerators are registered with the ShortcutRegistry, any
other shortcuts in the widget tree between the primary focus and the
ShortcutRegistry that define Alt-based shortcuts using the same keys will
take precedence over the accelerators.
Because accelerators aren’t used on macOS and iOS, the label ignores the Alt
key on those platforms, and the builder is always given -1 as an
accelerator index. Accelerator labels are still stripped of their
accelerator markers.
The built-in menu items MenuItemButton and SubmenuButton already provide
the appropriate MenuAcceleratorCallbackBinding, so unless you are creating
your own custom menu item type that takes a MenuAcceleratorLabel, it is
not necessary to provide one.
Fields§
§key: Option<KeyRef>See Widget::key.
label: StringThe label string that should be displayed.
The label string provides the label text, as well as the possible characters which could be used as accelerators in the menu system.
To indicate which letters in the label are to be used as accelerators, add
an “&” character before the character in the string. If more than one
character has an “&” in front of it, then the characters appearing earlier
in the string are preferred. To represent a literal “&”, insert “&&” into
the string. All other ampersands will be removed from the string before
calling MenuAcceleratorLabel::builder. Bare ampersands at the end of the
string or before whitespace are stripped and ignored.
See also:
display_label, which returns thelabelwith all of the ampersands stripped out of it, and double ampersands converted to ampersands.strip_accelerator_markers, which returns the supplied string with all of the ampersands stripped out of it, and double ampersands converted to ampersands, and optionally calls a callback with the index of the accelerator character found.
builder: MenuAcceleratorChildBuilderThe optional MenuAcceleratorChildBuilder which is used to build the
widget that displays the label itself.
The default_label_builder function serves as the
default value for builder, rendering the label as a RichText
widget with appropriate TextSpans for rendering the label with an underscore under
the selected accelerator for the label when accelerators have been activated.
When writing the builder function, it’s not necessary to take the current platform into account. On platforms which don’t support accelerators (e.g. macOS and iOS), the passed accelerator index will always be -1, and the accelerator markers will already be stripped.
Implementations§
Source§impl MenuAcceleratorLabel
impl MenuAcceleratorLabel
Sourcepub fn new(label: impl Into<String>) -> MenuAcceleratorLabel
pub fn new(label: impl Into<String>) -> MenuAcceleratorLabel
Creates a const MenuAcceleratorLabel.
The label parameter is required.
Sourcepub fn key(self, key: KeyRef) -> MenuAcceleratorLabel
pub fn key(self, key: KeyRef) -> MenuAcceleratorLabel
Dart MenuAcceleratorLabel(key:).
Sourcepub fn builder(
self,
builder: impl Fn(&mut App, BuildContext, &str, isize) -> WidgetRef + 'static,
) -> MenuAcceleratorLabel
pub fn builder( self, builder: impl Fn(&mut App, BuildContext, &str, isize) -> WidgetRef + 'static, ) -> MenuAcceleratorLabel
Dart MenuAcceleratorLabel(builder:).
Sourcepub fn display_label(&self) -> String
pub fn display_label(&self) -> String
Returns the label with any accelerator markers removed.
This getter just calls strip_accelerator_markers
with the label.
Sourcepub fn has_accelerator(&self) -> bool
pub fn has_accelerator(&self) -> bool
Whether label contains an accelerator definition.
Dart’s RegExp(r'&(?!([&\s]|$))'): an ampersand followed by a character that is
neither an ampersand nor whitespace.
Sourcepub fn default_label_builder(
app: &mut App,
context: BuildContext,
label: &str,
index: isize,
) -> WidgetRef
pub fn default_label_builder( app: &mut App, context: BuildContext, label: &str, index: isize, ) -> WidgetRef
Serves as the default value for builder, rendering the label as a
RichText widget with appropriate TextSpans for rendering the label with an
underscore under the selected accelerator for the label when the index is
non-negative, and a Text widget when the index is negative.
Sourcepub fn strip_accelerator_markers(
label: &str,
set_index: Option<&mut dyn FnMut(isize)>,
) -> String
pub fn strip_accelerator_markers( label: &str, set_index: Option<&mut dyn FnMut(isize)>, ) -> String
Strips out any accelerator markers from the given label, and unescapes
any escaped ampersands.
If set_index is supplied, it will be called before this function returns
with the index in the returned string of the accelerator character.
See label for the markers.
Trait Implementations§
Source§impl Debug for MenuAcceleratorLabel
impl Debug for MenuAcceleratorLabel
Source§impl StatefulWidget for MenuAcceleratorLabel
impl StatefulWidget for MenuAcceleratorLabel
Source§type State = MenuAcceleratorLabelState
type State = MenuAcceleratorLabelState
Source§fn debug_fill_properties(
&self,
__app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, __app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_state(&self) -> MenuAcceleratorLabelState
fn create_state(&self) -> MenuAcceleratorLabelState
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
impl !RefUnwindSafe for MenuAcceleratorLabel
impl !Send for MenuAcceleratorLabel
impl !Sync for MenuAcceleratorLabel
impl !UnwindSafe for MenuAcceleratorLabel
impl Forget for MenuAcceleratorLabel
impl Freeze for MenuAcceleratorLabelwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const RcInner<dyn Fn(&mut App, AnyElement, &str, isize) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &str, isize) -> Rc<dyn Widget>>>: Freeze,
impl Move for MenuAcceleratorLabel
impl Unpin for MenuAcceleratorLabel
impl UnsafeUnpin for MenuAcceleratorLabelwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, AnyElement, &str, isize) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &str, isize) -> Rc<dyn Widget>>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.