Leaflet
Deprecated since version 1.4: See the migration guide
Superclasses: Widget
, InitiallyUnowned
, Object
Implemented Interfaces: Swipeable
, Accessible
, Buildable
, ConstraintTarget
, Orientable
An adaptive container acting like a box or a stack.
The AdwLeaflet
widget can display its children like a Box
does
or like a Stack
does, adapting to size changes by switching
between the two modes.
When there is enough space the children are displayed side by side, otherwise only one is displayed and the leaflet is said to be “folded”. The threshold is dictated by the preferred minimum sizes of the children. When a leaflet is folded, the children can be navigated using swipe gestures.
The “over” and “under” transition types stack the children one on top of the other, while the “slide” transition puts the children side by side. While navigating to a child on the side or below can be performed by swiping the current child away, navigating to an upper child requires dragging it from the edge where it resides. This doesn’t affect non-dragging swipes.
CSS nodes
AdwLeaflet
has a single CSS node with name leaflet
. The node will get the
style classes .folded
when it is folded, .unfolded
when it’s not, or none
if it hasn’t computed its fold yet.
Constructors
Methods
- class Leaflet
- append(child: Widget) LeafletPage
Adds a child to
self
.Deprecated since version 1.4:
- Parameters:
child – the widget to add
- get_adjacent_child(direction: NavigationDirection) Widget | None
Finds the previous or next navigatable child.
This will be the same child
navigate
or swipe gestures will navigate to.If there’s no child to navigate to,
NULL
will be returned instead.See
navigatable
.Deprecated since version 1.4:
- Parameters:
direction – the direction
Gets whether gestures and shortcuts for navigating backward are enabled.
Deprecated since version 1.4:
Gets whether gestures and shortcuts for navigating forward are enabled.
Deprecated since version 1.4:
- get_child_by_name(name: str) Widget | None
Finds the child of
self
withname
.Returns
NULL
if there is no child with this name.See
name
.Deprecated since version 1.4:
- Parameters:
name – the name of the child to find
- get_child_transition_params() SpringParams
Gets the child transition spring parameters for
self
.Deprecated since version 1.4:
- get_child_transition_running() bool
Gets whether a child transition is currently running for
self
.Deprecated since version 1.4:
- get_fold_threshold_policy() FoldThresholdPolicy
Gets the fold threshold policy for
self
.Deprecated since version 1.4:
- get_folded() bool
Gets whether
self
is folded.The leaflet will be folded if the size allocated to it is smaller than the sum of the minimum or natural sizes of the children (see
fold_threshold_policy
), it will be unfolded otherwise.Deprecated since version 1.4:
- get_mode_transition_duration() int
Gets the mode transition animation duration for
self
.Deprecated since version 1.4:
- get_page(child: Widget) LeafletPage
Returns the
LeafletPage
object forchild
.Deprecated since version 1.4:
- Parameters:
child – a child of
self
- get_pages() SelectionModel
Returns a
ListModel
that contains the pages of the leaflet.This can be used to keep an up-to-date view. The model also implements
SelectionModel
and can be used to track and change the visible page.Deprecated since version 1.4:
- get_transition_type() LeafletTransitionType
Gets the type of animation used for transitions between modes and children.
Deprecated since version 1.4:
- get_visible_child() Widget | None
Gets the widget currently visible when the leaflet is folded.
Deprecated since version 1.4:
- get_visible_child_name() str | None
Gets the name of the currently visible child widget.
Deprecated since version 1.4:
- insert_child_after(child: Widget, sibling: Widget | None = None) LeafletPage
Inserts
child
in the position aftersibling
in the list of children.If
sibling
isNULL
, insertschild
at the first position.Deprecated since version 1.4:
- Parameters:
child – the widget to insert
sibling – the sibling after which to insert
child
Navigates to the previous or next child.
The child must have the
navigatable
property set toTRUE
, otherwise it will be skipped.This will be the same child as returned by
get_adjacent_child
or navigated to via swipe gestures.Deprecated since version 1.4:
- Parameters:
direction – the direction
- prepend(child: Widget) LeafletPage
Inserts
child
at the first position inself
.Deprecated since version 1.4:
- Parameters:
child – the widget to prepend
- remove(child: Widget) None
Removes a child widget from
self
.Deprecated since version 1.4:
- Parameters:
child – the child to remove
- reorder_child_after(child: Widget, sibling: Widget | None = None) None
Moves
child
to the position aftersibling
in the list of children.If
sibling
isNULL
, moveschild
to the first position.Deprecated since version 1.4:
- Parameters:
child – the widget to move, must be a child of
self
sibling – the sibling to move
child
after
Sets whether gestures and shortcuts for navigating backward are enabled.
The supported gestures are:
One-finger swipe on touchscreens
Horizontal scrolling on touchpads (usually two-finger swipe)
Back/forward mouse buttons
The keyboard back/forward keys are also supported, as well as the Alt`+:kbd:`← shortcut for horizontal orientation, or Alt`+:kbd:`↑ for vertical orientation.
If the orientation is horizontal, for right-to-left locales, gestures and shortcuts are reversed.
Only children that have
navigatable
set toTRUE
can be navigated to.Deprecated since version 1.4:
- Parameters:
can_navigate_back – the new value
Sets whether gestures and shortcuts for navigating forward are enabled.
The supported gestures are:
One-finger swipe on touchscreens
Horizontal scrolling on touchpads (usually two-finger swipe)
Back/forward mouse buttons
The keyboard back/forward keys are also supported, as well as the Alt`+:kbd:`→ shortcut for horizontal orientation, or Alt`+:kbd:`↓ for vertical orientation.
If the orientation is horizontal, for right-to-left locales, gestures and shortcuts are reversed.
Only children that have
navigatable
set toTRUE
can be navigated to.Deprecated since version 1.4:
- Parameters:
can_navigate_forward – the new value
- set_can_unfold(can_unfold: bool) None
Sets whether
self
can unfold.Deprecated since version 1.4:
- Parameters:
can_unfold – whether
self
can unfold
- set_child_transition_params(params: SpringParams) None
Sets the child transition spring parameters for
self
.The default value is equivalent to:
adw_spring_params_new (1, 0.5, 500)
Deprecated since version 1.4:
- Parameters:
params – the new parameters
- set_fold_threshold_policy(policy: FoldThresholdPolicy) None
Sets the fold threshold policy for
self
.If set to
ADW_FOLD_THRESHOLD_POLICY_MINIMUM
, it will only fold when the children cannot fit anymore. WithADW_FOLD_THRESHOLD_POLICY_NATURAL
, it will fold as soon as children don’t get their natural size.This can be useful if you have a long ellipsizing label and want to let it ellipsize instead of immediately folding.
Deprecated since version 1.4:
- Parameters:
policy – the policy to use
- set_homogeneous(homogeneous: bool) None
Sets
self
to be homogeneous or not.If set to
FALSE
, different children can have different size along the opposite orientation.Deprecated since version 1.4:
- Parameters:
homogeneous – whether to make
self
homogeneous
- set_mode_transition_duration(duration: int) None
Sets the mode transition animation duration for
self
.Deprecated since version 1.4:
- Parameters:
duration – the new duration, in milliseconds
- set_transition_type(transition: LeafletTransitionType) None
Sets the type of animation used for transitions between modes and children.
The transition type can be changed without problems at runtime, so it is possible to change the animation based on the mode or child that is about to become current.
Deprecated since version 1.4:
- Parameters:
transition – the new transition type
- set_visible_child(visible_child: Widget) None
Sets the widget currently visible when the leaflet is folded.
The transition is determined by
transition_type
andchild_transition_params
. The transition can be cancelled by the user, in which case visible child will change back to the previously visible child.Deprecated since version 1.4:
- Parameters:
visible_child – the new child
- set_visible_child_name(name: str) None
Makes the child with the name
name
visible.See
visible_child
.Deprecated since version 1.4:
- Parameters:
name – the name of a child
Properties
- class Leaflet
Whether gestures and shortcuts for navigating backward are enabled.
The supported gestures are:
One-finger swipe on touchscreens
Horizontal scrolling on touchpads (usually two-finger swipe)
Back/forward mouse buttons
The keyboard back/forward keys are also supported, as well as the Alt`+:kbd:`← shortcut for horizontal orientation, or Alt`+:kbd:`↑ for vertical orientation.
If the orientation is horizontal, for right-to-left locales, gestures and shortcuts are reversed.
Only children that have
navigatable
set toTRUE
can be navigated to.Deprecated since version 1.4:
Whether gestures and shortcuts for navigating forward are enabled.
The supported gestures are:
One-finger swipe on touchscreens
Horizontal scrolling on touchpads (usually two-finger swipe)
Back/forward mouse buttons
The keyboard back/forward keys are also supported, as well as the Alt`+:kbd:`→ shortcut for horizontal orientation, or Alt`+:kbd:`↓ for vertical orientation.
If the orientation is horizontal, for right-to-left locales, gestures and shortcuts are reversed.
Only children that have
navigatable
set toTRUE
can be navigated to.Deprecated since version 1.4:
- props.child_transition_params: SpringParams
The child transition spring parameters.
The default value is equivalent to:
adw_spring_params_new (1, 0.5, 500)
Deprecated since version 1.4:
- props.child_transition_running: bool
Whether a child transition is currently running.
Deprecated since version 1.4:
- props.fold_threshold_policy: FoldThresholdPolicy
Determines when the leaflet will fold.
If set to
ADW_FOLD_THRESHOLD_POLICY_MINIMUM
, it will only fold when the children cannot fit anymore. WithADW_FOLD_THRESHOLD_POLICY_NATURAL
, it will fold as soon as children don’t get their natural size.This can be useful if you have a long ellipsizing label and want to let it ellipsize instead of immediately folding.
Deprecated since version 1.4:
- props.folded: bool
Whether the leaflet is folded.
The leaflet will be folded if the size allocated to it is smaller than the sum of the minimum or natural sizes of the children (see
fold_threshold_policy
), it will be unfolded otherwise.Deprecated since version 1.4:
- props.homogeneous: bool
Whether the leaflet allocates the same size for all children when folded.
If set to
FALSE
, different children can have different size along the opposite orientation.Deprecated since version 1.4:
- props.mode_transition_duration: int
The mode transition animation duration, in milliseconds.
Deprecated since version 1.4:
- props.pages: SelectionModel
A selection model with the leaflet’s pages.
This can be used to keep an up-to-date view. The model also implements
SelectionModel
and can be used to track and change the visible page.Deprecated since version 1.4:
- props.transition_type: LeafletTransitionType
The type of animation used for transitions between modes and children.
The transition type can be changed without problems at runtime, so it is possible to change the animation based on the mode or child that is about to become current.
Deprecated since version 1.4:
- props.visible_child: Widget
The widget currently visible when the leaflet is folded.
The transition is determined by
transition_type
andchild_transition_params
. The transition can be cancelled by the user, in which case visible child will change back to the previously visible child.Deprecated since version 1.4:
- props.visible_child_name: str
The name of the widget currently visible when the leaflet is folded.
See
visible_child
.Deprecated since version 1.4: