Implemented padding in uiStack.
This commit is contained in:
parent
8d64f695e0
commit
3f05be544c
28
new/stack.c
28
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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
2
new/ui.h
2
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 *);
|
||||
|
|
|
@ -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 *);
|
||||
|
|
Loading…
Reference in New Issue