Struct gtk4::Notebook[][src]

pub struct Notebook(_);
Expand description

Notebook is a container whose children are pages switched between using tabs.

An example GtkNotebook

There are many configuration options for Notebook. Among other things, you can choose on which edge the tabs appear (see set_tab_pos()), whether, if there are too many tabs to fit the notebook should be made bigger or scrolling arrows added (see set_scrollable()), and whether there will be a popup menu allowing the users to switch pages. (see popup_enable()).

GtkNotebook as GtkBuildable

The Notebook implementation of the Buildable interface supports placing children into tabs by specifying “tab” as the “type” attribute of a <child> element. Note that the content of the tab must be created before the tab can be filled. A tab child can be specified without specifying a <child> type attribute.

To add a child widget in the notebooks action area, specify “action-start” or “action-end” as the “type” attribute of the <child> element.

An example of a UI definition fragment with Notebook:

<object class="GtkNotebook">
  <child>
    <object class="GtkLabel" id="notebook-content">
      <property name="label">Content</property>
    </object>
  </child>
  <child type="tab">
    <object class="GtkLabel" id="notebook-tab">
      <property name="label">Tab</property>
    </object>
  </child>
</object>

CSS nodes

notebook
├── header.top
│   ├── [<action widget>]
│   ├── tabs
│   │   ├── [arrow]
│   │   ├── tab
│   │   │   ╰── <tab label>
┊   ┊   ┊
│   │   ├── tab[.reorderable-page]
│   │   │   ╰── <tab label>
│   │   ╰── [arrow]
│   ╰── [<action widget>]
│
╰── stack
    ├── <child>
    ┊
    ╰── <child>

Notebook has a main CSS node with name notebook, a subnode with name header and below that a subnode with name tabs which contains one subnode per tab with name tab.

If action widgets are present, their CSS nodes are placed next to the tabs node. If the notebook is scrollable, CSS nodes with name arrow are placed as first and last child of the tabs node.

The main node gets the .frame style class when the notebook has a border (see set_show_border()).

The header node gets one of the style class .top, .bottom, .left or .right, depending on where the tabs are placed. For reorderable pages, the tab node gets the .reorderable-page class.

A tab node gets the .dnd style class while it is moved with drag-and-drop.

The nodes are always arranged from left-to-right, regardless of text direction.

Accessibility

Notebook uses the following roles:

Implements

WidgetExt, glib::ObjectExt, AccessibleExt, BuildableExt, ConstraintTargetExt, WidgetExtManual, AccessibleExtManual

Implementations

Creates a new Notebook widget with no pages.

Returns

the newly created Notebook

Creates a new builder-pattern struct instance to construct Notebook objects.

This method returns an instance of NotebookBuilder which can be used to create Notebook objects.

Removes the child from the notebook.

This function is very similar to remove_page(), but additionally informs the notebook that the removal is happening as part of a tab DND operation, which should not be cancelled.

child

a child

Gets one of the action widgets.

See set_action_widget().

pack_type

pack type of the action widget to receive

Returns

The action widget with the given pack_type or None when this action widget has not been set

Gets the current group name for self.

Returns

the group name, or None if none is set

Retrieves the menu label widget of the page containing child.

child

a widget contained in a page of self

Returns

the menu label, or None if the notebook page does not have a menu label other than the default (the tab label).

Retrieves the text of the menu label for the page containing child.

child

the child widget of a page of the notebook.

Returns

the text of the tab label, or None if the widget does not have a menu label other than the default menu label, or the menu label widget is not a Label. The string is owned by the widget and must not be freed.

Returns the NotebookPage for child.

child

a child of self

Returns

the NotebookPage for child

Returns a GListModel that contains the pages of the notebook.

This can be used to keep an up-to-date view. The model also implements SelectionModel and can be used to track and modify the visible page.

Returns

a GListModel for the notebook’s children

Returns whether the tab label area has arrows for scrolling.

Returns

true if arrows for scrolling are present

Returns whether a bevel will be drawn around the notebook pages.

Returns

true if the bevel is drawn

