Struct gtk4::FlowBox [−][src]
pub struct FlowBox(_);
Expand description
A FlowBox
puts child widgets in reflowing grid.
For instance, with the horizontal orientation, the widgets will be arranged from left to right, starting a new row under the previous row when necessary. Reducing the width in this case will require more rows, so a larger height will be requested.
Likewise, with the vertical orientation, the widgets will be arranged from top to bottom, starting a new column to the right when necessary. Reducing the height will require more columns, so a larger width will be requested.
The size request of a FlowBox
alone may not be what you expect;
if you need to be able to shrink it along both axes and dynamically
reflow its children, you may have to wrap it in a ScrolledWindow
to enable that.
The children of a FlowBox
can be dynamically sorted and filtered.
Although a FlowBox
must have only FlowBoxChild
children, you
can add any kind of widget to it via insert()
, and a
FlowBoxChild
widget will automatically be inserted between the box
and the widget.
Also see ListBox
.
CSS nodes
flowbox
├── flowboxchild
│ ╰── <child>
├── flowboxchild
│ ╰── <child>
┊
╰── [rubberband]
FlowBox
uses a single CSS node with name flowbox. FlowBoxChild
uses a single CSS node with name flowboxchild. For rubberband selection,
a subnode with name rubberband is used.
Accessibility
FlowBox
uses the AccessibleRole::Grid
role, and FlowBoxChild
uses the AccessibleRole::GridCell
role.
Implements
WidgetExt
, glib::ObjectExt
, AccessibleExt
, BuildableExt
, ConstraintTargetExt
, OrientableExt
, WidgetExtManual
, AccessibleExtManual
Implementations
Creates a new builder-pattern struct instance to construct FlowBox
objects.
This method returns an instance of FlowBoxBuilder
which can be used to create FlowBox
objects.
Binds model
to self
.
If self
was already bound to a model, that previous binding is
destroyed.
The contents of self
are cleared and then filled with widgets that
represent items from model
. self
is updated whenever model
changes.
If model
is None
, self
is left empty.
It is undefined to add or remove widgets directly (for example, with
insert()
) while self
is bound to a model.
Note that using a model is incompatible with the filtering and sorting
functionality in FlowBox
. When using a model, filtering and sorting
should be implemented by the model.
model
the GListModel
to be bound to self
create_widget_func
a function that creates widgets for items
Gets the nth child in the self
.
idx
the position of the child
Returns
the child widget, which will
always be a FlowBoxChild
or None
in case no child widget
with the given index exists.
Gets the child in the (x
, y
) position.
Both x
and y
are assumed to be relative to the origin of self
.
x
the x coordinate of the child
y
the y coordinate of the child
Returns
the child widget, which will
always be a FlowBoxChild
or None
in case no child widget
exists for the given x and y coordinates.
Inserts the widget
into self
at position
.
If a sort function is set, the widget will actually be inserted at the calculated position.
If position
is -1, or larger than the total number of children
in the self
, then the widget
will be appended to the end.
widget
the Widget
to add
position
the position to insert child
in
Updates the filtering for all children.
Call this function when the result of the filter
function on the self
is changed due ot an external
factor. For instance, this would be used if the
filter function just looked for a specific search
term, and the entry with the string has changed.
Updates the sorting for all children.
Call this when the result of the sort function on
self
is changed due to an external factor.
Select all children of self
, if the selection
mode allows it.
Calls a function for each selected child.
Note that the selection cannot be modified from within this function.
func
the function to call for each selected child
By setting a filter function on the self
one can decide dynamically
which of the children to show.
For instance, to implement a search function that only shows the children matching the search terms.
The filter_func
will be called for each child after the call, and
it will continue to be called each time a child changes (via
FlowBoxChildExt::changed()
) or when
invalidate_filter()
is called.
Note that using a filter function is incompatible with using a model
(see bind_model()
).
filter_func
callback that lets you filter which children to show
Hooks up an adjustment to focus handling in self
.
The adjustment is also used for autoscrolling during
rubberband selection. See ScrolledWindow::hadjustment()
for a typical way of obtaining the adjustment, and
set_vadjustment()
for setting the vertical
adjustment.
The adjustments have to be in pixel units and in the same coordinate system as the allocation for immediate children of the box.
adjustment
an adjustment which should be adjusted
when the focus is moved among the descendents of container
Sets whether or not all children of self
are given
equal space in the box.
homogeneous
true
to create equal allotments,
false
for variable allotments
Sets the maximum number of children to request and
allocate space for in self
’s orientation.
Setting the maximum number of children per line
limits the overall natural size request to be no more
than n_children
children long in the given orientation.
n_children
the maximum number of children per line
Sets the minimum number of children to line up
in self
’s orientation before flowing.
n_children
the minimum number of children per line
pub fn set_sort_func<P: Fn(&FlowBoxChild, &FlowBoxChild) -> i32 + 'static>(
&self,
sort_func: P
)
pub fn set_sort_func<P: Fn(&FlowBoxChild, &FlowBoxChild) -> i32 + 'static>(
&self,
sort_func: P
)
By setting a sort function on the self
, one can dynamically
reorder the children of the box, based on the contents of
the children.
The sort_func
will be called for each child after the call,
and will continue to be called each time a child changes (via
FlowBoxChildExt::changed()
) and when
invalidate_sort()
is called.
Note that using a sort function is incompatible with using a model
(see bind_model()
).
sort_func
the sort function
Hooks up an adjustment to focus handling in self
.
The adjustment is also used for autoscrolling during
rubberband selection. See ScrolledWindow::vadjustment()
for a typical way of obtaining the adjustment, and
set_hadjustment()
for setting the horizontal
adjustment.
The adjustments have to be in pixel units and in the same coordinate system as the allocation for immediate children of the box.
adjustment
an adjustment which should be adjusted
when the focus is moved among the descendents of container
Unselect all children of self
, if the selection
mode allows it.
Emitted when the user activates the box_
.
This is a keybinding signal.
pub fn connect_child_activated<F: Fn(&Self, &FlowBoxChild) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_child_activated<F: Fn(&Self, &FlowBoxChild) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool, bool) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool, bool) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when the user initiates a cursor movement.
This is a keybinding signal.
Applications should not connect to it, but may emit it with
g_signal_emit_by_name()
if they need to control the cursor
programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifier does not. There are too many key combinations to list them all here.
<kbd>
←</kbd>
,<kbd>
→</kbd>
,<kbd>
↑</kbd>
,<kbd>
↓</kbd>
move by individual children<kbd>
Home</kbd>
,<kbd>
End</kbd>
move to the ends of the box<kbd>
PgUp</kbd>
,<kbd>
PgDn</kbd>
move vertically by pages
step
the granularity fo the move, as a MovementStep
count
the number of step
units to move
extend
whether to extend the selection
modify
whether to modify the selection
Returns
true
to stop other handlers from being invoked for the event.
false
to propagate the event further.
pub fn emit_move_cursor(
&self,
step: MovementStep,
count: i32,
extend: bool,
modify: bool
) -> bool
Emitted to select all children of the box, if the selection mode permits it.
This is a keybinding signal.
The default bindings for this signal is <kbd>
Ctrl</kbd>
-<kbd>
a</kbd>
.
pub fn connect_selected_children_changed<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_selected_children_changed<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when the set of selected children changes.
Use selected_foreach()
or
selected_children()
to obtain the
selected children.
Emitted to toggle the selection of the child that has the focus.
This is a keybinding signal.
The default binding for this signal is <kbd>
Ctrl</kbd>
-<kbd>
Space</kbd>
.
Emitted to unselect all children of the box, if the selection mode permits it.
This is a keybinding signal.
The default bindings for this signal is <kbd>
Ctrl</kbd>
-<kbd>
Shift</kbd>
-<kbd>
a</kbd>
.
pub fn connect_accept_unpaired_release_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_activate_on_single_click_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_max_children_per_line_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_min_children_per_line_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
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 FlowBox
impl UnwindSafe for FlowBox
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
.