DId most of the uiRadioButtons implementation. Not quite working yet... both the radio button part of the button don't show up and the relayout after append isn't actually growing the window size.

This commit is contained in:
Pietro Gagliardi 2015-08-22 15:12:48 -04:00
parent 7a3406f4a1
commit 2d9022ab13
1 changed files with 22 additions and 5 deletions

View File

@ -3,18 +3,25 @@
struct uiRadioButtons {
uiDarwinControl c;
NSTextField *dummy;
NSMatrix *matrix;
};
uiDarwinDefineControl(
uiRadioButtons, // type name
uiRadioButtonsType, // type function
dummy // handle
matrix // handle
)
static NSButtonCell *cellAt(uiRadioButtons *r, uintmax_t n)
{
return (NSButtonCell *) [r->matrix cellAtRow:n column:0];
}
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
{
// TODO
[r->matrix addRow];
[cellAt(r, [r->matrix numberOfRows] - 1) setTitle:toNSString(text)];
// this will definitely cause a resize in at least the vertical direction, even if not in the horizontal
uiDarwinControlTriggerRelayout(uiDarwinControl(r));
}
@ -24,8 +31,18 @@ uiRadioButtons *uiNewRadioButtons(void)
r = (uiRadioButtons *) uiNewControl(uiRadioButtonsType());
r->dummy = [[NSTextField alloc] initWithFrame:NSZeroRect];
[r->dummy setStringValue:@"TODO uiRadioButtons not implemented"];
r->matrix = [[NSMatrix alloc] initWithFrame:NSZeroRect];
[r->matrix setMode:NSRadioModeMatrix];
// TODO should we allow an initial state of no selection, but not allow the user to select nothing?
[r->matrix setAllowsEmptySelection:NO];
[r->matrix setIntercellSpacing:NSMakeSize(4, 2)];
[r->matrix setAutorecalculatesCellSize:YES];
[r->matrix setDrawsBackground:NO];
[r->matrix setDrawsCellBackground:NO];
[r->matrix setAutosizesCells:YES];
[[r->matrix prototype] setButtonType:NSRadioButton];
// works on NSCells too (same selector)
uiDarwinSetControlFont((NSControl *) [r->matrix prototype], NSRegularControlSize);
uiDarwinFinishNewControl(r, uiRadioButtons);