morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::tui::Backend Class Referencefinal

Builds every widget of a mounted view tree as a core::tui::Component on one Screen. More...

#include <backend.hpp>

Inheritance diagram for morph::tui::Backend:
morph::ui::IViewBackend

Public Types

using Clock = std::function<std::chrono::steady_clock::time_point()>
 Reads the current time.

Public Member Functions

 Backend (::core::tui::Screen &screen, Clock now={})
 ~Backend () override
 Destroys the backend; every widget it made must already be gone.
 Backend (Backend const &)=delete
Backend & operator= (Backend const &)=delete
 Backend (Backend &&)=delete
Backend & operator= (Backend &&)=delete
std::unique_ptr< ui::TextWidget > createText (ui::ContainerWidget *parent) override
 Makes read-only text.
std::unique_ptr< ui::ButtonWidget > createButton (ui::ContainerWidget *parent) override
 Makes a push button.
std::unique_ptr< ui::TextInputWidget > createTextInput (ui::ContainerWidget *parent, ui::TextInputMode mode) override
 Makes a text field.
std::unique_ptr< ui::CheckboxWidget > createCheckbox (ui::ContainerWidget *parent) override
 Makes a check box.
std::unique_ptr< ui::SelectWidget > createSelect (ui::ContainerWidget *parent, ui::SelectStyle style) override
 Makes a choice of one option.
std::unique_ptr< ui::MenuWidget > createMenu (ui::ContainerWidget *parent) override
 Makes a command list.
std::unique_ptr< ui::StackWidget > createStack (ui::ContainerWidget *parent, ui::Axis axis) override
 Makes a stack.
std::unique_ptr< ui::GridWidget > createGrid (ui::ContainerWidget *parent) override
 Makes a grid.
std::unique_ptr< ui::SpacerWidget > createSpacer (ui::ContainerWidget *parent) override
 Makes empty space.
std::unique_ptr< ui::PanelWidget > createPanel (ui::ContainerWidget *parent) override
 Makes a titled frame.
std::unique_ptr< ui::ScrollWidget > createScroll (ui::ContainerWidget *parent, ui::Axis axis) override
 Makes a scroll area.
std::unique_ptr< ui::SlotWidget > createSlot (ui::ContainerWidget *parent) override
 Makes a slot.
std::unique_ptr< ui::TabsWidget > createTabs (ui::ContainerWidget *parent) override
 Makes a tab bar.
std::unique_ptr< ui::DialogWidget > createDialog (ui::ContainerWidget *parent) override
 Makes a modal overlay.
std::unique_ptr< ui::ToastWidget > createToast (ui::ContainerWidget *parent) override
 Makes a transient message.
std::unique_ptr< ui::BusyWidget > createBusy (ui::ContainerWidget *parent) override
 Makes a progress indicator.
std::unique_ptr< ui::TableWidget > createTable (ui::ContainerWidget *parent) override
 Makes a table.
std::unique_ptr< ui::DateTimeInputWidget > createDateTimeInput (ui::ContainerWidget *parent, ui::DateMode mode, int offsetMinutes) override
 Makes a date or date-and-time field.
std::unique_ptr< ui::SliderWidget > createSlider (ui::ContainerWidget *parent) override
 Makes a slider.
std::unique_ptr< ui::FilePickerWidget > createFilePicker (ui::ContainerWidget *parent, ui::FilePickerMode mode) override
 Makes a file path field.
std::unique_ptr< ui::BannerWidget > createBanner (ui::ContainerWidget *parent) override
 Makes a banner.
std::unique_ptr< ui::BadgeWidget > createBadge (ui::ContainerWidget *parent) override
 Makes a badge.
std::unique_ptr< ui::ProgressWidget > createProgress (ui::ContainerWidget *parent) override
 Makes a progress bar.
std::unique_ptr< ui::StepsWidget > createSteps (ui::ContainerWidget *parent) override
 Makes a steps indicator.
std::unique_ptr< ui::KeyValueWidget > createKeyValue (ui::ContainerWidget *parent) override
 Makes a key-value list.
std::unique_ptr< ui::EmptyStateWidget > createEmptyState (ui::ContainerWidget *parent) override
 Makes an empty state.
std::unique_ptr< ui::DrawerWidget > createDrawer (ui::ContainerWidget *parent, ui::Side side) override
 Makes a drawer.
std::unique_ptr< ui::SplitterWidget > createSplitter (ui::ContainerWidget *parent, ui::Axis axis) override
 Makes a splitter.
