Struct gtk4::Expander[][src]

pub struct Expander(_);
Expand description

Expander allows the user to reveal its child by clicking on an expander triangle.

An example GtkExpander

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.

label

the text of the label

Returns

a new Expander widget.

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.

Gets the child widget of self.

Returns

the child widget of self

Queries a Expander and returns its current state.

Returns true if the child widget is revealed.

Returns

the current state of the expander

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.

Retrieves the label widget for the frame.

Returns

the label widget

Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing.

Returns

the “resize toplevel” setting.

Returns whether the label’s text is interpreted as Pango markup.

Returns

true if the label’s text will be parsed for markup

Returns whether an underline in the text indicates a mnemonic.

Returns

true if an embedded underline in the expander label indicates the mnemonic accelerator keys

Sets the child widget of self.

child

the child widget

Sets the state of the expander.

Set to true, if you want the child widget to be revealed, and false if you want the child widget to be hidden.

expanded

whether the child widget is revealed

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

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

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

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.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.