gtk.expander

Module for [Expander] class

Types 3

A #GtkExpander allows the user to hide or show its child by clicking on an expander triangle similar to the triangles used in a #GtkTreeView.

Normally you use an expander as you would use any other descendant of #GtkBin; you create the child widget and use [gtk.container.Container.add] 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 #GtkExpander but do not add a child to it. The expander widget has an #GtkExpander: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 GtkExpander implementation of the GtkBuildable 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
├── title
│   ├── arrow
│   ╰── <label widget>
╰── <child>

GtkExpander 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.

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
bool expanded() @property
void expanded(bool propval) @property
string label() @property
void label(string propval) @property
bool labelFill() @propertyGet `labelFill` property. Returns: Whether the label widget should fill all available horizontal space.
void labelFill(bool propval) @propertySet `labelFill` property. Params: propval = Whether the label widget should fill all available horizontal space.
void labelWidget(gtk.widget.Widget propval) @property
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.
int spacing() @propertyGet `spacing` property. Returns: Space to put between the label and the child when the expander is expanded.
void spacing(int propval) @propertySet `spacing` property. Params: propval = Space to put between the label and the child when the expander is expanded.
bool useMarkup() @property
void useMarkup(bool propval) @property
bool useUnderline() @property
void useUnderline(bool propval) @property
gtk.expander.Expander newWithMnemonic(string label = null)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 ...
bool getExpanded()Queries a #GtkExpander and returns its current state. Returns true if the child widget is revealed.
string getLabel()Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup, as set by [gtk.expander.Expander.setLabel]. If the label text has not been set the retu...
bool getLabelFill()Returns whether the label widget will fill all available horizontal space allocated to expander. Returns: true if the label widget will fill all available horizontal space
gtk.widget.Widget getLabelWidget()Retrieves the label widget for the frame. See [gtk.expander.Expander.setLabelWidget]. Returns: the label widget, or null if there is none
bool getResizeToplevel()Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing. Returns: the “resize toplevel” setting.
int getSpacing()Gets the value set by [gtk.expander.Expander.setSpacing]. Returns: spacing between the expander and child
bool getUseMarkup()Returns whether the label’s text is interpreted as marked up with the [Pango text markup language][PangoMarkupFormat]. See [gtk.expander.Expander.setUseMarkup]. Returns: true if the label’s tex...
bool getUseUnderline()Returns whether an embedded underline in the expander label indicates a mnemonic. See [gtk.expander.Expander.setUseUnderline]. Returns: true if an embedded underline in the expander label indicates...
void setExpanded(bool expanded)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.
void setLabel(string label = null)Sets the text of the label of the expander to label.
void setLabelFill(bool labelFill)Sets whether the label widget should fill all available horizontal space allocated to expander.
void setLabelWidget(gtk.widget.Widget labelWidget = null)Set the label widget for the expander. This is the widget that will appear embedded alongside the expander arrow.
void setResizeToplevel(bool resizeToplevel)Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing.
void setSpacing(int spacing)Sets the spacing field of expander, which is the number of pixels to place between expander and the child.
void setUseMarkup(bool useMarkup)Sets whether the text of the label contains markup in [Pango’s text markup language][PangoMarkupFormat]. See [gtk.label.Label.setMarkup].
void setUseUnderline(bool useUnderline)If true, an underline in the text of the expander label indicates the next character should be used for the mnemonic accelerator key.
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 expanded(bool propval)
T label(string propval)
T labelFill(bool propval)Set `labelFill` property. Params: propval = Whether the label widget should fill all available horizontal space.
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 spacing(int propval)Set `spacing` property. Params: propval = Space to put between the label and the child when the expander is expanded. Returns: Builder instance for fluent chaining
T useMarkup(bool propval)
T useUnderline(bool propval)

Fluent builder for [gtk.expander.Expander]

Methods