TinyMaterialDesign
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Widget< RGB_T > Class Template Referenceabstract

Base class every TinyMaterialDesign widget derives from. More...

#include <Widget.h>

Inherited by Button< TINYMD_DEFAULT_RGB_T >, Container< TINYMD_DEFAULT_RGB_T >, IconButton< TINYMD_DEFAULT_RGB_T >, Keyboard< TINYMD_DEFAULT_RGB_T >, Label< TINYMD_DEFAULT_RGB_T >, ListItem< TINYMD_DEFAULT_RGB_T >, Menu< TINYMD_DEFAULT_RGB_T >, NavigationBar< TINYMD_DEFAULT_RGB_T >, RadioButton< TINYMD_DEFAULT_RGB_T >, SettingRow< TINYMD_DEFAULT_RGB_T >, Slider< TINYMD_DEFAULT_RGB_T >, Switch< TINYMD_DEFAULT_RGB_T >, TextField< TINYMD_DEFAULT_RGB_T >, WifiNetworkRow< TINYMD_DEFAULT_RGB_T >, AppBar< RGB_T >, Badge< RGB_T >, Banner< RGB_T >, BottomSheet< RGB_T >, Button< RGB_T >, Card< RGB_T >, Carousel< RGB_T >, Checkbox< RGB_T >, Chip< RGB_T >, CircularProgressIndicator< RGB_T >, Container< RGB_T >, Dialog< RGB_T >, Divider< RGB_T >, Drawer< RGB_T >, FloatingActionButton< RGB_T >, IconButton< RGB_T >, Keyboard< RGB_T >, Label< RGB_T >, LineChart< RGB_T >, LinearProgressIndicator< RGB_T >, ListItem< RGB_T >, MediaCard< RGB_T >, Menu< RGB_T >, NavigationBar< RGB_T >, NavigationRail< RGB_T >, RadioButton< RGB_T >, SearchBar< RGB_T >, SegmentedButton< RGB_T >, SettingRow< RGB_T >, Slider< RGB_T >, Snackbar< RGB_T >, StatTile< RGB_T >, Switch< RGB_T >, TabBar< RGB_T >, TextArea< RGB_T >, TextBlock< RGB_T >, TextField< RGB_T >, Tooltip< RGB_T >, and WifiNetworkRow< RGB_T >.

Collaboration diagram for Widget< RGB_T >:
Collaboration graph
[legend]

Public Member Functions

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.
 

Public Attributes

Bounds bounds
 
bool visible = true
 
bool enabled = true
 

Protected Member Functions

const MaterialTheme< RGB_T > & theme () const
 Convenience accessor for draw() overrides - see theme_.
 

Protected Attributes

const MaterialTheme< RGB_T > * theme_ = nullptr
 

Detailed Description

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

Base class every TinyMaterialDesign widget derives from.

Widgets are plain templated objects the sketch owns (as globals or members, same non-owning-reference style TinyGPU itself uses) and registers with a Screen via Screen::addWidget(). Screen calls draw()/ update()/onGesture() on the sketch's behalf each loop() iteration.

Constructor & Destructor Documentation

◆ ~Widget()

virtual ~Widget ( )
virtualdefault

Member Function Documentation

◆ child()

virtual Widget< RGB_T > * child ( int  index)
inlinevirtual

The index-th child (see childCount()); never called with an out-of-range index. Not owned by this widget any more than by whatever added it (addItem()/addAction()/...).

Reimplemented in Container< RGB_T >, Container< TINYMD_DEFAULT_RGB_T >, BottomSheet< RGB_T >, Drawer< RGB_T >, Menu< RGB_T >, and Menu< TINYMD_DEFAULT_RGB_T >.

◆ childCount()

virtual int childCount ( ) const
inlinevirtual

Number of child widgets this one draws as part of itself, if any (0 by default) - a composite widget like Drawer overrides this + child() to expose its items (Dialog its actions, etc.), so Screen::drawDirect() can draw a presented modal's children individually, each into its own small right-sized buffer, instead of needing one buffer big enough for the whole modal - see drawBackground().

Reimplemented in Container< RGB_T >, Container< TINYMD_DEFAULT_RGB_T >, BottomSheet< RGB_T >, Drawer< RGB_T >, Menu< RGB_T >, and Menu< TINYMD_DEFAULT_RGB_T >.

◆ draw()

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

◆ drawBackground()

virtual void drawBackground ( tinygpu::ISurface< RGB_T > &  target)
inlinevirtual

Draws everything this widget owns except its children (see childCount()) - e.g. Drawer's scrim + panel fill, without its list items. Default: draws everything via draw() itself, which is exactly right for a widget that doesn't override childCount() (its "children" are however many it reports - zero - so nothing is skipped). Screen::drawDirect() calls this instead of draw() for a presented modal, then draws each child (if any) separately.

Reimplemented in Container< RGB_T >, BottomSheet< RGB_T >, Drawer< RGB_T >, and Menu< RGB_T >.

