More uiRadioButtons work. Moved the sizeToCells call into Relayout, thinking it would fix a bug with adding a certain number of cells. It does not, but this is more correct anyway.
This commit is contained in:
parent
f6d10e4194
commit
5a6d96c20c
|
@ -1,6 +1,8 @@
|
||||||
// 14 august 2015
|
// 14 august 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
// TODO should the selection be lost when starting a new drag?
|
||||||
|
|
||||||
struct uiRadioButtons {
|
struct uiRadioButtons {
|
||||||
uiDarwinControl c;
|
uiDarwinControl c;
|
||||||
NSMatrix *matrix;
|
NSMatrix *matrix;
|
||||||
|
@ -17,23 +19,34 @@ static NSButtonCell *cellAt(uiRadioButtons *r, uintmax_t n)
|
||||||
return (NSButtonCell *) [r->matrix cellAtRow:n column:0];
|
return (NSButtonCell *) [r->matrix cellAtRow:n column:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void radioButtonsRelayout(uiDarwinControl *c)
|
||||||
|
{
|
||||||
|
uiRadioButtons *r = uiRadioButtons(c);
|
||||||
|
|
||||||
|
[r->matrix sizeToCells];
|
||||||
|
}
|
||||||
|
|
||||||
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
||||||
{
|
{
|
||||||
intmax_t prevSelection;
|
intmax_t prevSelection;
|
||||||
|
|
||||||
// renewRows:columns: will reset the selection
|
// renewRows:columns: will reset the selection
|
||||||
prevSelection = [r->matrix selectedRow];
|
prevSelection = [r->matrix selectedRow];
|
||||||
|
|
||||||
[r->matrix renewRows:([r->matrix numberOfRows] + 1) columns:1];
|
[r->matrix renewRows:([r->matrix numberOfRows] + 1) columns:1];
|
||||||
[cellAt(r, [r->matrix numberOfRows] - 1) setTitle:toNSString(text)];
|
[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
|
// this will definitely cause a resize in at least the vertical direction, even if not in the horizontal
|
||||||
// TODO sometimes this isn't enough
|
// we do that when relaying out below
|
||||||
[r->matrix sizeToCells];
|
// TODO sometimes it doesn't work right
|
||||||
|
|
||||||
// and renew the previous selection
|
// and renew the previous selection
|
||||||
// we need to turn on allowing empty selection for this to work properly on the initial state
|
// we need to turn on allowing empty selection for this to work properly on the initial state
|
||||||
// TODO this doesn't actually work
|
// TODO this doesn't actually work
|
||||||
[r->matrix setAllowsEmptySelection:YES];
|
[r->matrix setAllowsEmptySelection:YES];
|
||||||
[r->matrix selectCellAtRow:prevSelection column:0];
|
[r->matrix selectCellAtRow:prevSelection column:0];
|
||||||
[r->matrix setAllowsEmptySelection:NO];
|
[r->matrix setAllowsEmptySelection:NO];
|
||||||
|
|
||||||
uiDarwinControlTriggerRelayout(uiDarwinControl(r));
|
uiDarwinControlTriggerRelayout(uiDarwinControl(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +79,7 @@ uiRadioButtons *uiNewRadioButtons(void)
|
||||||
[r->matrix setAutosizesCells:YES];
|
[r->matrix setAutosizesCells:YES];
|
||||||
|
|
||||||
uiDarwinFinishNewControl(r, uiRadioButtons);
|
uiDarwinFinishNewControl(r, uiRadioButtons);
|
||||||
|
uiDarwinControl(r)->Relayout = radioButtonsRelayout;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue