From 2d9022ab13409d6266a724e75b3df695523e6af5 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 22 Aug 2015 15:12:48 -0400 Subject: [PATCH] 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. --- redo/reredo/darwin/radiobuttons.m | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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);