diff --git a/redo/reredo/darwin/radiobuttons.m b/redo/reredo/darwin/radiobuttons.m index 2d3a1330..8f879f36 100644 --- a/redo/reredo/darwin/radiobuttons.m +++ b/redo/reredo/darwin/radiobuttons.m @@ -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);