UiUiUi
A user interface library for micro controller sketches based on U8g2
UIWidget.h
1// SPDX-License-Identifier: BSD-2-Clause
2// (C) 2022 Dirk Hillbrecht
3
4#pragma once
5
6#include "Arduino.h"
7#include <U8g2lib.h>
8
9#include "UIEnums.h"
10#include "UISize.h"
11#include "UIArea.h"
12//#include "UIParent.h"
13
14// Forward reference
15class UIParent;
16
36class UIWidget {
37 public:
38
44 UISize preferredSize(U8G2* display);
45
51 virtual void layout(U8G2* display,UIArea* area);
52
62 virtual UIArea* render(U8G2* display,bool force)=0;
63
66
72 virtual void setParent(UIParent *parent);
73
74 protected:
75
77 UIWidget(UIWidget *next=nullptr);
78
81
84
86 void clearBox(U8G2* display,UIArea *dimm);
87
89 void clearFull(U8G2 *display);
90
92 void clip(U8G2 *display);
93
98 virtual void computePreferredSize(U8G2 *display,UISize *preferredSize)=0;
99
102
103 private:
104
106 UISize thePreferredSize;
107
108};
109
110// end of file
Area consisting of left, top, right, and bottom value.
Definition: UIArea.h:20
Simple abstraction of elements which have at least one child.
Definition: UIParent.h:14
Representation of a size, i.e.
Definition: UISize.h:9
Basic widget class, ancestor of all UI widgets.
Definition: UIWidget.h:36
UIArea dim
Actual area of this widget, set in layout().
Definition: UIWidget.h:80
virtual UIArea * render(U8G2 *display, bool force)=0
Render component in the space given in layout().
virtual void layout(U8G2 *display, UIArea *area)
Layout widget in the given rectanglar area, will be called before first call to render().
Definition: UIWidget.cpp:22
void clip(U8G2 *display)
Set U8g2's clip window to the area of this widget, should be called from render().
Definition: UIWidget.cpp:35
void clearBox(U8G2 *display, UIArea *dimm)
Clear the given area.
Definition: UIWidget.cpp:26
UISize preferredSize(U8G2 *display)
Return the preferred size of this widget, will be called before a call to layout().
Definition: UIWidget.cpp:16
void signalNeedsRendering()
Called internally: Signals to parent that this widget needs to be rendered.
Definition: UIWidget.cpp:43
UIParent * parent
Reference to the group this widget is connected to.
Definition: UIWidget.h:83
UIWidget(UIWidget *next=nullptr)
Initialize this widget and potentially set its successor.
Definition: UIWidget.cpp:14
virtual void computePreferredSize(U8G2 *display, UISize *preferredSize)=0
Store preferred size of this widget into the preferredSize reference.
virtual void setParent(UIParent *parent)
Set the parent widget group (if it exists).
Definition: UIWidget.cpp:39
UIWidget * next
Pointer to the next widget on the same level.
Definition: UIWidget.h:65
void clearFull(U8G2 *display)
Clear the full area of this widget.
Definition: UIWidget.cpp:31