`GtkNotebook` is a container whose children are pages switched between using tabs.
![An example GtkNotebook](notebook.png)
There are many configuration options for `GtkNotebook`. Among other things, you can choose on which edge the tabs appear (see [
method@Gtk.Notebook.set_tab_pos]), whether, if there are too many tabs to fit the notebook should be made bigger or scrolling arrows added (see
[method@Gtk.Notebook.set_scrollable]), and whether there will be a popup menu allowing the users to switch pages. (see [
method@Gtk.Notebook.popup_enable]).
GtkNotebook as GtkBuildable
The `GtkNotebook` implementation of the `GtkBuildable` 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 `GtkNotebook`:
```xml <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> ```
`GtkNotebook` 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 [method@Gtk.Notebook.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
`GtkNotebook` uses the following roles:
- gtk_accessible_role_group for the notebook widget
- gtk_accessible_role_tab_list for the list of tabs
- gtk_accessible_role_tab role for each tab
- gtk_accessible_role_tab_panel for each page
- public int append_page (Widget child, Widget? tab_label = null)
Appends a page to this.
- public int append_page_menu (Widget child, Widget? tab_label, Widget? menu_label)
Appends a page to this, specifying the
widget to use as the label in the popup menu.
- public void detach_tab (Widget child)
Removes the child from the notebook.
- public unowned Widget? get_action_widget (PackType pack_type)
Gets one of the action widgets.
- public int get_current_page ()
Returns the page number of the current page.
- public unowned string? get_group_name ()
Gets the current group name for this.
- public unowned Widget? get_menu_label (Widget child)
Retrieves the menu label widget of the page containing child
.
- public unowned string? get_menu_label_text (Widget child)
Retrieves the text of the menu label for the page containing child
.
- public int get_n_pages ()
Gets the number of pages in a notebook.
- public unowned Widget? get_nth_page (int page_num)
Returns the child widget contained in page number page_num
.
- public unowned NotebookPage get_page (Widget child)
Returns the `GtkNotebookPage` for child
.
- public ListModel get_pages ()
Returns a `GListModel` that contains the pages of the notebook.
- public bool get_scrollable ()
Returns whether the tab label area has arrows for scrolling.
- public bool get_show_border ()
Returns whether a bevel will be drawn around the notebook pages.
- public bool get_show_tabs ()
Returns whether the tabs of the notebook are shown.
- public bool get_tab_detachable (Widget child)
Returns whether the tab contents can be detached from
this.
- public unowned Widget? get_tab_label (Widget child)
Returns the tab label widget for the page child
.
- public unowned string? get_tab_label_text (Widget child)
Retrieves the text of the tab label for the page containing child
.
- public PositionType get_tab_pos ()
Gets the edge at which the tabs are drawn.
- public bool get_tab_reorderable (Widget child)
Gets whether the tab can be reordered via drag and drop or not.
- public int insert_page (Widget child, Widget? tab_label, int position)
Insert a page into this at the given
position.
- public int insert_page_menu (Widget child, Widget? tab_label, Widget? menu_label, int position)
Insert a page into this at the given
position, specifying the widget to use as the label in the popup menu.
- public void next_page ()
Switches to the next page.
- public int page_num (Widget child)
Finds the index of the page which contains the given child widget.
- public void popup_disable ()
Disables the popup menu.
- public void popup_enable ()
Enables the popup menu.
- public int prepend_page (Widget child, Widget? tab_label = null)
Prepends a page to this.
- public int prepend_page_menu (Widget child, Widget? tab_label, Widget? menu_label)
Prepends a page to this, specifying the
widget to use as the label in the popup menu.
- public void prev_page ()
Switches to the previous page.
- public void remove_page (int page_num)
Removes a page from the notebook given its index in the notebook.
- public void reorder_child (Widget child, int position)
Reorders the page containing child
, so that it appears in
position position
.
- public void set_action_widget (Widget widget, PackType pack_type)
Sets widget
as one of the action widgets.
- public void set_current_page (int page_num)
Switches to the page number page_num
.
- public void set_group_name (string? group_name)
Sets a group name for this.
- public void set_menu_label (Widget child, Widget? menu_label)
Changes the menu label for the page containing child
.
- public void set_menu_label_text (Widget child, string menu_text)
Creates a new label and sets it as the menu label of child
.
- public void set_scrollable (bool scrollable)
Sets whether the tab label area will have arrows for scrolling if there are
too many tabs to fit in the area.
- public void set_show_border (bool show_border)
Sets whether a bevel will be drawn around the notebook pages.
- public void set_show_tabs (bool show_tabs)
Sets whether to show the tabs for the notebook or not.
- public void set_tab_detachable (Widget child, bool detachable)
Sets whether the tab can be detached from this
to another notebook or widget.
- public void set_tab_label (Widget child, Widget? tab_label)
Changes the tab label for child
.
- public void set_tab_label_text (Widget child, string tab_text)
Creates a new label and sets it as the tab label for the page containing
child
.
- public void set_tab_pos (PositionType pos)
Sets the edge at which the tabs are drawn.
- public void set_tab_reorderable (Widget child, bool reorderable)
Sets whether the notebook tab can be reordered via drag and drop or not.