Adw.WrapLayout

g Adw.WrapLayout Adw.WrapLayout GObject.GInterface GObject.GInterface Gtk.Orientable Gtk.Orientable GObject.GInterface->Gtk.Orientable GObject.Object GObject.Object Gtk.LayoutManager Gtk.LayoutManager GObject.Object->Gtk.LayoutManager Gtk.LayoutManager->Adw.WrapLayout Gtk.Orientable->Adw.WrapLayout

Subclasses:

None

Methods

Inherited:

Gtk.LayoutManager (6), GObject.Object (37), Gtk.Orientable (2)

Structs:

GObject.ObjectClass (5)

class

new ()

get_align ()

get_child_spacing ()

get_child_spacing_unit ()

get_justify ()

get_justify_last_line ()

get_line_homogeneous ()

get_line_spacing ()

get_line_spacing_unit ()

get_natural_line_length ()

get_natural_line_length_unit ()

get_pack_direction ()

get_wrap_policy ()

get_wrap_reverse ()

set_align (align)

set_child_spacing (child_spacing)

set_child_spacing_unit (unit)

set_justify (justify)

set_justify_last_line (justify_last_line)

set_line_homogeneous (homogeneous)

set_line_spacing (line_spacing)

set_line_spacing_unit (unit)

set_natural_line_length (natural_line_length)

set_natural_line_length_unit (unit)

set_pack_direction (pack_direction)

set_wrap_policy (wrap_policy)

set_wrap_reverse (wrap_reverse)

Virtual Methods

Inherited:

Gtk.LayoutManager (6), GObject.Object (7)

Properties

Inherited:

Gtk.Orientable (1)

Name

Type

Flags

Short Description

align

float

r/w/en

child-spacing

int

r/w/en

child-spacing-unit

Adw.LengthUnit

r/w/en

justify

Adw.JustifyMode

r/w/en

justify-last-line

bool

r/w/en

line-homogeneous

bool

r/w/en

line-spacing

int

r/w/en

line-spacing-unit

Adw.LengthUnit

r/w/en

natural-line-length

int

r/w/en

natural-line-length-unit

Adw.LengthUnit

r/w/en

pack-direction

Adw.PackDirection

r/w/en

wrap-policy

Adw.WrapPolicy

r/w/en

wrap-reverse

bool

r/w/en

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Adw.WrapLayout(**kwargs)
Bases:

Gtk.LayoutManager, Gtk.Orientable

Abstract:

No

Structure:

Adw.WrapLayoutClass

A box-like layout that can wrap into multiple lines.

<picture> <source srcset=”wrap-box-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”wrap-box.png” alt=”wrap-box”> </picture>

AdwWrapLayout is similar to [class`Gtk`.BoxLayout], but can wrap lines when the widgets cannot fit otherwise. Unlike [class`Gtk`.FlowBox], the children aren’t arranged into a grid and behave more like words in a wrapping label.

Like GtkBoxLayout, AdwWrapLayout is orientable and has spacing:

  • [property`WrapLayout`:py:data::child-spacing<Adw.WrapLayout.props.child_spacing>] between children in the same line;

  • [property`WrapLayout`:py:data::line-spacing<Adw.WrapLayout.props.line_spacing>] between lines.

::: note Unlike GtkBoxLayout, AdwWrapLayout cannot follow the CSS border-spacing property.

Use the [property`WrapLayout`:py:data::natural-line-length<Adw.WrapLayout.props.natural_line_length>] property to determine the layout’s natural size, e.g. when using it in a [class`Gtk`.Popover].

Normally, a horizontal AdwWrapLayout wraps left to right and top to bottom for left-to-right languages. Both of these directions can be reversed, using the [property`WrapLayout`:py:data::pack-direction<Adw.WrapLayout.props.pack_direction>] and [property`WrapLayout`:py:data::wrap-reverse<Adw.WrapLayout.props.wrap_reverse>] properties. Additionally, the alignment of each line can be controlled with the [property`WrapLayout`:py:data::align<Adw.WrapLayout.props.align>] property.

Lines can be justified using the [property`WrapLayout`:py:data::justify<Adw.WrapLayout.props.justify>] property, filling the entire line by either increasing child size or spacing depending on the value. Set [property`WrapLayout`:py:data::justify-last-line<Adw.WrapLayout.props.justify_last_line>] to justify the last line as well.