std::unique_ptr< ui::CollapsibleWidget > createCollapsible (ui::ContainerWidget *parent) override
 Makes a collapsible section.
std::unique_ptr< ui::DropZoneWidget > createDropZone (ui::ContainerWidget *parent) override
 Makes a drop zone.
void fit ()
 Sizes every root widget to the screen's viewport and centres every open dialog; call before each Screen::draw(), which is how a resize reaches the tree.
void focusNext ()
 Moves keyboard focus to the next focusable widget — inside the innermost open dialog when one is open, because Screen::focusNext does not know overlays.
void focusPrev ()
 Moves keyboard focus to the previous focusable widget, with focusNext's dialog rule.
void focusFirst ()
 Focuses the first focusable widget when nothing has focus yet, or when the focus is on an open dialog's frame (the dialog held nothing focusable when it opened, and has since gained something).
bool endDrag ()
 Ends the drag-and-drop gesture in progress, if any, with no drop, as Esc does.
bool animating () const noexcept
 Whether any Busy widget is spinning, so the frontend should keep advancing the animation.
void advanceAnimation () noexcept
 Moves every spinning Busy to its next frame; the next draw shows it.
Public Member Functions inherited from morph::ui::IViewBackend
 IViewBackend (IViewBackend const &)=delete
IViewBackend & operator= (IViewBackend const &)=delete
 IViewBackend (IViewBackend &&)=delete
IViewBackend & operator= (IViewBackend &&)=delete
virtual std::unique_ptr< CustomWidget > createCustom (ContainerWidget *parent, CustomRequest const &request)
 Loads the component a custom node names, if this backend can. The only factory that may return null: null means "not loaded", and the mount shows the node's fallback instead. A backend that loads no components keeps this default.

Detailed Description

Builds every widget of a mounted view tree as a core::tui::Component on one Screen.

Containers arrange their children in cells when the screen renders them; a Dialog and an open Dropdown are screen overlays; drag-and-drop runs on the mouse with pointer capture. The factories, documented on ui::IViewBackend, run on the screen's thread. Widgets must be destroyed before the backend, and the backend before the screen.

The widgets show no tooltips, so nothing here needs the screen's hover timer (Screen::tickHover). A widget that goes drops the screen's hover target, so a caller that does tick it never reaches a destroyed component.

Definition at line 28 of file backend.hpp.

Member Typedef Documentation

◆ Clock

using morph::tui::Backend::Clock = std::function<std::chrono::steady_clock::time_point()>

Reads the current time.

Definition at line 31 of file backend.hpp.

Constructor & Destructor Documentation

◆ Backend()

morph::tui::Backend::Backend ( ::core::tui::Screen & screen,
Clock now = {} )
explicit
Parameters
screenWhere every widget renders. Borrowed: it must outlive the backend.
nowThe clock the widgets read the time from (a table telling a double click from two clicks); empty reads std::chrono::steady_clock. A test passes one it advances itself.

Member Function Documentation

◆ createText()

std::unique_ptr< ui::TextWidget > morph::tui::Backend::createText ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes read-only text.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createButton()

std::unique_ptr< ui::ButtonWidget > morph::tui::Backend::createButton ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a push button.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createTextInput()

std::unique_ptr< ui::TextInputWidget > morph::tui::Backend::createTextInput ( ui::ContainerWidget * parent,
ui::TextInputMode mode )
nodiscardoverridevirtual

Makes a text field.

Parameters
parentThe container to append to, or null for a root.
modeSingle-line, multiline or password.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createCheckbox()

std::unique_ptr< ui::CheckboxWidget > morph::tui::Backend::createCheckbox ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a check box.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createSelect()

std::unique_ptr< ui::SelectWidget > morph::tui::Backend::createSelect ( ui::ContainerWidget * parent,
ui::SelectStyle style )
nodiscardoverridevirtual

Makes a choice of one option.

Parameters
parentThe container to append to, or null for a root.
styleDropdown or radio.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createMenu()

std::unique_ptr< ui::MenuWidget > morph::tui::Backend::createMenu ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a command list.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createStack()

std::unique_ptr< ui::StackWidget > morph::tui::Backend::createStack ( ui::ContainerWidget * parent,
ui::Axis axis )
nodiscardoverridevirtual

Makes a stack.

Parameters
parentThe container to append to, or null for a root.
axisVertical (a column) or horizontal (a row).
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createGrid()

std::unique_ptr< ui::GridWidget > morph::tui::Backend::createGrid ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a grid.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createSpacer()

