More uiRadioButtons work. Fixed most of the sizing issues.

This commit is contained in:
Pietro Gagliardi 2015-08-22 17:21:27 -04:00
parent bcf7916336
commit 9216013e55
1 changed files with 14 additions and 2 deletions

View File

@ -19,9 +19,21 @@ static NSButtonCell *cellAt(uiRadioButtons *r, uintmax_t n)
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
{
[r->matrix addRow];
intmax_t prevSelection;
// renewRows:columns: will reset the selection
prevSelection = [r->matrix selectedRow];
[r->matrix renewRows:([r->matrix numberOfRows] + 1) columns:1];
[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
// TODO sometimes this isn't enough
[r->matrix sizeToCells];
// and renew the previous selection
// we need to turn on allowing empty selection for this to work properly on the initial state
// TODO this doesn't actually work
[r->matrix setAllowsEmptySelection:YES];
[r->matrix selectCellAtRow:prevSelection column:0];
[r->matrix setAllowsEmptySelection:NO];
uiDarwinControlTriggerRelayout(uiDarwinControl(r));
}
@ -44,7 +56,7 @@ uiRadioButtons *uiNewRadioButtons(void)
prototype:cell
numberOfRows:0
numberOfColumns:0];
// even with this property, none of the radio buttons will be selected initially, which is what we want
// we manually twiddle this property to allow programmatic non-selection state
[r->matrix setAllowsEmptySelection:NO];
[r->matrix setSelectionByRect:YES];
[r->matrix setIntercellSpacing:NSMakeSize(4, 2)];