Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TouchScreenGUIDemo
Diff: Widgets/ContainerWidget.h
- Revision:
- 12:63db16fea709
- Parent:
- 9:616a9686d5db
- Child:
- 13:6714534e7974
diff -r b485561aa112 -r 63db16fea709 Widgets/ContainerWidget.h
--- a/Widgets/ContainerWidget.h Fri Apr 22 16:12:42 2016 +0000
+++ b/Widgets/ContainerWidget.h Sun May 08 14:42:08 2016 +0000
@@ -2,147 +2,38 @@
#define SIMPLEGUI_CONTAINER_WIDGET_H
#include "Widget.h"
-
-class WidgetList
-{
-
-public:
-
- WidgetList(Widget* w) : widget(w), next(NULL) {}
-
- Widget* widget;
- WidgetList* next;
-
-};
+#include "Window.h"
/**
* Simple container hold widgets side-by-side and draws a border
* It will expand as needed to hold the widgets
**/
-class ContainerWidget : public Widget
+class ContainerWidget : public Window
{
public:
- ContainerWidget(GUI* gui) : Widget(gui), _padding(0), _borderWidth(1), _borderColour(White), _widgets(NULL) {
- }
-
- /**
- * Set the amount of padding between the border and a widget edge
- **/
- void setPadding(int pixels) {
- if(_padding != pixels) {
- _padding = pixels;
- adjust();
- }
- }
-
- void setBorder(int width, uint16_t colour) {
- _borderColour = colour;
- if(_borderWidth != width) {
- _borderWidth = width;
- adjust();
- }
- }
-
- void append(Widget* widget) {
-
- WidgetList* w = new WidgetList(widget);
- WidgetList* p = _widgets;
-
- if(_widgets == NULL) {
- _widgets = w;
- } else {
- while(p->next != NULL) {
- p = p->next;
- }
-
- p->next = w;
- }
-
- adjust();
- }
-
- virtual void setLocation(int x, int y) {
- Widget::setLocation(x,y);
- adjust();
- }
-
- virtual void setSize(int width, int height) {
- Widget::setSize(width, height);
- _minWidth = width;
- _minHeight = height;
- adjust();
- }
+ enum Layout { VERTICAL_LEFT, VERTICAL_RIGHT, VERTICAL_CENTER, HORIZONTAL };
- virtual void adjust() {
- int wx = _x + _padding + _borderWidth;
- int wy = _y + _padding + _borderWidth;
- int h = 0;
-
- _width = _minWidth;
- _height = _minHeight;
-
- WidgetList* p = _widgets;
- while(p != NULL) {
- // Position the widget
- p->widget->setLocation(wx, wy);
- wx += p->widget->width();
- if(p->widget->height() > h) {
- h = p->widget->height();
- }
-
- p = p->next;
- }
+ ContainerWidget(GraphicsContext *context);
+
+ /**
+ * Overrides
+ **/
+ virtual void setSize(int width, int height);
- int neededWidth = _padding + _borderWidth + wx - _x;
- int neededHeight = 2 * (_padding + _borderWidth) + h;
-
- if(neededWidth > _width) {
- _width = neededWidth;
- }
-
- if(neededHeight > _height) {
- _height = neededHeight;
- }
- }
+ void setLayout(Layout l);
- virtual void _draw() {
- // Draw the border
- // Top
- _gui->display()->fillrect(_x, _y, _x+_width, _y+_borderWidth, _borderColour);
- // Bottom
- _gui->display()->fillrect(_x, _y + _height - _borderWidth, _x + _width, _y+_height, _borderColour);
- // Left
- _gui->display()->fillrect(_x, _y, _x+_borderWidth, _y+_height, _borderColour);
- // Right
- _gui->display()->fillrect(_x+_width-_borderWidth, _y, _x+_width, _y+_height, _borderColour);
-
- WidgetList* p = _widgets;
- while(p != NULL) {
- p->widget->draw();
- p = p->next;
- }
- }
-
- virtual void _clear() {
- WidgetList* p = _widgets;
- while(p != NULL) {
- p->widget->clear();
- p = p->next;
- }
- }
-
-
-
protected:
- int _padding;
- int _borderWidth;
- uint16_t _borderColour;
+ int _minWidth, _minHeight;
+ Layout _layout;
+
+ /**
+ * Override
+ **/
+ virtual void _adjust();
- int _minWidth, _minHeight;
- WidgetList* _widgets;
};
#endif
\ No newline at end of file