◆ isContainer()

virtual bool isContainer ( ) const
inlinevirtual

Provides true if the widget is a container.

Reimplemented in Container< RGB_T >, and Container< TINYMD_DEFAULT_RGB_T >.

◆ isDraggable()

virtual bool isDraggable ( ) const
inlinevirtual

Whether a continuous drag starting inside this widget's bounds should be classified as GestureType::kDrag (see GestureDetector::isDraggable and Screen::isDraggableAt). Only Slider (and Carousel, for its own horizontal swipe) needs true.

Reimplemented in Carousel< RGB_T >, Slider< RGB_T >, and Slider< TINYMD_DEFAULT_RGB_T >.

◆ isDraggableAt()

virtual bool isDraggableAt ( int32_t  x,
int32_t  y 
) const
inlinevirtual

Whether a drag starting at (x, y) - this widget's own coordinate space - should be classified as GestureType::kDrag. Default: just isDraggable(), ignoring the point - correct for any leaf widget. A composite (Container, Dialog, Drawer, Menu, BottomSheet) overrides this to recurse into whichever child sits at that point instead, so e.g. a Slider nested inside one of them is still recognized correctly by Screen::isDraggableAt().

Reimplemented in Screen< RGB_T >, Screen< TINYMD_DEFAULT_RGB_T >, Container< RGB_T >, Container< TINYMD_DEFAULT_RGB_T >, Banner< RGB_T >, BottomSheet< RGB_T >, Dialog< RGB_T >, Drawer< RGB_T >, Menu< RGB_T >, Menu< TINYMD_DEFAULT_RGB_T >, and SliderRow< RGB_T >.

◆ onGesture()

virtual bool onGesture ( const tinygpu::GestureEvent &  event)
inlinevirtual

◆ setTheme()

virtual void setTheme ( const MaterialTheme< RGB_T > &  theme)
inlinevirtual

Sets the theme this widget draws itself with - see theme(). Screen pushes its own theme into a widget at registration time (addWidget()/addFixedWidget()/presentDialog()) and again whenever Screen::setTheme() is called; container widgets (Dialog, Drawer) cascade this down to whatever children they already hold.

Reimplemented in Container< RGB_T >, Screen< RGB_T >, Banner< RGB_T >, BottomSheet< RGB_T >, Carousel< RGB_T >, Dialog< RGB_T >, Drawer< RGB_T >, Menu< RGB_T >, SliderRow< RGB_T >, SwitchRow< RGB_T >, and RadioRow< RGB_T >.

◆ setThemeTint()

virtual void setThemeTint ( RGB_T  background,
RGB_T  foreground 
)
inlinevirtual

Lets a container (AppBar, chiefly) push its own background/foreground color pair down onto a child it draws itself (leading/trailing), so e.g. an IconButton in an app bar with a color override reads clearly against it by default instead of staying on its own theme-wide default (which is tuned to sit on theme.colors.surface, not whatever color the app bar happens to be). Default: no-op, correct for any widget with no notion of "ambient" vs. its own explicit styling. IconButton overrides this as a fallback only used when it has no explicit setColorOverride() of its own, so e.g. a record button's active-red override still wins over the app bar's ambient tint.

Reimplemented in IconButton< RGB_T >.

◆ theme()

const MaterialTheme< RGB_T > & theme ( ) const
inlineprotected

Convenience accessor for draw() overrides - see theme_.

◆ update()

virtual bool update ( uint32_t  nowMs)
inlinevirtual

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 in Container< RGB_T >, Container< TINYMD_DEFAULT_RGB_T >, Screen< RGB_T >, Screen< TINYMD_DEFAULT_RGB_T >, AppBar< RGB_T >, Banner< RGB_T >, BottomSheet< RGB_T >, Button< RGB_T >, Button< TINYMD_DEFAULT_RGB_T >, Carousel< RGB_T >, Dialog< RGB_T >, Drawer< RGB_T >, FloatingActionButton< RGB_T >, IconButton< RGB_T >, IconButton< TINYMD_DEFAULT_RGB_T >, Menu< RGB_T >, Menu< TINYMD_DEFAULT_RGB_T >, LinearProgressIndicator< RGB_T >, CircularProgressIndicator< RGB_T >, SearchBar< RGB_T >, Snackbar< RGB_T >, TextArea< RGB_T >, TextField< RGB_T >, TextField< TINYMD_DEFAULT_RGB_T >, and Tooltip< RGB_T >.

Member Data Documentation

◆ bounds

Bounds bounds

◆ enabled

bool enabled = true

◆ theme_

const MaterialTheme<RGB_T>* theme_ = nullptr
protected

The theme this widget draws itself with - set via setTheme(), pushed in by Screen at registration time. Never dereferenced before that - every widget is registered with a Screen (which always has a theme, default-constructed if nothing else) before its first draw().

◆ visible

bool visible = true

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