Struct gtk4::PopoverMenu [−][src]
pub struct PopoverMenu(_);
Expand description
PopoverMenu
is a subclass of Popover
that implements menu
behavior.
PopoverMenu
treats its children like menus and allows switching
between them. It can open submenus as traditional, nested submenus,
or in a more touch-friendly sliding fashion.
PopoverMenu
is meant to be used primarily with menu models,
using from_model()
. If you need to put
other widgets such as a SpinButton
or a Switch
into a popover,
you can use add_child()
.
For more dialog-like behavior, use a plain Popover
.
Menu models
The XML format understood by Builder
for GMenuModel
consists
of a toplevel <menu>
element, which contains one or more <item>
elements. Each <item>
element contains <attribute>
and <link>
elements with a mandatory name attribute. <link>
elements have the
same content model as <menu>
. Instead of <link name="submenu">
or <link name="section">
, you can use <submenu>
or <section>
elements.
<menu id='app-menu'>
<section>
<item>
<attribute name='label' translatable='yes'>_New Window</attribute>
<attribute name='action'>app.new</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_About Sunny</attribute>
<attribute name='action'>app.about</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Quit</attribute>
<attribute name='action'>app.quit</attribute>
</item>
</section>
</menu>
Attribute values can be translated using gettext, like other Builder
content. <attribute>
elements can be marked for translation with a
translatable="yes"
attribute. It is also possible to specify message
context and translator comments, using the context and comments attributes.
To make use of this, the Builder
must have been given the gettext
domain to use.
The following attributes are used when constructing menu items:
- “label”: a user-visible string to display
- “action”: the prefixed name of the action to trigger
- “target”: the parameter to use when activating the action
- “icon” and “verb-icon”: names of icons that may be displayed
- “submenu-action”: name of an action that may be used to track whether a submenu is open
- “hidden-when”: a string used to determine when the item will be hidden.
Possible values include “action-disabled”, “action-missing”, “macos-menubar”.
This is mainly useful for exported menus, see
GtkApplicationExt::set_menubar()
. - “custom”: a string used to match against the ID of a custom child added with
add_child()
,PopoverMenuBar::add_child()
, or in the ui file with<child type="ID">
.
The following attributes are used when constructing sections:
- “label”: a user-visible string to use as section heading
- “display-hint”: a string used to determine special formatting for the section. Possible values include “horizontal-buttons”, “circular-buttons” and “inline-buttons”. They all indicate that section should be displayed as a horizontal row of buttons.
- “text-direction”: a string used to determine the
TextDirection
to use when “display-hint” is set to “horizontal-buttons”. Possible values include “rtl”, “ltr”, and “none”.
The following attributes are used when constructing submenus:
- “label”: a user-visible string to display
- “icon”: icon name to display
Menu items will also show accelerators, which are usually associated
with actions via GtkApplicationExt::set_accels_for_action()
,
[WidgetClass::add_binding_action
][crate::WidgetClass::add_binding_action] or
ShortcutController::add_shortcut()
.
CSS Nodes
PopoverMenu
is just a subclass of Popover
that adds custom content
to it, therefore it has the same CSS nodes. It is one of the cases that add
a .menu style class to the popover’s main node.
Accessibility
PopoverMenu
uses the AccessibleRole::Menu
role, and its
items use the AccessibleRole::MenuItem
,
AccessibleRole::MenuItemCheckbox
or
AccessibleRole::MenuItemRadio
roles, depending on the
action they are connected to.
Implements
PopoverExt
, WidgetExt
, glib::ObjectExt
, AccessibleExt
, BuildableExt
, ConstraintTargetExt
, NativeExt
, ShortcutManagerExt
, WidgetExtManual
, AccessibleExtManual
Implementations
Creates a PopoverMenu
and populates it according to model
.
The created buttons are connected to actions found in the
ApplicationWindow
to which the popover belongs - typically
by means of being attached to a widget that is contained within
the ApplicationWindow
s widget hierarchy.
Actions can also be added using WidgetExt::insert_action_group()
on the menus attach widget or on any of its parent widgets.
This function creates menus with sliding submenus.
See from_model_full()
for a way
to control this.
model
a GMenuModel
Returns
the new PopoverMenu
Creates a PopoverMenu
and populates it according to model
.
The created buttons are connected to actions found in the
action groups that are accessible from the parent widget.
This includes the ApplicationWindow
to which the popover
belongs. Actions can also be added using WidgetExt::insert_action_group()
on the parent widget or on any of its parent widgets.
The only flag that is supported currently is
PopoverMenuFlags::NESTED
, which makes GTK create traditional,
nested submenus instead of the default sliding submenus.
model
a GMenuModel
flags
flags that affect how the menu is created
Returns
the new PopoverMenu
Creates a new builder-pattern struct instance to construct PopoverMenu
objects.
This method returns an instance of PopoverMenuBuilder
which can be used to create PopoverMenu
objects.
Removes a widget that has previously been added with
add_child()
.
child
the Widget
to remove
Returns
true
if the widget was removed
Sets a new menu model on self
.
The existing contents of self
are removed, and
the self
is populated with new contents according
to model
.
model
a GMenuModel
The name of the visible submenu.
The name of the visible submenu.
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for PopoverMenu
impl !Send for PopoverMenu
impl !Sync for PopoverMenu
impl Unpin for PopoverMenu
impl UnwindSafe for PopoverMenu
Blanket Implementations
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T
. Read more
Upcasts an object to a reference of its superclass or interface T
. Read more
Tries to downcast to a subclass or interface implementor T
. Read more
Tries to downcast to a reference of its subclass or interface implementor T
. Read more
Tries to cast to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Casts to T
unconditionally. Read more
Casts to &T
unconditionally. Read more
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: Fn(&[Value]) -> Option<Value>,
Same as connect_unsafe
but takes a SignalId
instead of a signal name.
Emit signal by signal id.
Same as emit
but takes Value
for the arguments.
Emit signal by its name.
Same as emit_by_name
but takes Value
for the arguments.
Emit signal with details by signal id.
Same as emit_with_details
but takes Value
for the arguments.
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Returns a SendValue
clone of self
.