std::unique_ptr< ui::SpacerWidget > morph::tui::Backend::createSpacer ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes empty space.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createPanel()

std::unique_ptr< ui::PanelWidget > morph::tui::Backend::createPanel ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a titled frame.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createScroll()

std::unique_ptr< ui::ScrollWidget > morph::tui::Backend::createScroll ( ui::ContainerWidget * parent,
ui::Axis axis )
nodiscardoverridevirtual

Makes a scroll area.

Parameters
parentThe container to append to, or null for a root.
axisThe scroll direction.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createSlot()

std::unique_ptr< ui::SlotWidget > morph::tui::Backend::createSlot ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a slot.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createTabs()

std::unique_ptr< ui::TabsWidget > morph::tui::Backend::createTabs ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a tab bar.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createDialog()

std::unique_ptr< ui::DialogWidget > morph::tui::Backend::createDialog ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a modal overlay.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createToast()

std::unique_ptr< ui::ToastWidget > morph::tui::Backend::createToast ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a transient message.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createBusy()

std::unique_ptr< ui::BusyWidget > morph::tui::Backend::createBusy ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a progress indicator.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createTable()

std::unique_ptr< ui::TableWidget > morph::tui::Backend::createTable ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a table.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createDateTimeInput()

std::unique_ptr< ui::DateTimeInputWidget > morph::tui::Backend::createDateTimeInput ( ui::ContainerWidget * parent,
ui::DateMode mode,
int offsetMinutes )
nodiscardoverridevirtual

Makes a date or date-and-time field.

Parameters
parentThe container to append to, or null for a root.
modeDate, or date and time.
offsetMinutesThe display zone's offset from UTC.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createSlider()

std::unique_ptr< ui::SliderWidget > morph::tui::Backend::createSlider ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a slider.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createFilePicker()

std::unique_ptr< ui::FilePickerWidget > morph::tui::Backend::createFilePicker ( ui::ContainerWidget * parent,
ui::FilePickerMode mode )
nodiscardoverridevirtual

Makes a file path field.

Parameters
parentThe container to append to, or null for a root.
modeOpen or save.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createBanner()

std::unique_ptr< ui::BannerWidget > morph::tui::Backend::createBanner ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a banner.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createBadge()

std::unique_ptr< ui::BadgeWidget > morph::tui::Backend::createBadge ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a badge.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createProgress()

std::unique_ptr< ui::ProgressWidget > morph::tui::Backend::createProgress ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a progress bar.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createSteps()

std::unique_ptr< ui::StepsWidget > morph::tui::Backend::createSteps ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a steps indicator.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createKeyValue()

std::unique_ptr< ui::KeyValueWidget > morph::tui::Backend::createKeyValue ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a key-value list.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createEmptyState()

std::unique_ptr< ui::EmptyStateWidget > morph::tui::Backend::createEmptyState ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes an empty state.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createDrawer()

std::unique_ptr< ui::DrawerWidget > morph::tui::Backend::createDrawer ( ui::ContainerWidget * parent,
ui::Side side )
nodiscardoverridevirtual

Makes a drawer.

Parameters
parentThe container to append to, or null for a root.
sideThe edge it slides in from.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createSplitter()

std::unique_ptr< ui::SplitterWidget > morph::tui::Backend::createSplitter ( ui::ContainerWidget * parent,
ui::Axis axis )
nodiscardoverridevirtual

Makes a splitter.

Parameters
parentThe container to append to, or null for a root.
axisThe axis its panes are laid out along.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createCollapsible()

std::unique_ptr< ui::CollapsibleWidget > morph::tui::Backend::createCollapsible ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a collapsible section.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ createDropZone()

std::unique_ptr< ui::DropZoneWidget > morph::tui::Backend::createDropZone ( ui::ContainerWidget * parent)
nodiscardoverridevirtual

Makes a drop zone.

Parameters
parentThe container to append to, or null for a root.
Returns
The widget.

Implements morph::ui::IViewBackend.

◆ endDrag()

bool morph::tui::Backend::endDrag ( )

Ends the drag-and-drop gesture in progress, if any, with no drop, as Esc does.

Esc reaches the gesture through the widget that has the keyboard focus; a frontend calls this for an Esc no widget took, so that a drag ends while nothing is focused too.

Returns
True when a drag was in progress and has ended.

◆ animating()

bool morph::tui::Backend::animating ( ) const
nodiscardnoexcept

Whether any Busy widget is spinning, so the frontend should keep advancing the animation.

Returns
True while at least one Busy is active.

The documentation for this class was generated from the following file: