CtkExpander

CtkExpander — A container which can hide its child

Functions

Properties

gboolean expanded Read / Write / Construct
char * label Read / Write / Construct
gboolean label-fill Read / Write / Construct
CtkWidget * label-widget Read / Write
gboolean resize-toplevel Read / Write
int spacing Read / Write
gboolean use-markup Read / Write / Construct
gboolean use-underline Read / Write / Construct

Signals

void activate Action

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkContainer
                ╰── CtkBin
                    ╰── CtkExpander

Implemented Interfaces

CtkExpander implements AtkImplementorIface and CtkBuildable.

Includes

#include <ctk/ctk.h>

Description

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

Normally you use an expander as you would use any other descendant of CtkBin; you create the child widget and use ctk_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 CtkExpander but do not add a child to it. The expander widget has an “expanded” property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
static void
expander_callback (GObject    *object,
                   GParamSpec *param_spec,
                   gpointer    user_data)
{
  CtkExpander *expander;

  expander = CTK_EXPANDER (object);

  if (ctk_expander_get_expanded (expander))
    {
      // Show or create widgets
    }
  else
    {
      // Hide or destroy widgets
    }
}

static void
create_expander (void)
{
  CtkWidget *expander = ctk_expander_new_with_mnemonic ("_More Options");
  g_signal_connect (expander, "notify::expanded",
                    G_CALLBACK (expander_callback), NULL);

  // ...
}


CtkExpander as CtkBuildable

The CtkExpander implementation of the CtkBuildable 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 CtkExpander:

1
2
3
4
5
6
7
8
<object class="CtkExpander">
  <child type="label">
    <object class="CtkLabel" id="expander-label"/>
  </child>
  <child>
    <object class="CtkEntry" id="expander-content"/>
  </child>
</object>


CSS nodes

1
2
3
4
5
expander
├── title
   ├── arrow
   ╰── <label widget>
╰── <child>

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

Functions

ctk_expander_new ()

CtkWidget *
ctk_expander_new (const gchar *label);

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

Parameters

label

the text of the label.

[nullable]

Returns

a new CtkExpander widget.

Since: 2.4


ctk_expander_new_with_mnemonic ()

CtkWidget *
ctk_expander_new_with_mnemonic (const gchar *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.

Parameters

label

the text of the label with an underscore in front of the mnemonic character.

[nullable]

Returns

a new CtkExpander widget.

Since: 2.4


ctk_expander_set_expanded ()

void
ctk_expander_set_expanded (CtkExpander *expander,
                           gboolean 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.

Parameters

expander

a CtkExpander

 

expanded

whether the child widget is revealed

 

Since: 2.4


ctk_expander_get_expanded ()

gboolean
ctk_expander_get_expanded (CtkExpander *expander);

Queries a CtkExpander and returns its current state. Returns TRUE if the child widget is revealed.

See ctk_expander_set_expanded().

Parameters

expander

a CtkExpander

 

Returns

the current state of the expander

Since: 2.4


ctk_expander_set_spacing ()

void
ctk_expander_set_spacing (CtkExpander *expander,
                          gint spacing);

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

Parameters

expander

a CtkExpander

 

spacing

distance between the expander and child in pixels

 

Since: 2.4


ctk_expander_get_spacing ()

gint
ctk_expander_get_spacing (CtkExpander *expander);

Gets the value set by ctk_expander_set_spacing().

Parameters

expander

a CtkExpander

 

Returns

spacing between the expander and child

Since: 2.4


ctk_expander_set_label ()

void
ctk_expander_set_label (CtkExpander *expander,
                        const gchar *label);

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

This will also clear any previously set labels.

Parameters

expander

a CtkExpander

 

label

a string.

[nullable]

Since: 2.4


ctk_expander_get_label ()

const gchar *
ctk_expander_get_label (CtkExpander *expander);

Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup, as set by ctk_expander_set_label(). 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 ctk_button_new() to use as a container.

Note that this function behaved differently in versions prior to 2.14 and used to return the label text stripped of embedded underlines indicating mnemonics and Pango markup. This problem can be avoided by fetching the label text directly from the label widget.

Parameters

expander

a CtkExpander

 

Returns

The text of the label widget. This string is owned by the widget and must not be modified or freed.

[nullable]

Since: 2.4


ctk_expander_set_use_underline ()

void
ctk_expander_set_use_underline (CtkExpander *expander,
                                gboolean use_underline);

If true, an underline in the text of the expander label indicates the next character should be used for the mnemonic accelerator key.

Parameters

expander

a CtkExpander

 

use_underline

TRUE if underlines in the text indicate mnemonics

 

Since: 2.4


ctk_expander_get_use_underline ()

gboolean
ctk_expander_get_use_underline (CtkExpander *expander);

Returns whether an embedded underline in the expander label indicates a mnemonic. See ctk_expander_set_use_underline().

Parameters

expander

a CtkExpander

 

Returns

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

Since: 2.4


ctk_expander_set_use_markup ()

void
ctk_expander_set_use_markup (CtkExpander *expander,
                             gboolean use_markup);

Sets whether the text of the label contains markup in Pango’s text markup language. See ctk_label_set_markup().

Parameters

expander

a CtkExpander

 

use_markup

TRUE if the label’s text should be parsed for markup

 

Since: 2.4


ctk_expander_get_use_markup ()

gboolean
ctk_expander_get_use_markup (CtkExpander *expander);

Returns whether the label’s text is interpreted as marked up with the Pango text markup language. See ctk_expander_set_use_markup().

Parameters

expander

a CtkExpander

 

Returns

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

Since: 2.4


ctk_expander_set_label_widget ()

void
ctk_expander_set_label_widget (CtkExpander *expander,
                               CtkWidget *label_widget);

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

Parameters

expander

a CtkExpander

 

label_widget

the new label widget.

[nullable]

Since: 2.4


ctk_expander_get_label_widget ()

CtkWidget *
ctk_expander_get_label_widget (CtkExpander *expander);

Retrieves the label widget for the frame. See ctk_expander_set_label_widget().

Parameters

expander

a CtkExpander

 

Returns

the label widget, or NULL if there is none.

[nullable][transfer none]

Since: 2.4


ctk_expander_set_label_fill ()

void
ctk_expander_set_label_fill (CtkExpander *expander,
                             gboolean label_fill);

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

Note that this function has no effect since 3.20.

Parameters

expander

a CtkExpander

 

label_fill

TRUE if the label should should fill all available horizontal space

 

Since: 2.22


ctk_expander_get_label_fill ()

gboolean
ctk_expander_get_label_fill (CtkExpander *expander);

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

Parameters

expander

a CtkExpander

 

Returns

TRUE if the label widget will fill all available horizontal space

Since: 2.22


ctk_expander_set_resize_toplevel ()

void
ctk_expander_set_resize_toplevel (CtkExpander *expander,
                                  gboolean resize_toplevel);

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

Parameters

expander

a CtkExpander

 

resize_toplevel

whether to resize the toplevel

 

Since: 3.2


ctk_expander_get_resize_toplevel ()

gboolean
ctk_expander_get_resize_toplevel (CtkExpander *expander);

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

Parameters

expander

a CtkExpander

 

Returns

the “resize toplevel” setting.

Since: 3.2

Types and Values

struct CtkExpander

struct CtkExpander;

struct CtkExpanderClass

struct CtkExpanderClass {
  CtkBinClass    parent_class;

  /* Key binding signal; to get notification on the expansion
   * state connect to notify:expanded.
   */
  void        (* activate) (CtkExpander *expander);
};

Members

activate ()

Keybinding signal is emitted when the user hits the Enter key.

 

Property Details

The “expanded” property

  “expanded”                 gboolean

Whether the expander has been opened to reveal the child widget.

Owner: CtkExpander

Flags: Read / Write / Construct

Default value: FALSE


The “label” property

  “label”                    char *

Text of the expander's label.

Owner: CtkExpander

Flags: Read / Write / Construct

Default value: NULL


The “label-fill” property

  “label-fill”               gboolean

Whether the label widget should fill all available horizontal space.

Note that this property is ignored since 3.20.

Owner: CtkExpander

Flags: Read / Write / Construct

Default value: FALSE


The “label-widget” property

  “label-widget”             CtkWidget *

A widget to display in place of the usual expander label.

Owner: CtkExpander

Flags: Read / Write


The “resize-toplevel” property

  “resize-toplevel”          gboolean

When this property is TRUE, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.

Owner: CtkExpander

Flags: Read / Write

Default value: FALSE

Since: 3.2


The “spacing” property

  “spacing”                  int

Space to put between the label and the child when the expander is expanded.

CtkExpander:spacing has been deprecated since version 3.20 and should not be used in newly-written code.

This property is deprecated and ignored. Use margins on the child instead.

Owner: CtkExpander

Flags: Read / Write

Allowed values: >= 0

Default value: 0


The “use-markup” property

  “use-markup”               gboolean

The text of the label includes XML markup. See pango_parse_markup().

Owner: CtkExpander

Flags: Read / Write / Construct

Default value: FALSE


The “use-underline” property

  “use-underline”            gboolean

If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

Owner: CtkExpander

Flags: Read / Write / Construct

Default value: FALSE

Signal Details

The “activate” signal

void
user_function (CtkExpander *ctkexpander,
               gpointer     user_data)

Flags: Action