diff --git a/new/stack.c b/new/stack.c index fa28e59..eaa7a7e 100644 --- a/new/stack.c +++ b/new/stack.c @@ -13,6 +13,7 @@ struct stack { uintmax_t cap; int vertical; uintptr_t parent; + int padded; }; #define S(c) ((stack *) (c)) @@ -58,16 +59,22 @@ static uiSize stackPreferredSize(uiControl *c, uiSizing *d) intmax_t maxswid, maxsht; uintmax_t i; uiSize size, preferred; + uiSizingComm *dd = (uiSizingComm *) d; size.width = 0; size.height = 0; if (s->len == 0) return size; - // 1) add in padding - // TODO padding + // 0) get this Stack's padding xpadding = 0; ypadding = 0; + if (s->padded) { + xpadding = dd->xPadding; + ypadding = dd->yPadding; + } + + // 1) initialize the desired rect with the needed padding if (s->vertical) size.height = (s->len - 1) * ypadding; else @@ -117,13 +124,18 @@ static void stackResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, in intmax_t stretchywid, stretchyht; uintmax_t i; uiSize preferred; + uiSizingComm *dd = (uiSizingComm *) d; if (s->len == 0) return; - // TODO padding + // -1) get this Stack's padding xpadding = 0; ypadding = 0; + if (s->padded) { + xpadding = dd->xPadding; + ypadding = dd->yPadding; + } // 0) inset the available rect by the needed padding if (s->vertical) @@ -220,3 +232,13 @@ void uiStackAdd(uiControl *st, uiControl *c, int stretchy) s->len++; updateParent(s->parent); } + +// TODO get padded + +void uiStackSetPadded(uiControl *st, int padded) +{ + stack *s = S(st); + + s->padded = padded; + updateParent(s->parent); +} diff --git a/new/test.c b/new/test.c index f8e7c40..c4a373e 100644 --- a/new/test.c +++ b/new/test.c @@ -66,12 +66,17 @@ static void setCheckboxText(uiControl *b, void *data) } uiWindow *w; -uiControl *stacks[5]; +#define nStacks 5 +uiControl *stacks[nStacks]; uiControl *spaced; static void setSpaced(int spaced) { + int i; + uiWindowSetMargined(w, spaced); + for (i = 0; i < nStacks; i++) + uiStackSetPadded(stacks[i], spaced); } static void toggleSpaced(uiControl *c, void *data) diff --git a/new/ui.h b/new/ui.h index 0c32fba..8387dda 100644 --- a/new/ui.h +++ b/new/ui.h @@ -42,6 +42,8 @@ void uiButtonOnClicked(uiControl *, void (*)(uiControl *, void *), void *); uiControl *uiNewHorizontalStack(void); uiControl *uiNewVerticalStack(void); void uiStackAdd(uiControl *, uiControl *, int); +// TODO get padded +void uiStackSetPadded(uiControl *, int); uiControl *uiNewEntry(void); char *uiEntryText(uiControl *); diff --git a/new/uipriv.h b/new/uipriv.h index ebb1be4..26d06ba 100644 --- a/new/uipriv.h +++ b/new/uipriv.h @@ -4,16 +4,22 @@ typedef struct uiSize uiSize; typedef struct uiSizing uiSizing; +typedef struct uiSizingComm uiSizingComm; struct uiSize { intmax_t width; intmax_t height; }; +// TODO this is a bit iffy; clean it up #define uiSizingCommon \ intmax_t xPadding; \ intmax_t yPadding; +struct uiSizingComm { + uiSizingCommon +}; + struct uiControl { void (*destroy)(uiControl *); uintptr_t (*handle)(uiControl *);