Scrollable working - now to make it a container.
This commit is contained in:
parent
b27ef131c7
commit
f1878955e5
8 changed files with 42 additions and 28 deletions
|
@ -63,7 +63,6 @@ static void guiDeleteListProcess(void) {
|
|||
_deleteList[0]->reg->destroy(_deleteList[0]);
|
||||
arrdel(_deleteList, 0);
|
||||
}
|
||||
arrfree(_deleteList);
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,7 +125,9 @@ void guiShutdown(void) {
|
|||
uint8_t i;
|
||||
|
||||
wmShutdown();
|
||||
|
||||
guiDeleteListProcess();
|
||||
arrfree(_deleteList);
|
||||
|
||||
DEL(__guiBaseColors);
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@ CheckboxT *checkboxCreate(char *label, uint8_t value, ...) {
|
|||
static void checkboxDestroy(struct WidgetS *widget, ...) {
|
||||
CheckboxT *c = (CheckboxT *)widget;
|
||||
|
||||
widgetDestroy(W(c->label));
|
||||
// Do not destroy label here - the parent owns it at this point.
|
||||
|
||||
DEL(c);
|
||||
}
|
||||
|
||||
|
@ -104,8 +105,11 @@ static void checkboxPaint(struct WidgetS *widget, ...) {
|
|||
// Paint checkbox.
|
||||
surfaceBoxHighlight(c->base.r.x, c->base.r.y + 1, c->base.r.x + h, c->base.r.y + h, c->value ? GUI_BLACK : GUI_WHITE, c->value ? GUI_WHITE : GUI_BLACK);
|
||||
surfaceBoxFilled(c->base.r.x + 1, c->base.r.y + 2, c->base.r.x + h - 1, c->base.r.y + h - 1, c->value ? GUI_DARKGRAY : GUI_WHITE);
|
||||
// Paint label.
|
||||
widgetPaintManually(W(c->label), c->base.r.x + w, c->base.r.y);
|
||||
// Finish initializing.
|
||||
if (!c->attached) {
|
||||
c->attached = 1;
|
||||
windowWidgetAdd(c->base.parent, c->base.r.x + w, c->base.r.y, W(c->label));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
typedef struct CheckboxS {
|
||||
WidgetT base; // Required by all widgets.
|
||||
LabelT *label; // Label to display text.
|
||||
uint8_t attached; // Have we attached the label?
|
||||
ClickHandlerT handler; // Actual event handler.
|
||||
uint8_t value; // Is theis checkbox selected?
|
||||
} CheckboxT;
|
||||
|
|
|
@ -89,7 +89,8 @@ RadioT *radioCreate(char *label, uint8_t group, uint8_t value, ...) {
|
|||
static void radioDestroy(struct WidgetS *widget, ...) {
|
||||
RadioT *r = (RadioT *)widget;
|
||||
|
||||
widgetDestroy(W(r->label));
|
||||
// Do not destroy label here - the parent owns it at this point.
|
||||
|
||||
DEL(r);
|
||||
}
|
||||
|
||||
|
@ -141,8 +142,11 @@ static void radioPaint(struct WidgetS *widget, ...) {
|
|||
i += d;
|
||||
}
|
||||
|
||||
// Paint label.
|
||||
widgetPaintManually(W(r->label), r->base.r.x + w, r->base.r.y);
|
||||
// Finish initializing.
|
||||
if (!r->attached) {
|
||||
r->attached = 1;
|
||||
windowWidgetAdd(r->base.parent, r->base.r.x + w, r->base.r.y, W(r->label));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
typedef struct RadioS {
|
||||
WidgetT base; // Required by all widgets.
|
||||
LabelT *label; // Label to display text.
|
||||
uint8_t attached; // Have we attached the label?
|
||||
ClickHandlerT handler; // Actual event handler.
|
||||
uint8_t value; // Is this radio button selected?
|
||||
uint8_t group; // Which group does this radio button belong to?
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "../image.h"
|
||||
|
||||
#include "../wmwindow.h"
|
||||
#include "scroll.h"
|
||||
|
||||
|
||||
|
@ -37,6 +36,7 @@ static void scrollablePaint(struct WidgetS *widget, ...);
|
|||
|
||||
|
||||
static void scrollableClickHandler(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event, void *data) {
|
||||
logWrite("Event from scrollable\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,7 +54,7 @@ ScrollableT *scrollableCreate(int16_t width, int16_t height, int16_t totalWidth,
|
|||
if (s->flags & SCROLLABLE_SCROLL_V) {
|
||||
s->scrollv = vscrollCreate(height, scrollableClickHandler, NULL);
|
||||
vscrollRangeSet(s->scrollv, 0, totalHeight- 1);
|
||||
w = s->scrollv->base.r.w;
|
||||
w = s->scrollv->base.r.w; // Used when creating horizontal scroll bar below.
|
||||
}
|
||||
if (s->flags & SCROLLABLE_SCROLL_H) {
|
||||
s->scrollh = hscrollCreate(width - w, scrollableClickHandler, NULL);
|
||||
|
@ -80,9 +80,8 @@ ScrollableT *scrollableCreate(int16_t width, int16_t height, int16_t totalWidth,
|
|||
static void scrollableDestroy(struct WidgetS *widget, ...) {
|
||||
ScrollableT *s = (ScrollableT *)widget;
|
||||
|
||||
if (s->scrollh) widgetDestroy(W(s->scrollh));
|
||||
if (s->scrollv) widgetDestroy(W(s->scrollv));
|
||||
if (s->area) surfaceDestroy(&s->area);
|
||||
// Do not destroy scroll bars here - the parent owns them at this point.
|
||||
if (s->area) surfaceDestroy(&s->area);
|
||||
|
||||
DEL(s);
|
||||
}
|
||||
|
@ -90,26 +89,28 @@ static void scrollableDestroy(struct WidgetS *widget, ...) {
|
|||
|
||||
static void scrollablePaint(struct WidgetS *widget, ...) {
|
||||
ScrollableT *s = (ScrollableT *)widget;
|
||||
int16_t width;
|
||||
int16_t height;
|
||||
|
||||
if (widgetDirtyGet(widget)) {
|
||||
widgetDirtySet(widget, 0);
|
||||
// Find height and width of blittable area, based on presence of scrollbars.
|
||||
if (s->scrollh) {
|
||||
height = s->base.r.h - s->scrollh->base.r.h;
|
||||
widgetPaintManually(W(s->scrollh), s->base.r.x, s->base.r.y + height);
|
||||
} else {
|
||||
height = s->base.r.h;
|
||||
}
|
||||
if (s->scrollv) {
|
||||
width = s->base.r.w - s->scrollv->base.r.w;
|
||||
widgetPaintManually(W(s->scrollv), s->base.r.x + width, s->base.r.y);
|
||||
} else {
|
||||
width = s->base.r.w;
|
||||
// Finish initializing?
|
||||
if (s->sizes.x == 0 && s->sizes.y == 0) {
|
||||
if (s->scrollh) {
|
||||
s->sizes.y = s->base.r.h - s->scrollh->base.r.h;
|
||||
s->base.r.h -= s->scrollh->base.r.h;
|
||||
windowWidgetAdd(s->base.parent, s->base.r.x, s->base.r.y + s->sizes.y, W(s->scrollh));
|
||||
} else {
|
||||
s->sizes.y = s->base.r.h;
|
||||
}
|
||||
if (s->scrollv) {
|
||||
s->sizes.x = s->base.r.w - s->scrollv->base.r.w;
|
||||
s->base.r.w -= s->scrollv->base.r.w;
|
||||
windowWidgetAdd(s->base.parent, s->base.r.x + s->sizes.x, s->base.r.y, W(s->scrollv));
|
||||
} else {
|
||||
s->sizes.x = s->base.r.w;
|
||||
}
|
||||
}
|
||||
// Blit.
|
||||
surfaceBlit(s->base.r.x, s->base.r.y, s->offset.x, s->offset.y, width, height, s->area);
|
||||
surfaceBlit(s->base.r.x, s->base.r.y, s->offset.x, s->offset.y, s->sizes.x, s->sizes.y, s->area);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ typedef struct ScrollableS {
|
|||
SurfaceT *area; // Scrollable area buffer.
|
||||
HscrollT *scrollh; // Horizontal scroll bar.
|
||||
VscrollT *scrollv; // Vertical scroll bar.
|
||||
PointT sizes; // Scroll bar width and height info.
|
||||
uint8_t flags; // Flag bits.
|
||||
} ScrollableT;
|
||||
|
||||
|
|
|
@ -872,6 +872,7 @@ void windowWidgetRemove(WindowT *window, WidgetT *widget) {
|
|||
void wmShutdown(void) {
|
||||
uint16_t i;
|
||||
|
||||
// Delete all windows.
|
||||
for (i=0; i<arrlen(_windowList); i++) widgetDestroy(W(_windowList[i]));
|
||||
arrfree(_windowList);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue