Struct gtk4::ScrolledWindow [−][src]
pub struct ScrolledWindow(_);
Expand description
ScrolledWindow
is a container that makes its child scrollable.
It does so using either internally added scrollbars or externally associated adjustments, and optionally draws a frame around the child.
Widgets with native scrolling support, i.e. those whose classes implement
the Scrollable
interface, are added directly. For other types
of widget, the class Viewport
acts as an adaptor, giving
scrollability to other widgets. set_child()
intelligently accounts for whether or not the added child is a Scrollable
.
If it isn’t, then it wraps the child in a Viewport
. Therefore, you can
just add any child widget and not worry about the details.
If set_child()
has added a Viewport
for you,
you can remove both your added child widget from the Viewport
, and the
Viewport
from the ScrolledWindow
, like this:
⚠️ The following code is in c ⚠️
GtkWidget *scrolled_window = gtk_scrolled_window_new ();
GtkWidget *child_widget = gtk_button_new ();
// GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically
// add a GtkViewport.
gtk_box_append (GTK_BOX (scrolled_window), child_widget);
// Either of these will result in child_widget being unparented:
gtk_box_remove (GTK_BOX (scrolled_window), child_widget);
// or
gtk_box_remove (GTK_BOX (scrolled_window),
gtk_bin_get_child (GTK_BIN (scrolled_window)));
Unless property::ScrolledWindow::hscrollbar-policy
and
property::ScrolledWindow::vscrollbar-policy
are PolicyType::Never
or
PolicyType::External
, ScrolledWindow
adds internal Scrollbar
widgets
around its child. The scroll position of the child, and if applicable the
scrollbars, is controlled by the property::ScrolledWindow::hadjustment
and property::ScrolledWindow::vadjustment
that are associated with the
ScrolledWindow
. See the docs on Scrollbar
for the details,
but note that the “step_increment” and “page_increment” fields are only
effective if the policy causes scrollbars to be present.
If a ScrolledWindow
doesn’t behave quite as you would like, or
doesn’t have exactly the right layout, it’s very possible to set up
your own scrolling with Scrollbar
and for example a Grid
.
Touch support
ScrolledWindow
has built-in support for touch devices. When a
touchscreen is used, swiping will move the scrolled window, and will
expose ‘kinetic’ behavior. This can be turned off with the
property::ScrolledWindow::kinetic-scrolling
property if it is undesired.
ScrolledWindow
also displays visual ‘overshoot’ indication when
the content is pulled beyond the end, and this situation can be
captured with the signal::ScrolledWindow::edge-overshot
signal.
If no mouse device is present, the scrollbars will overlaid as
narrow, auto-hiding indicators over the content. If traditional
scrollbars are desired although no mouse is present, this behaviour
can be turned off with the property::ScrolledWindow::overlay-scrolling
property.
CSS nodes
ScrolledWindow
has a main CSS node with name scrolledwindow.
It gets a .frame style class added when property::ScrolledWindow::has-frame
is true
.
It uses subnodes with names overshoot and undershoot to draw the overflow and underflow indications. These nodes get the .left, .right, .top or .bottom style class added depending on where the indication is drawn.
ScrolledWindow
also sets the positional style classes (.left, .right,
.top, .bottom) and style classes related to overlay scrolling
(.overlay-indicator, .dragging, .hovering) on its scrollbars.
If both scrollbars are visible, the area where they meet is drawn with a subnode named junction.
Accessibility
ScrolledWindow
uses the AccessibleRole::Group
role.
Implements
WidgetExt
, glib::ObjectExt
, AccessibleExt
, BuildableExt
, ConstraintTargetExt
, WidgetExtManual
, AccessibleExtManual
Implementations
Creates a new builder-pattern struct instance to construct ScrolledWindow
objects.
This method returns an instance of ScrolledWindowBuilder
which can be used to create ScrolledWindow
objects.
Returns the horizontal scrollbar’s adjustment.
This is the adjustment used to connect the horizontal scrollbar to the child widget’s horizontal scroll functionality.
Returns
the horizontal Adjustment
Gets the placement of the contents with respect to the scrollbars.
Returns
the current placement value.
Retrieves the current policy values for the horizontal and vertical scrollbars.
See set_policy()
.
Returns
hscrollbar_policy
location to store the policy for the horizontal scrollbar
vscrollbar_policy
location to store the policy for the vertical scrollbar
Reports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height.
Returns
whether natural height propagation is enabled.
Reports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width.
Returns
whether natural width propagation is enabled.
Returns the vertical scrollbar’s adjustment.
This is the adjustment used to connect the vertical scrollbar to the child widget’s vertical scroll functionality.
Returns
the vertical Adjustment
Sets the Adjustment
for the horizontal scrollbar.
hadjustment
the Adjustment
to use, or None
to create a new one
Changes the frame drawn around the contents of self
.
has_frame
whether to draw a frame around scrolled window contents
Turns kinetic scrolling on or off.
Kinetic scrolling only applies to devices with source
GDK_SOURCE_TOUCHSCREEN
.
kinetic_scrolling
true
to enable kinetic scrolling
Sets the maximum height that self
should keep visible.
The self
will grow up to this height before it starts
scrolling the content.
It is a programming error to set the maximum content height to a value
smaller than property::ScrolledWindow::min-content-height
.
height
the maximum content height
Sets the maximum width that self
should keep visible.
The self
will grow up to this width before it starts
scrolling the content.
It is a programming error to set the maximum content width to a
value smaller than property::ScrolledWindow::min-content-width
.
width
the maximum content width
Sets the minimum height that self
should keep visible.
Note that this can and (usually will) be smaller than the minimum size of the content.
It is a programming error to set the minimum content height to a
value greater than property::ScrolledWindow::max-content-height
.
height
the minimal content height
Sets the minimum width that self
should keep visible.
Note that this can and (usually will) be smaller than the minimum size of the content.
It is a programming error to set the minimum content width to a
value greater than property::ScrolledWindow::max-content-width
.
width
the minimal content width
Enables or disables overlay scrolling for this scrolled window.
overlay_scrolling
whether to enable overlay scrolling
Sets the placement of the contents with respect to the scrollbars for the scrolled window.
The default is CornerType::TopLeft
, meaning the child is
in the top left, with the scrollbars underneath and to the right.
Other values in CornerType
are CornerType::TopRight
,
CornerType::BottomLeft
, and CornerType::BottomRight
.
See also placement()
and
unset_placement()
.
window_placement
position of the child window
Sets the scrollbar policy for the horizontal and vertical scrollbars.
The policy determines when the scrollbar should appear; it is a value
from the PolicyType
enumeration. If PolicyType::Always
, the
scrollbar is always present; if PolicyType::Never
, the scrollbar is
never present; if PolicyType::Automatic
, the scrollbar is present only
if needed (that is, if the slider part of the bar would be smaller
than the trough — the display is larger than the page size).
hscrollbar_policy
policy for horizontal bar
vscrollbar_policy
policy for vertical bar
Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.
propagate
whether to propagate natural height
Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.
propagate
whether to propagate natural width
Sets the Adjustment
for the vertical scrollbar.
vadjustment
the Adjustment
to use, or None
to create a new one
Unsets the placement of the contents with respect to the scrollbars.
If no window placement is set for a scrolled window,
it defaults to CornerType::TopLeft
.
When the horizontal scrollbar is displayed.
Use set_policy()
to set
this property.
When the horizontal scrollbar is displayed.
Use set_policy()
to set
this property.
When the vertical scrollbar is displayed.
Use set_policy()
to set
this property.
When the vertical scrollbar is displayed.
Use set_policy()
to set
this property.
Where the contents are located with respect to the scrollbars.
Where the contents are located with respect to the scrollbars.
pub fn connect_edge_overshot<F: Fn(&Self, PositionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_edge_overshot<F: Fn(&Self, PositionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted whenever user initiated scrolling makes the scrolled window firmly surpass the limits defined by the adjustment in that orientation.
A similar behavior without edge resistance is provided by the
signal::ScrolledWindow::edge-reached
signal.
Note: The pos
argument is LTR/RTL aware, so callers should be
aware too if intending to provide behavior on horizontal edges.
pos
edge side that was hit
pub fn connect_edge_reached<F: Fn(&Self, PositionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_edge_reached<F: Fn(&Self, PositionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted whenever user-initiated scrolling makes the scrolled window exactly reach the lower or upper limits defined by the adjustment in that orientation.
A similar behavior with edge resistance is provided by the
signal::ScrolledWindow::edge-overshot
signal.
Note: The pos
argument is LTR/RTL aware, so callers should be
aware too if intending to provide behavior on horizontal edges.
pos
edge side that was reached
pub fn connect_move_focus_out<F: Fn(&Self, DirectionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_move_focus_out<F: Fn(&Self, DirectionType) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when focus is moved away from the scrolled window by a keybinding.
This is a keybinding signal.
The default bindings for this signal are
Ctrl + Tab
to move forward and Ctrl + Shift + Tab
to
move backward.
direction_type
either DirectionType::TabForward
or
DirectionType::TabBackward
pub fn connect_scroll_child<F: Fn(&Self, ScrollType, bool) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_scroll_child<F: Fn(&Self, ScrollType, bool) -> bool + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when a keybinding that scrolls is pressed.
This is a keybinding signal.
The horizontal or vertical adjustment is updated which triggers a signal that the scrolled window’s child may listen to and scroll itself.
scroll
a ScrollType
describing how much to scroll
horizontal
whether the keybinding scrolls the child horizontally or not
pub fn connect_hscrollbar_policy_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_kinetic_scrolling_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_max_content_height_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_max_content_width_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_min_content_height_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_min_content_width_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_overlay_scrolling_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_propagate_natural_height_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_propagate_natural_width_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_vscrollbar_policy_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_window_placement_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 ScrolledWindow
impl !Send for ScrolledWindow
impl !Sync for ScrolledWindow
impl Unpin for ScrolledWindow
impl UnwindSafe for ScrolledWindow
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
.