Some more work, edging us ever-closer to the correct solution...
This commit is contained in:
parent
60c988100a
commit
28c9efa972
39
darwin/box.m
39
darwin/box.m
|
@ -249,16 +249,14 @@ struct uiBox {
|
|||
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
||||
{
|
||||
boxChild *bc;
|
||||
NSView *childView;
|
||||
NSLayoutPriority priority;
|
||||
uintmax_t oldnStretchy;
|
||||
|
||||
bc = [boxChild new];
|
||||
bc.c = c;
|
||||
bc.stretchy = stretchy;
|
||||
childView = [bc view];
|
||||
bc.oldPrimaryHuggingPri = [childView contentHuggingPriorityForOrientation:self->primaryOrientation];
|
||||
bc.oldSecondaryHuggingPri = [childView contentHuggingPriorityForOrientation:self->secondaryOrientation];
|
||||
bc.oldPrimaryHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(bc.c), self->primaryOrientation);
|
||||
bc.oldSecondaryHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(bc.c), self->secondaryOrientation);
|
||||
|
||||
uiControlSetParent(bc.c, uiControl(self->b));
|
||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self);
|
||||
|
@ -271,9 +269,9 @@ struct uiBox {
|
|||
else
|
||||
// TODO will default high work?
|
||||
priority = NSLayoutPriorityRequired;
|
||||
[childView setContentHuggingPriority:priority forOrientation:self->primaryOrientation];
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), priority, self->primaryOrientation);
|
||||
// make sure controls don't hug their secondary direction so they fill the width of the view
|
||||
[childView setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:self->secondaryOrientation];
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
||||
|
||||
[self->children addObject:bc];
|
||||
|
||||
|
@ -281,14 +279,8 @@ struct uiBox {
|
|||
if (bc.stretchy) {
|
||||
oldnStretchy = self->nStretchy;
|
||||
self->nStretchy++;
|
||||
if (oldnStretchy == 0) {
|
||||
// TODO isolate into its own function?
|
||||
uiControl *parent;
|
||||
|
||||
parent = uiControlParent(uiControl(self->b));
|
||||
if (parent != NULL)
|
||||
uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent));
|
||||
}
|
||||
if (oldnStretchy == 0)
|
||||
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b));
|
||||
}
|
||||
|
||||
[bc release]; // we don't need the initial reference now
|
||||
|
@ -297,33 +289,25 @@ struct uiBox {
|
|||
- (void)delete:(uintmax_t)n
|
||||
{
|
||||
boxChild *bc;
|
||||
NSView *removedView;
|
||||
int stretchy;
|
||||
|
||||
// TODO separate into a method?
|
||||
bc = (boxChild *) [self->children objectAtIndex:n];
|
||||
removedView = [bc view];
|
||||
stretchy = bc.stretchy;
|
||||
|
||||
uiControlSetParent(bc.c, NULL);
|
||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
||||
|
||||
[removedView setContentHuggingPriority:bc.oldPrimaryHuggingPri forOrientation:self->primaryOrientation];
|
||||
[removedView setContentHuggingPriority:bc.oldSecondaryHuggingPri forOrientation:self->secondaryOrientation];
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), bc.oldPrimaryHuggingPri, self->primaryOrientation);
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), bc.oldSecondaryHuggingPri, self->secondaryOrientation);
|
||||
|
||||
[self->children removeObjectAtIndex:n];
|
||||
|
||||
[self establishOurConstraints];
|
||||
if (stretchy) {
|
||||
self->nStretchy--;
|
||||
if (self->nStretchy == 0) {
|
||||
// TODO isolate into its own function?
|
||||
uiControl *parent;
|
||||
|
||||
parent = uiControlParent(uiControl(self->b));
|
||||
if (parent != NULL)
|
||||
uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent));
|
||||
}
|
||||
if (self->nStretchy == 0)
|
||||
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,6 +396,9 @@ static void uiBoxChildEdgeHuggingChanged(uiDarwinControl *c)
|
|||
[b->view establishOurConstraints];
|
||||
}
|
||||
|
||||
uiDarwinControlDefaultHuggingPriority(uiBox, view)
|
||||
uiDarwinControlDefaultSetHuggingPriority(uiBox, view)
|
||||
|
||||
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
|
||||
{
|
||||
[b->view append:c stretchy:stretchy];
|
||||
|
|
|
@ -26,6 +26,16 @@ void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *c)
|
|||
(*(c->ChildEdgeHuggingChanged))(c);
|
||||
}
|
||||
|
||||
NSLayoutPriority uiDarwinControlHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation)
|
||||
{
|
||||
return (*(c->HuggingPriority))(c, orientation);
|
||||
}
|
||||
|
||||
void uiDarwinControlSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
||||
{
|
||||
(*(c->SetHuggingPriority))(c, priority, orientation);
|
||||
}
|
||||
|
||||
void uiDarwinSetControlFont(NSControl *c, NSControlSize size)
|
||||
{
|
||||
[c setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
|
||||
|
@ -49,3 +59,12 @@ BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *c, BOOL enabled)
|
|||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
void uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl *c)
|
||||
{
|
||||
uiControl *parent;
|
||||
|
||||
parent = uiControlParent(uiControl(c));
|
||||
if (parent != NULL)
|
||||
uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent));
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ struct uiGroup {
|
|||
uiControl *child;
|
||||
int margined;
|
||||
struct singleChildConstraints constraints;
|
||||
NSLayoutPriority horzHuggingPri;
|
||||
NSLayoutPriority vertHuggingPri;
|
||||
};
|
||||
|
||||
static void removeConstraints(uiGroup *g)
|
||||
|
@ -69,8 +71,21 @@ static void groupRelayout(uiGroup *g)
|
|||
@"uiGroup");
|
||||
}
|
||||
|
||||
uiDarwinControlDefaultHugsTrailingEdge(uiGroup, box)
|
||||
uiDarwinControlDefaultHugsBottom(uiGroup, box)
|
||||
// TODO rename these since I'm starting to get confused by what they mean by hugging
|
||||
BOOL uiGroupHugsTrailingEdge(uiDarwinControl *c)
|
||||
{
|
||||
uiGroup *g = uiGroup(c);
|
||||
|
||||
// TODO make a function?
|
||||
return g->horzHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
||||
}
|
||||
|
||||
BOOL uiGroupHugsBottom(uiDarwinControl *c)
|
||||
{
|
||||
uiGroup *g = uiGroup(c);
|
||||
|
||||
return g->vertHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
||||
}
|
||||
|
||||
static void uiGroupChildEdgeHuggingChanged(uiDarwinControl *c)
|
||||
{
|
||||
|
@ -79,6 +94,26 @@ static void uiGroupChildEdgeHuggingChanged(uiDarwinControl *c)
|
|||
groupRelayout(g);
|
||||
}
|
||||
|
||||
static NSLayoutPriority uiGroupHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation)
|
||||
{
|
||||
uiGroup *g = uiGroup(c);
|
||||
|
||||
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
||||
return g->horzHuggingPri;
|
||||
return g->vertHuggingPri;
|
||||
}
|
||||
|
||||
static void uiGroupSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
||||
{
|
||||
uiGroup *g = uiGroup(c);
|
||||
|
||||
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
||||
g->horzHuggingPri = priority;
|
||||
else
|
||||
g->vertHuggingPri = priority;
|
||||
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(g));
|
||||
}
|
||||
|
||||
char *uiGroupTitle(uiGroup *g)
|
||||
{
|
||||
return uiDarwinNSStringToText([g->box title]);
|
||||
|
@ -138,5 +173,9 @@ uiGroup *uiNewGroup(const char *title)
|
|||
// we can't use uiDarwinSetControlFont() because the selector is different
|
||||
[g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
||||
|
||||
// default to low hugging to not hug edges
|
||||
g->horzHuggingPri = NSLayoutPriorityDefaultLow;
|
||||
g->vertHuggingPri = NSLayoutPriorityDefaultLow;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
|
42
darwin/tab.m
42
darwin/tab.m
|
@ -20,6 +20,8 @@ struct uiTab {
|
|||
uiDarwinControl c;
|
||||
NSTabView *tabview;
|
||||
NSMutableArray *pages;
|
||||
NSLayoutPriority horzHuggingPri;
|
||||
NSLayoutPriority vertHuggingPri;
|
||||
};
|
||||
|
||||
@implementation tabPage
|
||||
|
@ -124,8 +126,20 @@ static void tabRelayout(uiTab *t)
|
|||
[page establishChildConstraints];
|
||||
}
|
||||
|
||||
uiDarwinControlDefaultHugsTrailingEdge(uiTab, tabview)
|
||||
uiDarwinControlDefaultHugsBottom(uiTab, tabview)
|
||||
BOOL uiTabHugsTrailingEdge(uiDarwinControl *c)
|
||||
{
|
||||
uiTab *t = uiTab(c);
|
||||
|
||||
// TODO make a function?
|
||||
return t->horzHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
||||
}
|
||||
|
||||
BOOL uiTabHugsBottom(uiDarwinControl *c)
|
||||
{
|
||||
uiTab *t = uiTab(c);
|
||||
|
||||
return t->vertHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
||||
}
|
||||
|
||||
static void uiTabChildEdgeHuggingChanged(uiDarwinControl *c)
|
||||
{
|
||||
|
@ -134,6 +148,26 @@ static void uiTabChildEdgeHuggingChanged(uiDarwinControl *c)
|
|||
tabRelayout(t);
|
||||
}
|
||||
|
||||
static NSLayoutPriority uiTabHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation)
|
||||
{
|
||||
uiTab *t = uiTab(c);
|
||||
|
||||
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
||||
return t->horzHuggingPri;
|
||||
return t->vertHuggingPri;
|
||||
}
|
||||
|
||||
static void uiTabSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
||||
{
|
||||
uiTab *t = uiTab(c);
|
||||
|
||||
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
||||
t->horzHuggingPri = priority;
|
||||
else
|
||||
t->vertHuggingPri = priority;
|
||||
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(t));
|
||||
}
|
||||
|
||||
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
|
||||
{
|
||||
uiTabInsertAt(t, name, [t->pages count], child);
|
||||
|
@ -225,5 +259,9 @@ uiTab *uiNewTab(void)
|
|||
|
||||
t->pages = [NSMutableArray new];
|
||||
|
||||
// default to low hugging to not hug edges
|
||||
t->horzHuggingPri = NSLayoutPriorityDefaultLow;
|
||||
t->vertHuggingPri = NSLayoutPriorityDefaultLow;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
|
|
@ -177,6 +177,11 @@ static void uiWindowChildEdgeHuggingChanged(uiDarwinControl *c)
|
|||
windowRelayout(w);
|
||||
}
|
||||
|
||||
// TODO
|
||||
uiDarwinControlDefaultHuggingPriority(uiWindow, window)
|
||||
uiDarwinControlDefaultSetHuggingPriority(uiWindow, window)
|
||||
// end TODO
|
||||
|
||||
char *uiWindowTitle(uiWindow *w)
|
||||
{
|
||||
return uiDarwinNSStringToText([w->window title]);
|
||||
|
|
23
ui_darwin.h
23
ui_darwin.h
|
@ -22,6 +22,8 @@ struct uiDarwinControl {
|
|||
BOOL (*HugsTrailingEdge)(uiDarwinControl *);
|
||||
BOOL (*HugsBottom)(uiDarwinControl *);
|
||||
void (*ChildEdgeHuggingChanged)(uiDarwinControl *);
|
||||
NSLayoutPriority (*HuggingPriority)(uiDarwinControl *, NSLayoutConstraintOrientation);
|
||||
void (*SetHuggingPriority)(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation);
|
||||
};
|
||||
#define uiDarwinControl(this) ((uiDarwinControl *) (this))
|
||||
// TODO document
|
||||
|
@ -30,6 +32,8 @@ _UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *);
|
|||
_UI_EXTERN BOOL uiDarwinControlHugsTrailingEdge(uiDarwinControl *);
|
||||
_UI_EXTERN BOOL uiDarwinControlHugsBottom(uiDarwinControl *);
|
||||
_UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *);
|
||||
_UI_EXTERN NSLayoutPriority uiDarwinControlHuggingPriority(uiDarwinControl *, NSLayoutConstraintOrientation);
|
||||
_UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation);
|
||||
|
||||
#define uiDarwinControlDefaultDestroy(type, handlefield) \
|
||||
static void type ## Destroy(uiControl *c) \
|
||||
|
@ -125,6 +129,16 @@ _UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *);
|
|||
{ \
|
||||
/* do nothing */ \
|
||||
}
|
||||
#define uiDarwinControlDefaultHuggingPriority(type, handlefield) \
|
||||
static NSLayoutPriority type ## HuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation) \
|
||||
{ \
|
||||
return [type(c)->handlefield contentHuggingPriorityForOrientation:orientation]; \
|
||||
}
|
||||
#define uiDarwinControlDefaultSetHuggingPriority(type, handlefield) \
|
||||
static void type ## SetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation) \
|
||||
{ \
|
||||
[type(c)->handlefield setContentHuggingPriority:priority forOrientation:orientation]; \
|
||||
}
|
||||
|
||||
#define uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) \
|
||||
uiDarwinControlDefaultHandle(type, handlefield) \
|
||||
|
@ -141,7 +155,9 @@ _UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *);
|
|||
uiDarwinControlDefaultSetSuperview(type, handlefield) \
|
||||
uiDarwinControlDefaultHugsTrailingEdge(type, handlefield) \
|
||||
uiDarwinControlDefaultHugsBottom(type, handlefield) \
|
||||
uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield)
|
||||
uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield) \
|
||||
uiDarwinControlDefaultHuggingPriority(type, handlefield) \
|
||||
uiDarwinControlDefaultSetHuggingPriority(type, handlefield)
|
||||
|
||||
#define uiDarwinControlAllDefaults(type, handlefield) \
|
||||
uiDarwinControlDefaultDestroy(type, handlefield) \
|
||||
|
@ -166,6 +182,8 @@ _UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *);
|
|||
uiDarwinControl(var)->HugsTrailingEdge = type ## HugsTrailingEdge; \
|
||||
uiDarwinControl(var)->HugsBottom = type ## HugsBottom; \
|
||||
uiDarwinControl(var)->ChildEdgeHuggingChanged = type ## ChildEdgeHuggingChanged; \
|
||||
uiDarwinControl(var)->HuggingPriority = type ## HuggingPriority; \
|
||||
uiDarwinControl(var)->SetHuggingPriority = type ## SetHuggingPriority; \
|
||||
uiDarwinControl(var)->visible = YES; \
|
||||
uiDarwinControl(var)->enabled = YES;
|
||||
// TODO document
|
||||
|
@ -180,6 +198,9 @@ _UI_EXTERN char *uiDarwinNSStringToText(NSString *);
|
|||
// TODO document
|
||||
_UI_EXTERN BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *, BOOL);
|
||||
|
||||
// TODO document
|
||||
_UI_EXTERN void uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue