UiUiUi
A user interface library for micro controller sketches based on U8g2
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
UIWidget Class Referenceabstract

Basic widget class, ancestor of all UI widgets. More...

#include <UIWidget.h>

Inheritance diagram for UIWidget:
Inheritance graph
[legend]
Collaboration diagram for UIWidget:
Collaboration graph
[legend]

Public Member Functions

UISize preferredSize (U8G2 *display)
 Return the preferred size of this widget, will be called before a call to layout(). More...
 
virtual void layout (U8G2 *display, UIArea *area)
 Layout widget in the given rectanglar area, will be called before first call to render(). More...
 
virtual UIArearender (U8G2 *display, bool force)=0
 Render component in the space given in layout(). More...
 
virtual void setParent (UIParent *parent)
 Set the parent widget group (if it exists). More...
 

Public Attributes

UIWidgetnext
 Pointer to the next widget on the same level.
 

Protected Member Functions

 UIWidget (UIWidget *next=nullptr)
 Initialize this widget and potentially set its successor.
 
void clearBox (U8G2 *display, UIArea *dimm)
 Clear the given area.
 
void clearFull (U8G2 *display)
 Clear the full area of this widget.
 
void clip (U8G2 *display)
 Set U8g2's clip window to the area of this widget, should be called from render().
 
virtual void computePreferredSize (U8G2 *display, UISize *preferredSize)=0
 Store preferred size of this widget into the preferredSize reference. More...
 
void signalNeedsRendering ()
 Called internally: Signals to parent that this widget needs to be rendered.
 

Protected Attributes

UIArea dim
 Actual area of this widget, set in layout().
 
UIParentparent
 Reference to the group this widget is connected to.
 

Detailed Description

Basic widget class, ancestor of all UI widgets.

A UIWidget has three basic operations which are called by the framework in that order:

  1. preferredSize() returns the size the widget wants to have on the screen. Any or all lengths may be Size::MAX_LEN in which case it gets what is available.
  2. layout() gets the actual coordinates in which the widget may render itself. They can be larger or smaller than the preferred size. The widget has to cope with it.
  3. render() asks the widget to actually draw itself into the frame buffer. It must restrict itself to the area it is assigned to. It returns the area where it actually has changed something. If no changes are needed, it returns the empty area.

A UIWidget may have a successor which is the next widget in the interface ON THE SAME LEVEL. Specialized UIWidgets bring certain semantics into such a chain of widgets.

The UIWidget class itself has only a tiny amount of business logic. The majority of it is spread through a number of derived classes representing all kinds of user interface elements.

Member Function Documentation

◆ computePreferredSize()

virtual void UIWidget::computePreferredSize ( U8G2 *  display,
UISize preferredSize 
)
protectedpure virtual

Store preferred size of this widget into the preferredSize reference.

Implementations can be assured to be called only once and the passed preferredSize will be (0,0).

Implemented in UIBitmap, UICards, UICheckerboard, UIColumns, UIEnvelope, UIHorizontalLine, UIRows, UITextIcon, UITextLine, and UIVerticalLine.

◆ layout()

void UIWidget::layout ( U8G2 *  display,
UIArea area 
)
virtual

Layout widget in the given rectanglar area, will be called before first call to render().

Note that overloading implementation should invoke UIWidget::layout(), otherwise certain internal mechanisms will not work.

Reimplemented in UICards, UIColumns, UIEnvelope, and UIRows.

◆ preferredSize()

UISize UIWidget::preferredSize ( U8G2 *  display)

Return the preferred size of this widget, will be called before a call to layout().

This method delegates the operation into computePreferredSize() if the preferred size has not yet been computed.

◆ render()

virtual UIArea * UIWidget::render ( U8G2 *  display,
bool  force 
)
pure virtual

Render component in the space given in layout().

If force is true, the component must render itself in its rectangle. Otherwise, it may refrain from doing anything if its internal state says that nothing has changed. Component returns the area which actually must be written to screen. This area may be smaller than the whole area of the component. If the component has not changed anything, it must return an empty area, e.g. UIArea::EMPTY().

Implemented in UIBitmap, UICards, UICheckerboard, UIEnvelope, UIHorizontalLine, UITextLine, UIVerticalLine, and UIWidgetGroup.

◆ setParent()

void UIWidget::setParent ( UIParent parent)
virtual

Set the parent widget group (if it exists).

This method is called by the widget group this widget is assigned to during initialisation. It should not be called by anyone else.


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