Struct gtk4::Expander [−][src]
pub struct Expander(_);
Expand description
Expander
allows the user to reveal its child by clicking
on an expander triangle.
This is similar to the triangles used in a TreeView
.
Normally you use an expander as you would use a frame; you create
the child widget and use set_child()
to add it
to the expander. When the expander is toggled, it will take care of
showing and hiding the child automatically.
Special Usage
There are situations in which you may prefer to show and hide the
expanded widget yourself, such as when you want to actually create
the widget at expansion time. In this case, create a Expander
but do not add a child to it. The expander widget has an
property::Expander::expanded
[ property which can be used to
monitor its expansion state. You should watch this property with
a signal connection as follows:
⚠️ The following code is in c ⚠️
static void
expander_callback (GObject *object,
GParamSpec *param_spec,
gpointer user_data)
{
GtkExpander *expander;
expander = GTK_EXPANDER (object);
if (gtk_expander_get_expanded (expander))
{
// Show or create widgets
}
else
{
// Hide or destroy widgets
}
}
static void
create_expander (void)
{
GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options");
g_signal_connect (expander, "notify::expanded",
G_CALLBACK (expander_callback), NULL);
// ...
}
GtkExpander as GtkBuildable
The Expander
implementation of the Buildable
interface supports
placing a child in the label position by specifying “label” as the
“type” attribute of a <child>
element. A normal content child can be
specified without specifying a <child>
type attribute.
An example of a UI definition fragment with GtkExpander:
<object class="GtkExpander">
<child type="label">
<object class="GtkLabel" id="expander-label"/>
</child>
<child>
<object class="GtkEntry" id="expander-content"/>
</child>
</object>
CSS nodes
expander
╰── box
├── title
│ ├── arrow
│ ╰── <label widget>
╰── <child>
Expander
has three CSS nodes, the main node with the name expander,
a subnode with name title and node below it with name arrow. The arrow of an
expander that is showing its child gets the :checked pseudoclass added to it.
Accessibility
Expander
uses the AccessibleRole::Button
role.
Implements
WidgetExt
, glib::ObjectExt
, AccessibleExt
, BuildableExt
, ConstraintTargetExt
, WidgetExtManual
, AccessibleExtManual
Implementations
Creates a new expander using label
as the text of the label.
If characters in label
are preceded by an underscore, they are
underlined. If you need a literal underscore character in a label,
use “__” (two underscores). The first underlined character represents
a keyboard accelerator called a mnemonic.
Pressing Alt and that key activates the button.
label
the text of the label with an underscore in front of the mnemonic character
Returns
a new Expander
widget.
Creates a new builder-pattern struct instance to construct Expander
objects.
This method returns an instance of ExpanderBuilder
which can be used to create Expander
objects.
Fetches the text from a label widget.
This is including any embedded underlines indicating mnemonics and
Pango markup, as set by set_label()
. If the label
text has not been set the return value will be None
. This will be the
case if you create an empty button with Button::new()
to use as a
container.
Returns
The text of the label widget. This string is owned by the widget and must not be modified or freed.
Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing.
Returns
the “resize toplevel” setting.
Sets the text of the label of the expander to label
.
This will also clear any previously set labels.
label
a string
Set the label widget for the expander.
This is the widget that will appear embedded alongside the expander arrow.
label_widget
the new label widget
Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing.
resize_toplevel
whether to resize the toplevel
Sets whether the text of the label contains Pango markup.
use_markup
true
if the label’s text should be parsed for markup
If true, an underline in the text indicates a mnemonic.
use_underline
true
if underlines in the text indicate mnemonics
Activates the Expander
.
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 Expander
impl UnwindSafe for Expander
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
.