By default, AdwWrapLayout wraps as soon as the previous line cannot fit any more children without shrinking them past their natural size. Set [property`WrapLayout`:py:data::wrap-policy<Adw.WrapLayout.props.wrap_policy>] to [enum`Adw`.WrapPolicy.MINIMUM] to only wrap once all the children in the previous line have been shrunk to their minimum size.

To make each line take the same amount of space, set [property`WrapLayout`:py:data::line-homogeneous<Adw.WrapLayout.props.line_homogeneous>] to TRUE.

Spacing and natural line length can scale with the text scale factor, use the [property`WrapLayout`:py:data::child-spacing-unit<Adw.WrapLayout.props.child_spacing_unit>], [property`WrapLayout`:py:data::line-spacing-unit<Adw.WrapLayout.props.line_spacing_unit>] and/or [property`WrapLayout`:py:data::natural-line-length-unit<Adw.WrapLayout.props.natural_line_length_unit>] properties to enable that behavior.

See [class`WrapBox`].

New in version 1.7.

classmethod new()
Returns:

the newly created AdwWrapLayout

Return type:

Gtk.LayoutManager

Creates a new AdwWrapLayout.

New in version 1.7.

get_align()
Returns:

the child alignment

Return type:

float

Gets the alignment of the children within each line.

New in version 1.7.

get_child_spacing()
Returns:

spacing between widgets on the same line

Return type:

int

Gets spacing between widgets on the same line.

New in version 1.7.

get_child_spacing_unit()
Returns:

the length unit

Return type:

Adw.LengthUnit

Gets the length unit for child spacing.

New in version 1.7.

get_justify()
Returns:

the justify mode

Return type:

Adw.JustifyMode

Gets whether and how each complete line is stretched to fill the entire widget.

New in version 1.7.

get_justify_last_line()
Returns:

whether the last line is justified

Return type:

bool

Gets whether the last line should be stretched to fill the entire widget.

New in version 1.7.

get_line_homogeneous()
Returns:

whether lines should be homogeneous

Return type:

bool

Gets whether all lines should take the same amount of space.

New in version 1.7.

get_line_spacing()
Returns:

the line spacing

Return type:

int

Gets the spacing between lines.

New in version 1.7.

get_line_spacing_unit()
Returns:

the length unit

Return type:

Adw.LengthUnit

Gets the length unit for line spacing.

New in version 1.7.

get_natural_line_length()
Returns:

the natural length

Return type:

int

Gets the natural size for each line.

New in version 1.7.

get_natural_line_length_unit()
Returns:

the length unit

Return type:

Adw.LengthUnit

Gets the length unit for line spacing.

New in version 1.7.

get_pack_direction()
Returns:

the line direction

Return type:

Adw.PackDirection

Gets the direction children are packed in each line.

New in version 1.7.

get_wrap_policy()
Returns:

the wrap policy

Return type:

Adw.WrapPolicy

Gets the policy for line wrapping.

New in version 1.7.

get_wrap_reverse()
Returns:

whether wrap direction is reversed

Return type:

bool

Gets whether wrap direction is reversed.

New in version 1.7.

set_align(align)
Parameters:

align (float) – the child alignment

Sets the alignment of the children within each line.

0 means the children are placed at the start of the line, 1 means they are placed at the end of the line. 0.5 means they are placed in the middle of the line.

Alignment is only used when [property`WrapLayout`:py:data::justify<Adw.WrapLayout.props.justify>] is set to ADW_JUSTIFY_NONE, or on the last line when the [property`WrapLayout`:py:data::justify-last-line<Adw.WrapLayout.props.justify_last_line>] is FALSE.

New in version 1.7.

set_child_spacing(child_spacing)
Parameters:

child_spacing (int) – the child spacing

Sets the spacing between widgets on the same line.

See [property`WrapLayout`:py:data::child-spacing-unit<Adw.WrapLayout.props.child_spacing_unit>].

New in version 1.7.

set_child_spacing_unit(unit)
Parameters:

unit (Adw.LengthUnit) – the length unit

Sets the length unit for child spacing.

Allows the spacing to vary depending on the text scale factor.

See [property`WrapLayout`:py:data::child-spacing<Adw.WrapLayout.props.child_spacing>].