Returns whether the tabs of the notebook are shown.

Returns

true if the tabs are shown

Returns whether the tab contents can be detached from self.

child

a child Widget

Returns

true if the tab is detachable.

Returns the tab label widget for the page child.

None is returned if child is not in self or if no tab label has specifically been set for child.

child

the page

Returns

the tab label

Retrieves the text of the tab label for the page containing child.

child

a widget contained in a page of self

Returns

the text of the tab label, or None if the tab label idget is not a Label. The string is owned by the widget and must not be freed.

Gets the edge at which the tabs are drawn.

Returns

the edge at which the tabs are drawn

Gets whether the tab can be reordered via drag and drop or not.

child

a child Widget

Returns

true if the tab is reorderable.

Switches to the next page.

Nothing happens if the current page is the last page.

Disables the popup menu.

Enables the popup menu.

If the user clicks with the right mouse button on the tab labels, a menu with all the pages will be popped up.

Switches to the previous page.

Nothing happens if the current page is the first page.

Sets widget as one of the action widgets.

Depending on the pack type the widget will be placed before or after the tabs. You can use a Box if you need to pack more than one widget on the same side.

widget

a Widget

pack_type

pack type of the action widget

Sets a group name for self.

Notebooks with the same name will be able to exchange tabs via drag and drop. A notebook with a None group name will not be able to exchange tabs with any other notebook.

group_name

the name of the notebook group, or None to unset it

Changes the menu label for the page containing child.

child

the child widget

the menu label, or None for default

Creates a new label and sets it as the menu label of child.

child

the child widget

the label text

Sets whether the tab label area will have arrows for scrolling if there are too many tabs to fit in the area.

scrollable

true if scroll arrows should be added

Sets whether a bevel will be drawn around the notebook pages.

This only has a visual effect when the tabs are not shown.

show_border

true if a bevel should be drawn around the notebook

Sets whether to show the tabs for the notebook or not.

show_tabs

true if the tabs should be shown

Sets whether the tab can be detached from self to another notebook or widget.

Note that two notebooks must share a common group identificator (see set_group_name()) to allow automatic tabs interchange between them.

If you want a widget to interact with a notebook through DnD (i.e.: accept dragged tabs from it) it must be set as a drop destination and accept the target “GTK_NOTEBOOK_TAB”. The notebook will fill the selection with a GtkWidget** pointing to the child widget that corresponds to the dropped tab.

Note that you should use detach_tab() instead of remove_page() if you want to remove the tab from the source notebook as part of accepting a drop. Otherwise, the source notebook will think that the dragged tab was removed from underneath the ongoing drag operation, and will initiate a drag cancel animation.

⚠️ The following code is in c ⚠️

static void
on_drag_data_received (GtkWidget        *widget,
                       GdkDrop          *drop,
                       GtkSelectionData *data,
                       guint             time,
                       gpointer          user_data)
{
  GtkDrag *drag;
  GtkWidget *notebook;
  GtkWidget **child;

  drag = gtk_drop_get_drag (drop);
  notebook = g_object_get_data (drag, "gtk-notebook-drag-origin");
  child = (void*) gtk_selection_data_get_data (data);

  // process_widget (*child);

  gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), *child);
}

If you want a notebook to accept drags from other widgets, you will have to set your own DnD code to do it.

child

a child Widget

detachable

whether the tab is detachable or not

Changes the tab label for child.

If None is specified for tab_label, then the page will have the label “page N”.

child

the page

tab_label

the tab label widget to use, or None for default tab label

Creates a new label and sets it as the tab label for the page containing child.

child

the page

tab_text

the label text

Sets the edge at which the tabs are drawn.

pos

the edge to draw the tabs at

Sets whether the notebook tab can be reordered via drag and drop or not.

child

a child Widget

reorderable

whether the tab is reorderable or not

If true, pressing the right mouse button on the notebook shows a page switching menu.

If true, pressing the right mouse button on the notebook shows a page switching menu.

The index of the current page.

The ::create-window signal is emitted when a detachable tab is dropped on the root window.

