Started implementing the changes in dilemma.md. Migrated box.c; did most of ui.idl as well.

This commit is contained in:
Pietro Gagliardi 2015-04-26 23:01:00 -04:00
parent 2ef8e4b912
commit 54f16419ea
2 changed files with 41 additions and 167 deletions

192
new/box.c
View File

@ -7,18 +7,17 @@ typedef struct box box;
typedef struct boxControl boxControl; typedef struct boxControl boxControl;
struct box { struct box {
uiBox s; uiBox b;
void (*baseDestroy)(uiControl *);
void (*baseSetParent)(uiControl *, uiContainer *);
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
boxControl *controls; boxControl *controls;
uintmax_t len; uintmax_t len;
uintmax_t cap; uintmax_t cap;
int vertical; int vertical;
int hasParent; int hasParent;
uiOSContainer *osContainer; uiContainer *parent;
int padded; int padded;
int userHid;
int containerHid;
int userDisabled;
int containerDisabled;
}; };
struct boxControl { struct boxControl {
@ -33,43 +32,30 @@ static void boxDestroy(uiControl *c)
box *b = (box *) c; box *b = (box *) c;
uintmax_t i; uintmax_t i;
if (b->hasParent) (*(b->baseDestroy))(c);
complain("attempt to destroy a uiControl at %p while it still has a parent", c);
for (i = 0; i < b->len; i++) { for (i = 0; i < b->len; i++) {
uiControlSetHasParent(b->controls[i].c, 0); uiControlSetParent(b->controls[i].c, NULL);
uiControlSetOSContainer(b->controls[i].c, NULL);
uiControlDestroy(b->controls[i].c); uiControlDestroy(b->controls[i].c);
} }
uiFree(b->controls); uiFree(b->controls);
uiFree(b); uiFree(b);
} }
static uintptr_t boxHandle(uiControl *c) static void boxSetParent(uiControl *c, uiContainer *parent)
{
return 0;
}
static void boxSetHasParent(uiControl *c, int hasParent)
{
box *b = (box *) c;
b->hasParent = hasParent;
}
static void boxSetOSContainer(uiControl *c, uiOSContainer *osContainer)
{ {
box *b = (box *) c; box *b = (box *) c;
uintmax_t i; uintmax_t i;
uiOSContainer *oldcontainer; uiOSContainer *oldparent;
oldcontainer = b->osContainer; (*(b->baseSetParent))(c, parent);
b->osContainer = osContainer; oldparent = b->parent;
b->parent = parent;
for (i = 0; i < b->len; i++) for (i = 0; i < b->len; i++)
uiControlSetOSContainer(b->controls[i].c, b->osContainer); uiControlSetParent(b->controls[i].c, b->parent);
if (oldcontainer != NULL) if (oldparent != NULL)
uiOSContainerUpdate(oldcontainer); uiContainerUpdate(oldparent);
if (b->osContainer != NULL) if (b->parent != NULL)
uiOSContainerUpdate(b->osContainer); uiContainerUpdate(b->parent);
} }
static void boxPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) static void boxPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
@ -147,6 +133,8 @@ static void boxResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intm
uintmax_t i; uintmax_t i;
intmax_t preferredWidth, preferredHeight; intmax_t preferredWidth, preferredHeight;
(*(b->baseResize))(c, x, y, width, height, d);
if (b->len == 0) if (b->len == 0)
return; return;
@ -215,107 +203,6 @@ static void boxResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intm
} }
} }
static int boxVisible(uiControl *c)
{
box *b = (box *) c;
return !(b->userHid);
}
static void boxShow(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->userHid = 0;
if (!b->containerHid) {
for (i = 0; i < b->len; i++)
uiControlContainerShow(b->controls[i].c);
if (b->osContainer != NULL)
uiOSContainerUpdate(b->osContainer);
}
}
static void boxHide(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->userHid = 1;
for (i = 0; i < b->len; i++)
uiControlContainerHide(b->controls[i].c);
if (b->osContainer != NULL)
uiOSContainerUpdate(b->osContainer);
}
static void boxContainerShow(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->containerHid = 0;
if (!b->userHid) {
for (i = 0; i < b->len; i++)
uiControlContainerShow(b->controls[i].c);
if (b->osContainer != NULL)
uiOSContainerUpdate(b->osContainer);
}
}
static void boxContainerHide(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->containerHid = 1;
for (i = 0; i < b->len; i++)
uiControlContainerHide(b->controls[i].c);
if (b->osContainer != NULL)
uiOSContainerUpdate(b->osContainer);
}
static void boxEnable(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->userDisabled = 0;
if (!b->containerDisabled)
for (i = 0; i < b->len; i++)
uiControlContainerEnable(b->controls[i].c);
}
static void boxDisable(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->userDisabled = 1;
for (i = 0; i < b->len; i++)
uiControlContainerDisable(b->controls[i].c);
}
static void boxContainerEnable(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->containerDisabled = 0;
if (!b->userDisabled)
for (i = 0; i < b->len; i++)
uiControlContainerEnable(b->controls[i].c);
}
static void boxContainerDisable(uiControl *c)
{
box *b = (box *) c;
uintmax_t i;
b->containerDisabled = 1;
for (i = 0; i < b->len; i++)
uiControlContainerDisable(b->controls[i].c);
}
#define boxCapGrow 32 #define boxCapGrow 32
static void boxAppend(uiBox *ss, uiControl *c, int stretchy) static void boxAppend(uiBox *ss, uiControl *c, int stretchy)
@ -330,9 +217,9 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy)
b->controls[b->len].c = c; b->controls[b->len].c = c;
b->controls[b->len].stretchy = stretchy; b->controls[b->len].stretchy = stretchy;
b->len++; // must be here for OS container updates to work b->len++; // must be here for OS container updates to work
if (b->osContainer != NULL) { if (b->parent != NULL) {
uiControlSetOSContainer(b->controls[b->len - 1].c, b->osContainer); uiControlSetParent(b->controls[b->len - 1].c, b->parent);
uiOSContainerUpdate(b->osContainer); uiContainerUpdate(b->parent);
} }
} }
@ -348,10 +235,9 @@ static void boxDelete(uiBox *ss, uintmax_t index)
b->controls[i] = b->controls[i + 1]; b->controls[i] = b->controls[i + 1];
// TODO memset the last one to NULL // TODO memset the last one to NULL
b->len--; b->len--;
uiControlSetHasParent(removed, 0); if (b->parent != NULL) {
if (b->osContainer != NULL) { uiControlSetParent(removed, NULL);
uiControlSetOSContainer(removed, NULL); uiContainerUpdate(b->parent);
uiOSContainerUpdate(b->osContainer);
} }
} }
@ -367,8 +253,8 @@ static void boxSetPadded(uiBox *ss, int padded)
box *b = (box *) ss; box *b = (box *) ss;
b->padded = padded; b->padded = padded;
if (b->osContainer != NULL) if (b->parent != NULL)
uiOSContainerUpdate(b->osContainer); uiContainerUpdate(b->parent);
} }
uiBox *uiNewHorizontalBox(void) uiBox *uiNewHorizontalBox(void)
@ -377,21 +263,15 @@ uiBox *uiNewHorizontalBox(void)
b = uiNew(box); b = uiNew(box);
uiMakeContainer(uiContainer(b));
b->baseDestroy = uiControl(b)->Destroy;
uiControl(b)->Destroy = boxDestroy; uiControl(b)->Destroy = boxDestroy;
uiControl(b)->Handle = boxHandle; b->baseSetParent = uiControl(b)->SetParent;
uiControl(b)->SetHasParent = boxSetHasParent; uiControl(b)->SetParent = boxSetParent;
uiControl(b)->SetOSContainer = boxSetOSContainer;
uiControl(b)->PreferredSize = boxPreferredSize; uiControl(b)->PreferredSize = boxPreferredSize;
b->baseResize = uiControl(b)->Resize;
uiControl(b)->Resize = boxResize; uiControl(b)->Resize = boxResize;
uiControl(b)->Visible = boxVisible;
uiControl(b)->Show = boxShow;
uiControl(b)->Hide = boxHide;
uiControl(b)->ContainerShow = boxContainerShow;
uiControl(b)->ContainerHide = boxContainerHide;
uiControl(b)->Enable = boxEnable;
uiControl(b)->Disable = boxDisable;
uiControl(b)->ContainerEnable = boxContainerEnable;
uiControl(b)->ContainerDisable = boxContainerDisable;
uiBox(b)->Append = boxAppend; uiBox(b)->Append = boxAppend;
uiBox(b)->Delete = boxDelete; uiBox(b)->Delete = boxDelete;
@ -403,11 +283,11 @@ uiBox *uiNewHorizontalBox(void)
uiBox *uiNewVerticalBox(void) uiBox *uiNewVerticalBox(void)
{ {
uiBox *ss; uiBox *bb;
box *b; box *b;
ss = uiNewHorizontalBox(); bb = uiNewHorizontalBox();
b = (box *) ss; b = (box *) bb;
b->vertical = 1; b->vertical = 1;
return ss; return ss;
} }

