Skip to content

Modal

#include <Modal.hpp>

Inherits: Widget

A full-screen dimmed overlay with a centered content box.

Modal renders a semi-transparent backdrop and centers its content widget on screen. Press Escape to dismiss unless dismissable = false.

ReturnNameDescription
Modal explicit
core::Sizemeasure virtualMeasures how much space this widget needs.
voidlayout virtualPositions and sizes this widget and its children.
boolonEvent virtualHandles an input event.
boolisFocusable virtual const inlineReturns whether this widget can receive keyboard focus.
voidhandleResize
std::vector< std::shared_ptr< Widget > >getChildren virtual const inlineReturns this widget’s children.

explicit

explicit Modal(std::shared_ptr< Widget > content, std::function< void()> onClose, bool dismissable)

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.

  • availW Maximum available width (may be ignored by widget)

  • availH Maximum available height (may be ignored by widget)

The Size this widget wants, or needs at minimum


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.

  • x The X coordinate for this widget

  • y The Y coordinate for this widget

  • width The width allocated to this widget

  • height The height allocated to this widget


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.

  • event The input event

True if this widget (or one of its listeners) handled the event


virtual const inline

virtual inline bool isFocusable() const

Returns whether this widget can receive keyboard focus.

Widgets like Button and Input return true; containers return false.

True if this widget can be focused, false otherwise


void handleResize(int termWidth, int termHeight)

virtual const inline

virtual inline std::vector< std::shared_ptr< Widget > > getChildren() const

Returns this widget’s children.

Vector of child widgets (empty if no children)

ReturnNameDescription
voiddrawContent virtualDraws this widget’s content.

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.

  • buf The buffer to draw to

  • inner The inner rectangle (excluding border/padding)

ReturnNameDescription
std::shared_ptr< core::Widget >content
std::function< void()>onClose
booldismissable
floatcontentW
floatcontentH

std::shared_ptr< core::Widget > content

std::function< void()> onClose

bool dismissable

float contentW = 0.5f

float contentH = 0.4f