TinyMaterialDesign
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Dialog< RGB_T > Class Template Reference

Modal alert dialog: full-screen scrim + centered card + title + wrapped message + action widgets (typically Button). More...

#include <Dialog.h>

Inheritance diagram for Dialog< RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for Dialog< RGB_T >:
Collaboration graph
[legend]

Public Types

using ActionCountFn = std::function< int()>
 
using ActionAtFn = std::function< Widget< RGB_T > &(int index)>
 

Public Member Functions

 Dialog ()=default
 
 Dialog (Bounds cardBounds, const char *title, const char *message)
 
void setTitle (const char *title)
 
void setMessage (const char *message)
 
void addAction (Widget< RGB_T > &action)
 
void setActionProvider (ActionCountFn count, ActionAtFn at)
 Switches to callback-driven actions - see the class comment.
 
void setTheme (const MaterialTheme< RGB_T > &theme) override
 
Bounds actionRect (int index, int count, int32_t width=80, int32_t height=36) const
 
void draw (tinygpu::ISurface< RGB_T > &target) override
 
bool onGesture (const tinygpu::GestureEvent &event) override
 
bool update (uint32_t nowMs) override
 
bool isDraggableAt (int32_t x, int32_t y) const override
 
- Public Member Functions inherited from Widget< RGB_T >
virtual ~Widget ()=default
 
virtual void setTheme (const MaterialTheme< RGB_T > &theme)
 
virtual void draw (tinygpu::ISurface< RGB_T > &target)=0
 
virtual bool onGesture (const tinygpu::GestureEvent &event)
 Handles one gesture event. Returns true if this widget consumed it.
 
virtual bool update (uint32_t nowMs)
 
virtual bool isDraggable () const
 
virtual bool isDraggableAt (int32_t x, int32_t y) const
 
virtual int childCount () const
 
virtual Widget< RGB_T > * child (int index)
 
virtual void drawBackground (tinygpu::ISurface< RGB_T > &target)
 
virtual void setThemeTint (RGB_T background, RGB_T foreground)
 
virtual bool isContainer () const
 Provides true if the widget is a container.
 

Additional Inherited Members

- Public Attributes inherited from Widget< RGB_T >
Bounds bounds
 
bool visible = true
 
bool enabled = true
 
- Protected Member Functions inherited from Widget< RGB_T >
const MaterialTheme< RGB_T > & theme () const
 Convenience accessor for draw() overrides - see theme_.
 
- Protected Attributes inherited from Widget< RGB_T >
const MaterialTheme< RGB_T > * theme_ = nullptr
 

Detailed Description

template<typename RGB_T = TINYMD_DEFAULT_RGB_T>
class tinymd::Dialog< RGB_T >

Modal alert dialog: full-screen scrim + centered card + title + wrapped message + action widgets (typically Button).

Show it with Screen::presentDialog(dialog); while presented, Screen routes every gesture to the dialog first. Actions (usually Button) are not owned by Dialog - position each one's bounds (actionRect() suggests a spot), add it with addAction(), and wire its onClick to call screen.dismissDialog() itself.

Alternative to addAction(): setActionProvider(count, at) switches to callback-driven actions instead - see Container.h's class comment for the same pattern (at(index) returns a Widget reference, typically from a small reused pool). Not usually needed for a dialog's handful of actions, but available for consistency.

Member Typedef Documentation

◆ ActionAtFn

using ActionAtFn = std::function<Widget<RGB_T>&(int index)>

◆ ActionCountFn

using ActionCountFn = std::function<int()>

Constructor & Destructor Documentation

◆ Dialog() [1/2]

Dialog ( )
default

◆ Dialog() [2/2]

Dialog ( Bounds  cardBounds,
const char *  title,
const char *  message 
)
inline

cardBounds is the dialog card's own rect, not the full screen - the scrim is drawn separately, covering the whole target surface.

Member Function Documentation

◆ actionRect()

Bounds actionRect ( int  index,
int  count,
int32_t  width = 80,
int32_t  height = 36 
) const
inline

Suggested rect for the index-th of count actions, right-aligned along the card's bottom edge.

◆ addAction()

void addAction ( Widget< RGB_T > &  action)
inline

Registers action as content of this dialog. Ignored while an action provider is active - see setActionProvider().

◆ draw()

void draw ( tinygpu::ISurface< RGB_T > &  target)
inlineoverridevirtual

Renders the widget into target using colors/fonts/tokens from its own theme (see theme()/setTheme()).

Implements Widget< RGB_T >.

◆ isDraggableAt()

bool isDraggableAt ( int32_t  x,
int32_t  y 
) const
inlineoverridevirtual

True if there's an action at (x, y) - this dialog's own (screen-space) coordinate space - that's draggable, recursing into it if it's itself a composite - see Widget::isDraggableAt().

Reimplemented from Widget< RGB_T >.

◆ onGesture()

bool onGesture ( const tinygpu::GestureEvent &  event)
inlineoverridevirtual

Screen routes every gesture here while the dialog is presented; only taps landing on an action are forwarded to it, everything else is swallowed (a modal dialog shouldn't leak touches through to whatever is behind it).

Reimplemented from Widget< RGB_T >.

◆ setActionProvider()

void setActionProvider ( ActionCountFn  count,
ActionAtFn  at 
)
inline

Switches to callback-driven actions - see the class comment.

◆ setMessage()

void setMessage ( const char *  message)
inline

◆ setTheme()

void setTheme ( const MaterialTheme< RGB_T > &  theme)
inlineoverridevirtual

Cascades the theme down to every action already added - see addAction(). In provider mode, each action is themed at the point it's fetched instead (see actionAt()).

Reimplemented from Widget< RGB_T >.

◆ setTitle()

void setTitle ( const char *  title)
inline

◆ update()

bool update ( uint32_t  nowMs)
inlineoverridevirtual

Called once per frame, before draw(), to advance any time-based animation (ripple fade, indeterminate progress sweep, ...). Returns true if that advance changed anything this widget will draw differently, so Screen can decide whether a redraw is actually needed - see Screen::isDirty(). Default: no-op, not dirty, so widgets that don't animate cost nothing extra.

Reimplemented from Widget< RGB_T >.


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