S or /

SourceClass ScrollArea

from egui import ScrollArea
class ScrollArea:

Add vertical and/or horizontal scrolling to a contained Ui.

By default, scroll bars only show up when needed, i.e. when the contents is larger than the container. This is controlled by egui.ScrollArea.scroll_bar_visibility.

There are two flavors of scroll areas: solid and floating. Solid scroll bars use up space, reducing the amount of space available to the contents. Floating scroll bars float on top of the contents, covering it. You can change the scroll style by changing the egui.style.Spacing.scroll.

Coordinate system

  • content: size of contents (generally large; that's why we want scroll bars)
  • outer: size of scroll area including scroll bar(s)
  • inner: excluding scroll bar(s). The area we clip the contents to. Includes content_margin.

If the floating scroll bars settings is turned on then inner == outer.

Example

You can scroll to an element using egui.Response.scroll_to_me, Ui.scroll_to_cursor and Ui.scroll_to_rect.

See also

If you want to allow zooming, use egui.Scene.

Methods§

Sourcedef animated(self, /, animated: bool) -> ScrollArea§

Should the scroll area animate scroll_to_* functions?

Default: True.

Sourcedef auto_shrink(self, /, auto_shrink: bool) -> ScrollArea§

For each axis, should the containing area shrink if the content is small?

  • If True, egui will add blank space outside the scroll area.
  • If False, egui will add blank space inside the scroll area.

Default: True.

def auto_shrink_axes(self, /, auto_shrink: Any) -> ScrollArea§
Source@staticmethod def both() -> ScrollArea§

Create a bi-directional (horizontal and vertical) scroll area.

Sourcedef content_margin(self, /, margin: Margin) -> ScrollArea§

Extra margin added around the contents.

The scroll bars will be either on top of this margin, or outside of it, depending on the value of egui.style.ScrollStyle.floating.

Default: egui.style.ScrollStyle.content_margin.

def drag_to_scroll(self, /, drag_to_scroll: DragScroll) -> ScrollArea§
def enable_scrolling(self, /, enable: bool) -> ScrollArea§
Source@staticmethod def horizontal() -> ScrollArea§

Create a horizontal scroll area.

Sourcedef horizontal_scroll_offset(self, /, offset: float) -> ScrollArea§

Set the horizontal scroll offset position.

Positive offset means scrolling right.

See also: egui.ScrollArea.scroll_offset, Ui.scroll_to_cursor and Response.scroll_to_me

Sourcedef hscroll(self, /, hscroll: bool) -> ScrollArea§

Turn on/off scrolling on the horizontal axis.

Sourcedef id_salt(self, /, id_salt: str) -> ScrollArea§

A source for the unique Id, e.g. .id_salt("second_scroll_area") or .id_salt(loop_index).

def id_source(self, /, id_source: str) -> ScrollArea§
Sourcedef max_height(self, /, max_height: float) -> ScrollArea§

The maximum height of the outer frame of the scroll area.

Use float.INFINITY if you want the scroll area to expand to fit the surrounding Ui (default).

See also egui.ScrollArea.auto_shrink.

Sourcedef max_width(self, /, max_width: float) -> ScrollArea§

The maximum width of the outer frame of the scroll area.

Use float.INFINITY if you want the scroll area to expand to fit the surrounding Ui (default).

See also egui.ScrollArea.auto_shrink.

Sourcedef min_scrolled_height(self, /, min_scrolled_height: float) -> ScrollArea§

The minimum height of a vertical scroll area which requires scroll bars.

The ScrollArea will only become smaller than this if the content is smaller than this (and so we don't require scroll bars).

Default: 64.0.

Sourcedef min_scrolled_width(self, /, min_scrolled_width: float) -> ScrollArea§

The minimum width of a horizontal scroll area which requires scroll bars.

The ScrollArea will only become smaller than this if the content is smaller than this (and so we don't require scroll bars).

Default: 64.0.

Source@staticmethod def neither() -> ScrollArea§

Create a scroll area where both direction of scrolling is disabled. It's unclear why you would want to do this.

Source@staticmethod def new(direction_enabled: Any) -> ScrollArea§

Create a scroll area where you decide which axis has scrolling enabled. For instance, ScrollArea.new([True, False]) enables horizontal scrolling.

Sourcedef on_drag_cursor(self, /, cursor: CursorIcon) -> ScrollArea§

Set the cursor used when the ScrollArea is being dragged.

Only applies if egui.ScrollArea.scroll_source() has set ScrollSource.drag to True.

Any changes to the mouse cursor made within the contents of the ScrollArea will override this setting.

Sourcedef on_hover_cursor(self, /, cursor: CursorIcon) -> ScrollArea§

Set the cursor used when the mouse pointer is hovering over the ScrollArea.

Only applies if egui.ScrollArea.scroll_source() has set ScrollSource.drag to True.

Any changes to the mouse cursor made within the contents of the ScrollArea will override this setting.

Sourcedef scroll(self, /, direction_enabled: Any) -> ScrollArea§

Turn on/off scrolling on the horizontal/vertical axes.

You can pass in False, True, [False, True] etc.

Sourcedef scroll_bar_rect(self, /, scroll_bar_rect: Rect) -> ScrollArea§

Specify within which screen-space rectangle to show the scroll bars.

This can be used to move the scroll bars to a smaller region of the ScrollArea, for instance if you are painting a sticky header on top of it.

Sourcedef scroll_bar_visibility(self, /, visibility: ScrollBarVisibility) -> ScrollArea§

Set the visibility of both horizontal and vertical scroll bars.

With ScrollBarVisibility.VisibleWhenNeeded (default), the scroll bar will be visible only when needed.

Sourcedef scroll_offset(self, /, offset: Vec2) -> ScrollArea§

Set the horizontal and vertical scroll offset position.

Positive offset means scrolling down/right.

See also: egui.ScrollArea.vertical_scroll_offset, egui.ScrollArea.horizontal_scroll_offset, Ui.scroll_to_cursor and Response.scroll_to_me

Sourcedef scroll_source(self, /, scroll_source: ScrollSource) -> ScrollArea§

Control the scrolling behavior.

  • If True (default), the scroll area will respond to user scrolling.
  • If False, the scroll area will not respond to user scrolling.

This can be used, for example, to optionally freeze scrolling while the user is typing text in a egui.TextEdit widget contained within the scroll area.

What sources does the ScrollArea use for scrolling the contents.

Sourcedef show(self, /) -> Any§

To show a ScrollArea, call .show() wrapped within async with (...) as scroll_ui:. You can use another variable name instead of scroll_ui. You can then create widgets inside the ScrollArea's ui as if it was a regular ui.

Source

Show the ScrollArea, and add the contents to the viewport.

If the inner area can be very long, consider using egui.ScrollArea.show_rows instead.

Sourcedef show_rows(self, /, row_height: float, num_rows: int) -> Any§

Efficiently show only the visible part of a large number of rows.

Sourcedef show_viewport(self, /) -> Any§

This can be used to only paint the visible part of the contents.

add_contents is given the viewport rectangle, which is the relative view of the content. So if the passed rect has min = zero, then show the top left content (the user has not scrolled).

Sourcedef stick_to_bottom(self, /, stick: bool) -> ScrollArea§

The scroll handle will stick to the bottom position even while the content size changes dynamically. This can be useful to simulate terminal UIs or log/info scrollers. The scroll handle remains stuck until user manually changes position. Once "unstuck" it will remain focused on whatever content viewport the user left it on. If the scroll handle is dragged to the bottom it will again become stuck and remain there until manually pulled from the end position.

Sourcedef stick_to_right(self, /, stick: bool) -> ScrollArea§

The scroll handle will stick to the rightmost position even while the content size changes dynamically. This can be useful to simulate text scrollers coming in from right hand side. The scroll handle remains stuck until user manually changes position. Once "unstuck" it will remain focused on whatever content viewport the user left it on. If the scroll handle is dragged all the way to the right it will again become stuck and remain there until manually pulled from the end position.

Source@staticmethod def vertical() -> ScrollArea§

Create a vertical scroll area.

Sourcedef vertical_scroll_offset(self, /, offset: float) -> ScrollArea§

Set the vertical scroll offset position.

Positive offset means scrolling down.

See also: egui.ScrollArea.scroll_offset, Ui.scroll_to_cursor and Response.scroll_to_me

Sourcedef vscroll(self, /, vscroll: bool) -> ScrollArea§

Turn on/off scrolling on the vertical axis.

Sourcedef wheel_scroll_multiplier(self, /, multiplier: Vec2) -> ScrollArea§

The scroll amount caused by a mouse wheel scroll is multiplied by this amount.

Independent for each scroll direction. Defaults to Vec2{x: 1.0, y: 1.0}.

This can invert or effectively disable mouse scrolling.