Class: Gtk::Expander

Inherits:
Widget
  • Object
show all
Defined in:
(unknown)

Overview

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

Normally you use an expander as you would use a frame; you create the child widget and use [methodGtk.Expander.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 GtkExpander but do not add a child to it. The expander widget has an [propertyGtk.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 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-widget
╰── box
    ├── title
    │   ├── expander
    │   ╰── <label widget>
    ╰── <child>

GtkExpander 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

GtkExpander uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.

Instance Method Summary collapse

Methods inherited from Widget

#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_state_flags, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #template=, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=

Constructor Details

#initialize(label) ⇒ Gtk::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.

Parameters:

  • label (String)

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

Instance Method Details

#childGtk::Widget

The child widget.

Returns:

#child=(child) ⇒ Gtk::Widget

The child widget.

Parameters:

Returns:

#expandedBoolean

Queries a GtkExpander and returns its current state.

Returns true if the child widget is revealed.

Returns:

  • (Boolean)

    the current state of the expander

#expanded=(expanded) ⇒ Boolean

Whether the expander has been opened to reveal the child.

Parameters:

  • expanded (Boolean)

Returns:

  • (Boolean)

    expanded

  • (Boolean)

    expanded

#expanded?Boolean

Whether the expander has been opened to reveal the child.

Returns:

  • (Boolean)

    expanded

#labelString

The text of the expanders label.

Returns:

  • (String)

    label

#label=(label) ⇒ String

The text of the expanders label.

Parameters:

  • label (String)

Returns:

  • (String)

    label

  • (String)

    label

#label_widgetGtk::Widget

A widget to display instead of the usual expander label.

Returns:

#label_widget=(label_widget) ⇒ Gtk::Widget

A widget to display instead of the usual expander label.

Parameters:

Returns:

#resize_toplevelBoolean

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

Returns:

  • (Boolean)

    the “resize toplevel” setting.

#resize_toplevel=(resize_toplevel) ⇒ Boolean

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

Parameters:

  • resize_toplevel (Boolean)

Returns:

  • (Boolean)

    resize-toplevel

  • (Boolean)

    resize-toplevel

#resize_toplevel?Boolean

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

Returns:

  • (Boolean)

    resize-toplevel

#use_markupBoolean

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

Returns:

  • (Boolean)

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

#use_markup=(use_markup) ⇒ Boolean

Whether the text in the label is Pango markup.

Parameters:

  • use_markup (Boolean)

Returns:

  • (Boolean)

    use-markup

  • (Boolean)

    use-markup

#use_markup?Boolean

Whether the text in the label is Pango markup.

Returns:

  • (Boolean)

    use-markup

#use_underlineBoolean

Returns whether an underline in the text indicates a mnemonic.

Returns:

  • (Boolean)

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

#use_underline=(use_underline) ⇒ Boolean

Whether an underline in the text indicates a mnemonic.

Parameters:

  • use_underline (Boolean)

Returns:

  • (Boolean)

    use-underline

  • (Boolean)

    use-underline

#use_underline?Boolean

Whether an underline in the text indicates a mnemonic.

Returns:

  • (Boolean)

    use-underline