New in version 1.7.

set_justify(justify)
Parameters:

justify (Adw.JustifyMode) – the justify mode

Sets whether and how each complete line should be stretched to fill the entire widget.

If set to ADW_JUSTIFY_FILL, each widget in the line will be stretched, keeping consistent spacing, so that the line fills the entire widget.

If set to ADW_JUSTIFY_SPREAD, the spacing between widgets will be increased, keeping widget sizes intact. The first and last widget will be aligned with the beginning and end of the line. If the line only contains a single widget, it will be stretched regardless.

If set to ADW_JUSTIFY_NONE, the line will not be stretched and the children will be placed together within the line, according to [property`WrapLayout`:py:data::align<Adw.WrapLayout.props.align>].

By default this doesn’t affect the last line, as it will be incomplete. Use [property`WrapLayout`:py:data::justify-last-line<Adw.WrapLayout.props.justify_last_line>] to justify it as well.

New in version 1.7.

set_justify_last_line(justify_last_line)
Parameters:

justify_last_line (bool) – whether to justify the last line

Sets whether the last line should be stretched to fill the entire widget.

See [property`WrapLayout`:py:data::justify<Adw.WrapLayout.props.justify>].

New in version 1.7.

set_line_homogeneous(homogeneous)
Parameters:

homogeneous (bool) – whether lines should be homogeneous

Sets whether all lines should take the same amount of space.

New in version 1.7.

set_line_spacing(line_spacing)
Parameters:

line_spacing (int) – the line spacing

Sets the spacing between lines.

See [property`WrapLayout`:py:data::line-spacing-unit<Adw.WrapLayout.props.line_spacing_unit>].

New in version 1.7.

set_line_spacing_unit(unit)
Parameters:

unit (Adw.LengthUnit) – the length unit

Sets the length unit for line spacing.

Allows the spacing to vary depending on the text scale factor.

See [property`WrapLayout`:py:data::line-spacing<Adw.WrapLayout.props.line_spacing>].

New in version 1.7.

set_natural_line_length(natural_line_length)
Parameters:

natural_line_length (int) – the natural length

Sets the natural size for each line.

It should be used to limit the line lengths, for example when used in popovers.

See [property`WrapLayout`:py:data::natural-line-length-unit<Adw.WrapLayout.props.natural_line_length_unit>].

New in version 1.7.

set_natural_line_length_unit(unit)
Parameters:

unit (Adw.LengthUnit) – the length unit

Sets the length unit for natural line length.

Allows the length to vary depending on the text scale factor.

See [property`WrapLayout`:py:data::natural-line-length<Adw.WrapLayout.props.natural_line_length>].

New in version 1.7.

set_pack_direction(pack_direction)
Parameters:

pack_direction (Adw.PackDirection) – the new line direction

Sets the direction children are packed in each line.

New in version 1.7.

set_wrap_policy(wrap_policy)
Parameters:

wrap_policy (Adw.WrapPolicy) – the new wrap policy

Sets the policy for line wrapping.

If set to ADW_WRAP_NATURAL, the box will wrap to the next line as soon as the previous line cannot fit any more children without shrinking them past their natural size.

If set to ADW_WRAP_MINIMUM, the box will try to fit as many children into each line as possible, shrinking them down to their minimum size before wrapping to the next line.

New in version 1.7.

set_wrap_reverse(wrap_reverse)
Parameters:

wrap_reverse (bool) – whether to reverse wrap direction

Sets whether wrap direction should be reversed.

By default, lines wrap downwards in a horizontal box, and towards the end in a vertical box. If set to TRUE, they wrap upwards or towards the start respectively.

New in version 1.7.

Property Details

Adw.WrapLayout.props.align
Name:

align

Type:

float

Default Value:

0.0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The alignment of the children within each line.

0 means the children are placed at the start of the line, 1 means they are placed at the end of the line. 0.5 means they are placed in the middle of the line.

Alignment is only used when [property`WrapLayout`:py:data::justify<Adw.WrapLayout.props.justify>] is set to ADW_JUSTIFY_NONE, or on the last line when the [property`WrapLayout`:py:data::justify-last-line<Adw.WrapLayout.props.justify_last_line>] is FALSE.

New in version 1.7.

Adw.WrapLayout.props.child_spacing
Name:

child-spacing

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The spacing between widgets on the same line.

