Expander

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.

Constructors

this
this(void* ptr, Flag!"Take" take)
this
this(string label)

Creates a new expander using label as the text of the label.

Members

Functions

connectActivate
gulong connectActivate(T callback, Flag!"After" after)

Connect to Activate signal.

getExpanded
bool getExpanded()

Queries a #GtkExpander and returns its current state. Returns true if the child widget is revealed.

getLabel
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 return value will be null. This will be the case if you create an empty button with gtk.button.Button.new_ to use as a container.

getLabelFill
bool getLabelFill()

Returns whether the label widget will fill all available horizontal space allocated to expander.

getLabelWidget
gtk.widget.Widget getLabelWidget()

Retrieves the label widget for the frame. See gtk.expander.Expander.setLabelWidget.

getResizeToplevel
bool getResizeToplevel()

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

getSpacing
int getSpacing()

Gets the value set by gtk.expander.Expander.setSpacing.

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

getUseUnderline
bool getUseUnderline()

Returns whether an embedded underline in the expander label indicates a mnemonic. See gtk.expander.Expander.setUseUnderline.

self
Expander self()

Returns this, for use in with statements.

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

setLabel
void setLabel(string label)

Sets the text of the label of the expander to label.

setLabelFill
void setLabelFill(bool labelFill)

Sets whether the label widget should fill all available horizontal space allocated to expander.

setLabelWidget
void setLabelWidget(gtk.widget.Widget labelWidget)

Set the label widget for the expander. This is the widget that will appear embedded alongside the expander arrow.

setResizeToplevel
void setResizeToplevel(bool resizeToplevel)

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

setSpacing
void setSpacing(int spacing)

Sets the spacing field of expander, which is the number of pixels to place between expander and the child.

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

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

Properties

_gType
GType _gType [@property getter]
expanded
bool expanded [@property getter]
expanded
bool expanded [@property setter]
label
string label [@property getter]
label
string label [@property setter]
labelFill
bool labelFill [@property getter]

Get labelFill property.

labelFill
bool labelFill [@property setter]

Set labelFill property.

labelWidget
gtk.widget.Widget labelWidget [@property getter]
labelWidget
gtk.widget.Widget labelWidget [@property setter]
resizeToplevel
bool resizeToplevel [@property getter]

Get resizeToplevel property.

resizeToplevel
bool resizeToplevel [@property setter]

Set resizeToplevel property.

spacing
int spacing [@property getter]

Get spacing property.

spacing
int spacing [@property setter]

Set spacing property.

useMarkup
bool useMarkup [@property getter]
useMarkup
bool useMarkup [@property setter]
useUnderline
bool useUnderline [@property getter]
useUnderline
bool useUnderline [@property setter]

Static functions

_getGType
GType _getGType()
builder
ExpanderGidBuilder builder()

Get builder for gtk.expander.Expander

newWithMnemonic
gtk.expander.Expander newWithMnemonic(string label)

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.

Inherited Members

From Bin

_getGType
GType _getGType()
_gType
GType _gType [@property getter]
self
Bin self()

Returns this, for use in with statements.

builder
BinGidBuilder builder()

Get builder for gtk.bin.Bin

getChild
gtk.widget.Widget getChild()

Gets the child of the #GtkBin, or null if the bin contains no child widget. The returned widget does not have a reference added, so you do not need to unref it.