Set up a system by which a control can trigger the relayout of its parents. Not quite perfect yet.

This commit is contained in:
Pietro Gagliardi 2015-08-17 19:11:35 -04:00
parent b9b8ab7552
commit 77a293b699
5 changed files with 35 additions and 0 deletions

View File

@ -35,6 +35,13 @@ uintptr_t uiControlHandle(uiControl *c)
return (*(c->Handle))(c);
}
uiControl *uiControlParent(uiControl *c)
{
struct controlBase *cb = controlBase(c);
return cb->parent;
}
static void controlUpdateState(uiControl *);
void uiControlSetParent(uiControl *c, uiControl *parent)

View File

@ -190,6 +190,13 @@ static void relayout(uiBox *b)
[metrics release];
[views release];
uiDarwinControlRelayoutParent(uiControl(b));
}
static void boxRelayout(uiDarwinControl *c)
{
relayout(uiBox(c));
}
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
@ -274,6 +281,7 @@ static uiBox *finishNewBox(BOOL vertical)
setHuggingPri(b->noStretchyView, NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical);
uiDarwinFinishNewControl(b, uiBox);
uiDarwinControl(b)->Relayout = boxRelayout;
return b;
}

View File

@ -10,6 +10,16 @@ uintmax_t uiDarwinControlType(void)
return type_uiDarwinControl;
}
void uiDarwinControlRelayoutParent(uiDarwinControl *c)
{
uiControl *p;
p = uiControlParent(uiControl(c));
if (p == NULL)
return;
(*(uiDarwinControl(p)->Relayout))(p);
}
void osCommitShow(uiControl *c)
{
NSView *view;

View File

@ -61,6 +61,7 @@ _UI_EXTERN uintmax_t uiControlType(void);
#define uiControl(this) ((uiControl *) uiIsA((this), uiControlType(), 1))
_UI_EXTERN void uiControlDestroy(uiControl *);
_UI_EXTERN uintptr_t uiControlHandle(uiControl *);
_UI_EXTERN uiControl *uiControlParent(uiControl *);
_UI_EXTERN void uiControlSetParent(uiControl *, uiControl *);
_UI_EXTERN void uiControlShow(uiControl *);
_UI_EXTERN void uiControlHide(uiControl *);

View File

@ -10,8 +10,12 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
typedef struct uiDarwinControl uiDarwinControl;
struct uiDarwinControl {
uiControl c;
void (*Relayout)(uiControl *);
};
_UI_EXTERN uintmax_t uiDarwinControlType(void);
#define uiDarwinControl(this) ((uiDarwinControl *) uiIsA((this), uiDarwinControlType(), 1))
// TODO document
_UI_EXTERN void uiDarwinControlRelayoutParent(uiDarwinControl *);
// TODO document
#define uiDarwinDefineControlWithOnDestroy(type, typefn, handlefield, onDestroy) \
@ -35,6 +39,10 @@ _UI_EXTERN uintmax_t uiDarwinControlType(void);
static void _ ## type ## ContainerUpdateState(uiControl *c) \
{ \
/* do nothing */ \
} \
static void _ ## type ## Relayout(uiControl *c) \
{ \
uiDarwinControlRelayoutParent(uiDarwinControl(c)); \
}
#define uiDarwinDefineControl(type, typefn, handlefield) \
@ -44,6 +52,7 @@ _UI_EXTERN uintmax_t uiDarwinControlType(void);
uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \
uiControl(variable)->Handle = _ ## type ## Handle; \
uiControl(variable)->ContainerUpdateState = _ ## type ## ContainerUpdateState; \
uiDarwinControl(variable)->Relayout = _ ## type ## Relayout; \
uiDarwinFinishControl(uiControl(variable));
// This is a function used to set up a control.