Struct gtk4::Notebook [−][src]
pub struct Notebook(_);
Expand description
Notebook
is a container whose children are pages switched
between using tabs.
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:
AccessibleRole::Group
for the notebook widgetAccessibleRole::TabList
for the list of tabsAccessibleRole::Tab
role for each tabAccessibleRole::TabPanel
for each page
Implements
WidgetExt
, glib::ObjectExt
, AccessibleExt
, BuildableExt
, ConstraintTargetExt
, WidgetExtManual
, AccessibleExtManual
Implementations
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
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 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
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 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
menu_label
the menu label, or None
for default
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 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
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.
pub fn connect_change_current_page<F: Fn(&Self, i32) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_create_window<F: Fn(&Self, &Widget) -> Option<Notebook> + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_create_window<F: Fn(&Self, &Widget) -> Option<Notebook> + 'static>(
&self,
f: F
) -> SignalHandlerId
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
pub fn connect_focus_tab<F: Fn(&Self, NotebookTab) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_move_focus_out<F: Fn(&Self, DirectionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_page_added<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_page_added<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_page_removed<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_page_removed<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_page_reordered<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_page_reordered<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_reorder_tab<F: Fn(&Self, DirectionType, bool) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_select_page<F: Fn(&Self, bool) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_switch_page<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_switch_page<F: Fn(&Self, &Widget, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
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”
menu_label
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.
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”
menu_label
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
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”
menu_label
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.
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
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
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for Notebook
impl UnwindSafe for Notebook
Blanket Implementations
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
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: Fn(&[Value]) -> Option<Value>,
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.
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Returns a SendValue
clone of self
.