gtk.expander

Module for [Expander] class

Types 3

[gtk.expander.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 [gtk.tree_view.TreeView].

Normally you use an expander as you would use a frame; you create the child widget and use [gtk.expander.Expander.setChild] 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 [gtk.expander.Expander] but do not add a child to it. The expander widget has an [gtk.expander.Expander.expanded] property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

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 [gtk.expander.Expander] implementation of the [gtk.buildable.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-widget
╰── box
   ├── title
   │   ├── expander
   │   ╰── <label widget>
   ╰── <child>

[gtk.expander.Expander] has a main node expander-widget, and subnode box containing the title and child widget. The box subnode title contains node expander, i.e. the expand/collapse arrow; then the label widget if any. The arrow of an expander that is showing its child gets the :checked pseudoclass set on it.

Accessibility

[gtk.expander.Expander] uses the [gtk.types.AccessibleRole.Button] role.

Methods
GType _gType() @property
Expander self()Returns `this`, for use in `with` statements.
ExpanderGidBuilder builder()Get builder for [gtk.expander.Expander] Returns: New builder object
gtk.widget.Widget child() @propertyGet `child` property. Returns: The child widget.
void child(gtk.widget.Widget propval) @propertySet `child` property. Params: propval = The child widget.
bool expanded() @propertyGet `expanded` property. Returns: Whether the expander has been opened to reveal the child.
void expanded(bool propval) @propertySet `expanded` property. Params: propval = Whether the expander has been opened to reveal the child.
string label() @propertyGet `label` property. Returns: The text of the expanders label.
void label(string propval) @propertySet `label` property. Params: propval = The text of the expanders label.
gtk.widget.Widget labelWidget() @propertyGet `labelWidget` property. Returns: A widget to display instead of the usual expander label.
void labelWidget(gtk.widget.Widget propval) @propertySet `labelWidget` property. Params: propval = A widget to display instead of the usual expander label.
bool resizeToplevel() @propertyGet `resizeToplevel` property. Returns: When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
void resizeToplevel(bool propval) @propertySet `resizeToplevel` property. Params: propval = When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
bool useMarkup() @propertyGet `useMarkup` property. Returns: Whether the text in the label is Pango markup.
void useMarkup(bool propval) @propertySet `useMarkup` property. Params: propval = Whether the text in the label is Pango markup.
bool useUnderline() @propertyGet `useUnderline` property. Returns: Whether an underline in the text indicates a mnemonic.
void useUnderline(bool propval) @propertySet `useUnderline` property. Params: propval = Whether an underline in the text indicates a mnemonic.
gtk.expander.Expander newWithMnemonic(string label = null)Creates a new expander using label as the text of the label.
gtk.widget.Widget getChild()Gets the child widget of expander. Returns: the child widget of expander
bool getExpanded()Queries a [gtk.expander.Expander] and returns its current state.
string getLabel()Fetches the text from a label widget.
gtk.widget.Widget getLabelWidget()Retrieves the label widget for the frame. Returns: the label widget
bool getResizeToplevel()Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing. Returns: the “resize toplevel” setting.
bool getUseMarkup()Returns whether the label’s text is interpreted as Pango markup. Returns: true if the label’s text will be parsed for markup
bool getUseUnderline()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
void setChild(gtk.widget.Widget child = null)Sets the child widget of expander.
void setExpanded(bool expanded)Sets the state of the expander.
void setLabel(string label = null)Sets the text of the label of the expander to label.
void setLabelWidget(gtk.widget.Widget labelWidget = null)Set the label widget for the expander.
void setResizeToplevel(bool resizeToplevel)Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.
void setUseMarkup(bool useMarkup)Sets whether the text of the label contains Pango markup.
void setUseUnderline(bool useUnderline)If true, an underline in the text indicates a mnemonic.
gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.expander.Expander))) && Parameters!T.length < 2)Connect to `Activate` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this(string label = null)Creates a new expander using label as the text of the label.
Methods
T child(gtk.widget.Widget propval)Set `child` property. Params: propval = The child widget. Returns: Builder instance for fluent chaining
T expanded(bool propval)Set `expanded` property. Params: propval = Whether the expander has been opened to reveal the child. Returns: Builder instance for fluent chaining
T label(string propval)Set `label` property. Params: propval = The text of the expanders label. Returns: Builder instance for fluent chaining
T labelWidget(gtk.widget.Widget propval)Set `labelWidget` property. Params: propval = A widget to display instead of the usual expander label. Returns: Builder instance for fluent chaining
T resizeToplevel(bool propval)Set `resizeToplevel` property. Params: propval = When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing. Returns: Builder ins...
T useMarkup(bool propval)Set `useMarkup` property. Params: propval = Whether the text in the label is Pango markup. Returns: Builder instance for fluent chaining
T useUnderline(bool propval)Set `useUnderline` property. Params: propval = Whether an underline in the text indicates a mnemonic. Returns: Builder instance for fluent chaining

Fluent builder for [gtk.expander.Expander]

Methods