See [property`WrapLayout`:py:data::child-spacing-unit<Adw.WrapLayout.props.child_spacing_unit>].

New in version 1.7.

Adw.WrapLayout.props.child_spacing_unit
Name:

child-spacing-unit

Type:

Adw.LengthUnit

Default Value:

Adw.LengthUnit.PX

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The length unit for child spacing.

Allows the spacing to vary depending on the text scale factor.

See [property`WrapLayout`:py:data::child-spacing<Adw.WrapLayout.props.child_spacing>].

New in version 1.7.

Adw.WrapLayout.props.justify
Name:

justify

Type:

Adw.JustifyMode

Default Value:

Adw.JustifyMode.NONE

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines whether and how each complete line should be stretched to fill the entire widget.

If set to ADW_JUSTIFY_FILL, each widget in the line will be stretched, keeping consistent spacing, so that the line fills the entire widget.

If set to ADW_JUSTIFY_SPREAD, the spacing between widgets will be increased, keeping widget sizes intact. The first and last widget will be aligned with the beginning and end of the line. If the line only contains a single widget, it will be stretched regardless.

If set to ADW_JUSTIFY_NONE, the line will not be stretched and the children will be placed together within the line, according to [property`WrapLayout`:py:data::align<Adw.WrapLayout.props.align>].

By default this doesn’t affect the last line, as it will be incomplete. Use [property`WrapLayout`:py:data::justify-last-line<Adw.WrapLayout.props.justify_last_line>] to justify it as well.

New in version 1.7.

Adw.WrapLayout.props.justify_last_line
Name:

justify-last-line

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the last line should be stretched to fill the entire widget.

See [property`WrapLayout`:py:data::justify<Adw.WrapLayout.props.justify>].

New in version 1.7.

Adw.WrapLayout.props.line_homogeneous
Name:

line-homogeneous

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether all lines should take the same amount of space.

New in version 1.7.

Adw.WrapLayout.props.line_spacing
Name:

line-spacing

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The spacing between lines.

See [property`WrapLayout`:py:data::line-spacing-unit<Adw.WrapLayout.props.line_spacing_unit>].

New in version 1.7.

Adw.WrapLayout.props.line_spacing_unit
Name:

line-spacing-unit

Type:

Adw.LengthUnit

Default Value:

Adw.LengthUnit.PX

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The length unit for line spacing.

Allows the spacing to vary depending on the text scale factor.

See [property`WrapLayout`:py:data::line-spacing<Adw.WrapLayout.props.line_spacing>].

New in version 1.7.

Adw.WrapLayout.props.natural_line_length
Name:

natural-line-length

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines the natural size for each line.

It should be used to limit the line lengths, for example when used in popovers.

See [property`WrapLayout`:py:data::natural-line-length-unit<Adw.WrapLayout.props.natural_line_length_unit>].

New in version 1.7.

Adw.WrapLayout.props.natural_line_length_unit
Name:

natural-line-length-unit

Type:

Adw.LengthUnit

Default Value:

Adw.LengthUnit.PX

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The length unit for natural line length.

Allows the length to vary depending on the text scale factor.

See [property`WrapLayout`:py:data::natural-line-length<Adw.WrapLayout.props.natural_line_length>].

New in version 1.7.

Adw.WrapLayout.props.pack_direction
Name:

pack-direction

Type:

Adw.PackDirection

Default Value:

Adw.PackDirection.START_TO_END

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The direction children are packed in each line.

New in version 1.7.

Adw.WrapLayout.props.wrap_policy
Name:

wrap-policy

Type:

Adw.WrapPolicy

Default Value:

Adw.WrapPolicy.NATURAL

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The policy for line wrapping.

If set to ADW_WRAP_NATURAL, the box will wrap to the next line as soon as the previous line cannot fit any more children without shrinking them past their natural size.

If set to ADW_WRAP_MINIMUM, the box will try to fit as many children into each line as possible, shrinking them down to their minimum size before wrapping to the next line.

New in version 1.7.

Adw.WrapLayout.props.wrap_reverse
Name:

wrap-reverse

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether wrap direction should be reversed.

By default, lines wrap downwards in a horizontal box, and towards the end in a vertical box. If set to TRUE, they wrap upwards or towards the start respectively.

New in version 1.7.