ScrollView
ScrollView
Section titled “ScrollView”#include <ScrollView.hpp>Inherits:
Widget
A clipping container that lets a child widget be scrolled inside a fixed viewport.
ScrollView renders its child into an internal viewport and only copies the visible region back to the parent buffer. This makes it useful for long text blocks, logs, and any content that should be partially visible inside a smaller area.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
ScrollView | Defaulted constructor. | |
ScrollView explicit | ||
void | setContent | Sets the widget to display inside the scroll view. |
std::shared_ptr< Widget > | getContent const inline | Gets the current child widget. |
void | setContentSize | Sets an explicit content size for the scrollable area. |
void | clearContentSize | Clears any explicit content size and falls back to measure(). |
int | scrollX const inline | Gets the horizontal scroll offset. |
int | scrollY const inline | Gets the vertical scroll offset. |
void | setScroll | Sets the scroll offset, clamped to the current content bounds. |
void | scrollBy | Scrolls relative to the current position. |
bool | isFocusable virtual const inline | Returns whether this widget can receive keyboard focus. |
core::Size | measure virtual | Measures how much space this widget needs. |
void | layout virtual | Positions and sizes this widget and its children. |
bool | onEvent virtual | Handles an input event. |
std::vector< std::shared_ptr< Widget > > | getChildren virtual const inline | Returns this widget’s children. |
std::vector< std::shared_ptr< Widget > > | getFocusChildren virtual const inline | Returns this widget’s children for focus traversal. |
ScrollView
Section titled “ScrollView”ScrollView() = defaultDefaulted constructor.
ScrollView
Section titled “ScrollView”explicit
explicit ScrollView(std::shared_ptr< Widget > child)setContent
Section titled “setContent”void setContent(std::shared_ptr< Widget > child)Sets the widget to display inside the scroll view.
Parameters
Section titled “Parameters”childThe content widget to scroll, or nullptr to clear it
getContent
Section titled “getContent”const inline
inline std::shared_ptr< Widget > getContent() constGets the current child widget.
Returns
Section titled “Returns”The scroll view content, or nullptr if empty
setContentSize
Section titled “setContentSize”void setContentSize(core::Size size)Sets an explicit content size for the scrollable area.
Use this when the content widget’s natural measurement does not reflect its full scrollable size, such as when wrapping a container or layout. Passing 0 for a dimension auto-fills that dimension from the viewport.
Parameters
Section titled “Parameters”sizeThe scrollable content size in cells
clearContentSize
Section titled “clearContentSize”void clearContentSize()Clears any explicit content size and falls back to measure().
scrollX
Section titled “scrollX”const inline
inline int scrollX() constGets the horizontal scroll offset.
scrollY
Section titled “scrollY”const inline
inline int scrollY() constGets the vertical scroll offset.
setScroll
Section titled “setScroll”void setScroll(int x, int y)Sets the scroll offset, clamped to the current content bounds.
scrollBy
Section titled “scrollBy”void scrollBy(int dx, int dy)Scrolls relative to the current position.
isFocusable
Section titled “isFocusable”virtual const inline
virtual inline bool isFocusable() constReturns whether this widget can receive keyboard focus.
Widgets like Button and Input return true; containers return false.
Returns
Section titled “Returns”True if this widget can be focused, false otherwise
measure
Section titled “measure”virtual
virtual core::Size measure(int availW, int availH)Measures how much space this widget needs.
Called during the measurement pass to determine widget size requirements. Should return the preferred size based on available space.
Parameters
Section titled “Parameters”-
availWMaximum available width (may be ignored by widget) -
availHMaximum available height (may be ignored by widget)
Returns
Section titled “Returns”The Size this widget wants, or needs at minimum
layout
Section titled “layout”virtual
virtual void layout(int x, int y, int width, int height)Positions and sizes this widget and its children.
Called after measurement to actually place the widget at a specific location. If your widget has children, you must call their layout() methods here.
Parameters
Section titled “Parameters”-
xThe X coordinate for this widget -
yThe Y coordinate for this widget -
widthThe width allocated to this widget -
heightThe height allocated to this widget
onEvent
Section titled “onEvent”virtual
virtual bool onEvent(const core::events::Event & event)Handles an input event.
Called by the framework to deliver an event to this widget. The default implementation runs any listeners registered via addEventListener(), then returns false. Subclasses (Button, Input, etc.) override this to add built-in behavior, and should call Widget::onEvent(event) first to give user listeners a chance to handle the event before the widget’s own logic.
Return true if the event was handled, false to let it bubble to the parent widget.
Parameters
Section titled “Parameters”eventThe input event
Returns
Section titled “Returns”True if this widget (or one of its listeners) handled the event
getChildren
Section titled “getChildren”virtual const inline
virtual inline std::vector< std::shared_ptr< Widget > > getChildren() constReturns this widget’s children.
Returns
Section titled “Returns”Vector of child widgets (empty if no children)
getFocusChildren
Section titled “getFocusChildren”virtual const inline
virtual inline std::vector< std::shared_ptr< Widget > > getFocusChildren() constReturns this widget’s children for focus traversal.
By default this matches getChildren(). Widgets with custom rendering behavior (like clipping/compositing) can override this without affecting paint traversal.
Protected Methods
Section titled “Protected Methods”| Return | Name | Description |
|---|---|---|
void | drawContent virtual | Draws this widget’s content. |
drawContent
Section titled “drawContent”virtual
virtual void drawContent(backend::Buffer & buf, core::Rect inner)Draws this widget’s content.
Called by render() after background and borders are drawn. This is where you should draw your widget’s actual content. The inner rectangle accounts for borders and padding.
Parameters
Section titled “Parameters”-
bufThe buffer to draw to -
innerThe inner rectangle (excluding border/padding)
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
std::shared_ptr< Widget > | content | |
bool | hasExplicitContentSize | |
core::Size | explicitContentSize | |
core::Size | currentContentSize | |
core::Rect | currentInner | |
bool | hasLayout | |
core::Pos | scroll |
content
Section titled “content”std::shared_ptr< Widget > contenthasExplicitContentSize
Section titled “hasExplicitContentSize”bool hasExplicitContentSize = falseexplicitContentSize
Section titled “explicitContentSize”core::Size explicitContentSize {}currentContentSize
Section titled “currentContentSize”core::Size currentContentSize {}currentInner
Section titled “currentInner”core::Rect currentInner {}hasLayout
Section titled “hasLayout”bool hasLayout = falsescroll
Section titled “scroll”core::Pos scroll {}Private Methods
Section titled “Private Methods”| Return | Name | Description |
|---|---|---|
void | clampScroll | |
void | relayoutContent | |
core::Size | resolveContentSize const |
clampScroll
Section titled “clampScroll”void clampScroll()relayoutContent
Section titled “relayoutContent”void relayoutContent()resolveContentSize
Section titled “resolveContentSize”const
core::Size resolveContentSize(core::Rect inner) const