A handler for this signal can create a window containing a notebook where the tab will be attached. It is also responsible for moving/resizing the window and adding the necessary properties to the notebook (e.g. the Notebook:group-name ).

page

the tab of notebook that is being detached

Returns

a Notebook that page should be added to, or None.

the ::page-added signal is emitted in the notebook right after a page is added to the notebook.

child

the child Widget affected

page_num

the new page number for child

the ::page-removed signal is emitted in the notebook right after a page is removed from the notebook.

child

the child Widget affected

page_num

the child page number

the ::page-reordered signal is emitted in the notebook right after a page has been reordered.

child

the child Widget affected

page_num

the new page number for child

Emitted when the user or a function changes the current page.

page

the new current page

page_num

the index of the page

Appends a page to self.

child

the Widget to use as the contents of the page

tab_label

the Widget to be used as the label for the page, or None to use the default label, “page N”

Returns

the index (starting from 0) of the appended page in the notebook, or -1 if function fails

Appends a page to self, specifying the widget to use as the label in the popup menu.

child

the Widget to use as the contents of the page

tab_label

the Widget to be used as the label for the page, or None to use the default label, “page N”

the widget to use as a label for the page-switch menu, if that is enabled. If None, and tab_label is a Label or None, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not a Label, menu_label must be specified if the page-switch menu is to be used.

Returns

the index (starting from 0) of the appended page in the notebook, or -1 if function fails

Returns the page number of the current page.

Returns

the index (starting from 0) of the current page in the notebook. If the notebook has no pages, then -1 will be returned.

Gets the number of pages in a notebook.

Returns

the number of pages in the notebook

Returns the child widget contained in page number page_num.

page_num

the index of a page in the notebook, or -1 to get the last page

Returns

the child widget, or None if page_num is out of bounds

Insert a page into self at the given position.

child

the Widget to use as the contents of the page

tab_label

the Widget to be used as the label for the page, or None to use the default label, “page N”

position

the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages

Returns

the index (starting from 0) of the inserted page in the notebook, or -1 if function fails

Insert a page into self at the given position, specifying the widget to use as the label in the popup menu.

child

the Widget to use as the contents of the page

tab_label

the Widget to be used as the label for the page, or None to use the default label, “page N”

the widget to use as a label for the page-switch menu, if that is enabled. If None, and tab_label is a Label or None, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not a Label, menu_label must be specified if the page-switch menu is to be used.

position

the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages.

Returns

the index (starting from 0) of the inserted page in the notebook

Finds the index of the page which contains the given child widget.

child

a Widget

Returns

the index of the page containing child, or -1 if child is not in the notebook

Prepends a page to self.

child

the Widget to use as the contents of the page

tab_label

the Widget to be used as the label for the page, or None to use the default label, “page N”

Returns

the index (starting from 0) of the prepended page in the notebook, or -1 if function fails

Prepends a page to self, specifying the widget to use as the label in the popup menu.

child

the Widget to use as the contents of the page

tab_label

the Widget to be used as the label for the page, or None to use the default label, “page N”

the widget to use as a label for the page-switch menu, if that is enabled. If None, and tab_label is a Label or None, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not a Label, menu_label must be specified if the page-switch menu is to be used.

Returns

the index (starting from 0) of the prepended page in the notebook, or -1 if function fails

Removes a page from the notebook given its index in the notebook.

page_num

the index of a notebook page, starting from 0. If -1, the last page will be removed.

Reorders the page containing child, so that it appears in position position.

If position is greater than or equal to the number of children in the list or negative, child will be moved to the end of the list.

child

the child to move

position

the new position, or -1 to move to the end

Switches to the page number page_num.

Note that due to historical reasons, GtkNotebook refuses to switch to a page unless the child widget is visible. Therefore, it is recommended to show child widgets before adding them to a notebook.

page_num

index of the page to switch to, starting from 0. If negative, the last page will be used. If greater than the number of pages in the notebook, nothing will be done.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Same as emit but takes Value for the arguments.

Emit signal by its name.

Same as emit_by_name but takes Value for the arguments.

Emit signal with details by signal id.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.