View File

@ -46,8 +46,7 @@ interface Control {
field Internal *void; // for use by ui only field Internal *void; // for use by ui only
func Destroy(void); func Destroy(void);
func Handle(void) uintptr_t; func Handle(void) uintptr_t;
func SetHasParent(hasParent int); func SetParent(c *Container);
func SetOSContainer(c *OSContainer);
func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t); func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t);
func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing); func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing);
func Visible(void) int; func Visible(void) int;
@ -61,15 +60,10 @@ interface Control {
func ContainerDisable(void); func ContainerDisable(void);
}; };
interface OSContainer { interface Container from Control {
field Internal *void; func Update(voiid);
func Destroy(void);
func Handle(void) uintptr_t;
func SetMainControl(c *Control);
func SetMargins(left intmax_t, top intmax_t, right intmax_t, bottom intmax_t);
func Update(void);
}; };
func NewOSContainer(osParent uintptr_t) *OSContainer; func MakeContainer(c *Container);
interface Window { interface Window {
func Destroy(void); func Destroy(void);
@ -93,7 +87,7 @@ interface Button from Control {
}; };
func NewButton(text *const char) *Button; func NewButton(text *const char) *Button;
interface Box from Control { interface Box from Container {
func Append(c *Control, stretchy int); func Append(c *Control, stretchy int);
func Delete(index uintmax_t); func Delete(index uintmax_t);
func Padded(void) int; func Padded(void) int;