Migrated uiGroup. Before we do uiTab, I want to refactor it a bit like we have with uiBox...
This commit is contained in:
parent
178c0301c2
commit
7d874ee911
|
@ -3,42 +3,24 @@
|
||||||
|
|
||||||
// TODO test empty groups
|
// TODO test empty groups
|
||||||
|
|
||||||
// if there is an intrinsic content size on the NSBox, Auto Layout won't bother checking the box's children and force the box to be the intrinsic size if its hugging priority is Required; we don't want that
|
|
||||||
// TODO don't truncate the label?
|
|
||||||
@interface libuiIntrinsicBox : NSBox {
|
|
||||||
BOOL libui_hasChild;
|
|
||||||
}
|
|
||||||
- (void)libui_setHasChild:(BOOL)h;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation libuiIntrinsicBox
|
|
||||||
|
|
||||||
- (void)libui_setHasChild:(BOOL)h
|
|
||||||
{
|
|
||||||
self->libui_hasChild = h;
|
|
||||||
[self invalidateIntrinsicContentSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSSize)intrinsicContentSize
|
|
||||||
{
|
|
||||||
if (!self->libui_hasChild)
|
|
||||||
return [super intrinsicContentSize];
|
|
||||||
return NSMakeSize(NSViewNoIntrinsicMetric, NSViewNoIntrinsicMetric);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
struct uiGroup {
|
struct uiGroup {
|
||||||
uiDarwinControl c;
|
uiDarwinControl c;
|
||||||
libuiIntrinsicBox *box;
|
libuiIntrinsicBox *box;
|
||||||
uiControl *child;
|
uiControl *child;
|
||||||
int margined;
|
int margined;
|
||||||
|
struct singleChildConstraints constraints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void removeConstraints(uiGroup *g)
|
||||||
|
{
|
||||||
|
singleChildConstraintsRemove(&(g->constraints), g->box);
|
||||||
|
}
|
||||||
|
|
||||||
static void uiGroupDestroy(uiControl *c)
|
static void uiGroupDestroy(uiControl *c)
|
||||||
{
|
{
|
||||||
uiGroup *g = uiGroup(c);
|
uiGroup *g = uiGroup(c);
|
||||||
|
|
||||||
|
removeConstraints(g);
|
||||||
if (g->child != NULL) {
|
if (g->child != NULL) {
|
||||||
uiControlSetParent(g->child, NULL);
|
uiControlSetParent(g->child, NULL);
|
||||||
uiControlDestroy(g->child);
|
uiControlDestroy(g->child);
|
||||||
|
@ -72,18 +54,28 @@ uiDarwinControlDefaultSetSuperview(uiGroup, box)
|
||||||
|
|
||||||
static void groupRelayout(uiGroup *g)
|
static void groupRelayout(uiGroup *g)
|
||||||
{
|
{
|
||||||
uiDarwinControl *cc;
|
|
||||||
NSView *childView;
|
NSView *childView;
|
||||||
|
|
||||||
|
removeConstraints(g);
|
||||||
if (g->child == NULL)
|
if (g->child == NULL)
|
||||||
return;
|
return;
|
||||||
cc = uiDarwinControl(g->child);
|
|
||||||
childView = (NSView *) uiControlHandle(g->child);
|
childView = (NSView *) uiControlHandle(g->child);
|
||||||
// first relayout the child
|
singleChildConstraintsEstablish(&(g->constraints),
|
||||||
//TODO (*(cc->Relayout))(cc);
|
g->box, childView,
|
||||||
//TODO layoutSingleView([g->box contentView], childView, g->margined, @"uiGroup");
|
uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)),
|
||||||
// we need to explicitly tell the NSBox to recompute its own size based on the new content layout
|
uiDarwinControlHugsBottom(uiDarwinControl(g->child)),
|
||||||
[g->box sizeToFit];
|
g->margined,
|
||||||
|
@"uiGroup");
|
||||||
|
}
|
||||||
|
|
||||||
|
uiDarwinControlDefaultHugsTrailingEdge(uiGroup, box)
|
||||||
|
uiDarwinControlDefaultHugsBottom(uiGroup, box)
|
||||||
|
|
||||||
|
static void uiWindowChildEdgeHuggingChanged(uiDarwinControl *c)
|
||||||
|
{
|
||||||
|
uiGroup *g = uiGroup(c);
|
||||||
|
|
||||||
|
groupRelayout(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiGroupTitle(uiGroup *g)
|
char *uiGroupTitle(uiGroup *g)
|
||||||
|
@ -103,6 +95,7 @@ void uiGroupSetChild(uiGroup *g, uiControl *child)
|
||||||
NSView *childView;
|
NSView *childView;
|
||||||
|
|
||||||
if (g->child != NULL) {
|
if (g->child != NULL) {
|
||||||
|
removeConstraints(g);
|
||||||
childView = (NSView *) uiControlHandle(g->child);
|
childView = (NSView *) uiControlHandle(g->child);
|
||||||
[childView removeFromSuperview];
|
[childView removeFromSuperview];
|
||||||
uiControlSetParent(g->child, NULL);
|
uiControlSetParent(g->child, NULL);
|
||||||
|
@ -126,7 +119,8 @@ int uiGroupMargined(uiGroup *g)
|
||||||
void uiGroupSetMargined(uiGroup *g, int margined)
|
void uiGroupSetMargined(uiGroup *g, int margined)
|
||||||
{
|
{
|
||||||
g->margined = margined;
|
g->margined = margined;
|
||||||
groupRelayout(g);
|
singleChildConstraintsSetMargined(&(w->constraints), w->margined);
|
||||||
|
// TODO issue a relayout command?
|
||||||
}
|
}
|
||||||
|
|
||||||
uiGroup *uiNewGroup(const char *title)
|
uiGroup *uiNewGroup(const char *title)
|
||||||
|
|
|
@ -8,7 +8,6 @@ struct uiWindow {
|
||||||
int margined;
|
int margined;
|
||||||
int (*onClosing)(uiWindow *, void *);
|
int (*onClosing)(uiWindow *, void *);
|
||||||
void *onClosingData;
|
void *onClosingData;
|
||||||
|
|
||||||
struct singleChildConstraints constraints;
|
struct singleChildConstraints constraints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue