Added uiStackRemove(), the first removal function in package ui! That took long enough... Now I can piece together all the control and parent logic...
This commit is contained in:
parent
949cd56611
commit
79f0650fee
16
stack.c
16
stack.c
|
@ -367,6 +367,22 @@ void uiStackAdd(uiControl *st, uiControl *c, int stretchy)
|
|||
uiParentUpdate(s->parent);
|
||||
}
|
||||
|
||||
void uiStackRemove(uiControl *st, uintptr_t index)
|
||||
{
|
||||
stack *s = (stack *) (st->data);
|
||||
uiControl *removed;
|
||||
uintmax_t nAfter;
|
||||
|
||||
removed = s->controls[index].c;
|
||||
nAfter = s->len - index - 1;
|
||||
memmove(&(s->controls[index + 1]), &(s->controls[index]), nAfter * sizeof (stackControl));
|
||||
s->len--;
|
||||
if (s->parent != NULL) {
|
||||
uiControlRemoveParent(removed);
|
||||
uiParentUpdate(s->parent);
|
||||
}
|
||||
}
|
||||
|
||||
int uiStackPadded(uiControl *c)
|
||||
{
|
||||
stack *s = (stack *) (c->data);
|
||||
|
|
36
test.c
36
test.c
|
@ -67,7 +67,7 @@ static void setCheckboxText(uiControl *b, void *data)
|
|||
}
|
||||
|
||||
uiWindow *w;
|
||||
#define nStacks 9
|
||||
#define nStacks 11
|
||||
uiControl *stacks[nStacks];
|
||||
uiControl *spaced;
|
||||
|
||||
|
@ -148,6 +148,22 @@ static void setLabelText(uiControl *b, void *data)
|
|||
uiFreeText(text);
|
||||
}
|
||||
|
||||
uiControl *firstStack;
|
||||
uiControl *secondStack;
|
||||
uiControl *movingLabel;
|
||||
|
||||
static void moveToFirst(uiControl *c, void *data)
|
||||
{
|
||||
uiStackRemove(secondStack, 1);
|
||||
uiStackAdd(firstStack, movingLabel, 1);
|
||||
}
|
||||
|
||||
static void moveToSecond(uiControl *c, void *data)
|
||||
{
|
||||
uiStackRemove(firstStack, 1);
|
||||
uiStackAdd(secondStack, movingLabel, 1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uiInitOptions o;
|
||||
|
@ -289,6 +305,24 @@ int main(int argc, char *argv[])
|
|||
uiTabAddPage(tab, "Page 2", stacks[i]);
|
||||
i++;
|
||||
|
||||
stacks[i] = uiNewHorizontalStack();
|
||||
firstStack = stacks[i];
|
||||
getButton = uiNewButton("Move Here");
|
||||
uiButtonOnClicked(getButton, moveToFirst, NULL);
|
||||
uiStackAdd(stacks[i], getButton, 0);
|
||||
movingLabel = uiNewLabel("This label moves!");
|
||||
uiStackAdd(stacks[i], movingLabel, 1);
|
||||
uiStackAdd(stacks[page2stack], stacks[i], 0);;
|
||||
i++;
|
||||
|
||||
stacks[i] = uiNewHorizontalStack();
|
||||
secondStack = stacks[i];
|
||||
getButton = uiNewButton("Move Here");
|
||||
uiButtonOnClicked(getButton, moveToSecond, NULL);
|
||||
uiStackAdd(stacks[i], getButton, 0);
|
||||
uiStackAdd(stacks[page2stack], stacks[i], 0);
|
||||
i++;
|
||||
|
||||
if (i != nStacks) {
|
||||
fprintf(stderr, "forgot to update nStacks (expected %d)\n", i);
|
||||
return 1;
|
||||
|
|
1
ui.h
1
ui.h
|
@ -131,6 +131,7 @@ void uiButtonOnClicked(uiControl *, void (*)(uiControl *, void *), void *);
|
|||
uiControl *uiNewHorizontalStack(void);
|
||||
uiControl *uiNewVerticalStack(void);
|
||||
void uiStackAdd(uiControl *, uiControl *, int);
|
||||
void uiStackRemove(uiControl *, uintmax_t);
|
||||
int uiStackPadded(uiControl *);
|
||||
void uiStackSetPadded(uiControl *, int);
|
||||
|
||||
|
|
Loading…
Reference in New Issue