using Annulus; using Azimuth; using Clave; namespace Glass.Testbed.TestCases.Controls { /// /// Two independent columns wired up with RadioGroup.FromChildrenOf, plus a button that clears one of them. /// public class RadioButtonTestCase : TestCase { private static readonly Vector LabeledRowSize = new Vector(220, 36); /// /// Lays out one RadioButton per label in a column, then hands the column to RadioGroup.FromChildrenOf so /// this group and any sibling column stay independent of each other. /// private RadioGroup AddRadioGroupColumn(string caption, string[] labels, int? preCheckedIndex = null) { AddCaption(caption); var column = NewChild(); column.Material = Material.Invisible; var rows = new RectAggregator( Rect.FromPositionAndSize(Vector.Zero, new Vector(LabeledRowSize.X, 0)), new Vector(0, Gutter)); for (int index = 0; index < labels.Length; ++index) { string label = labels[index]; Rect rowSlot = rows.NewRow(LabeledRowSize.Y); var radioButton = new RadioButton(ButtonBehavior.Default) { UncheckedMaterial = UiPacksheetMaterials.RadioButtonUnchecked, CheckedMaterial = UiPacksheetMaterials.RadioButtonChecked, Bounds = rowSlot, Checked = index == preCheckedIndex, DebugName = $"{label} radio button", }; var fieldLabel = new Label(Widgets.FieldTextStyle, label, Constraints.Tight(radioButton.CanvasRect.Size)); fieldLabel.DebugName = $"{label} label"; radioButton.CanvasChildren.Add(fieldLabel); if (fieldLabel.Truncation != null) { radioButton.Tooltip = Widgets.Tooltip(label); } column.CanvasChildren.Add(radioButton); } column.Bounds = Rect.FromPositionAndSize( ContentAggregator.NewRow(rows.Rect.Height).TopLeft, rows.Rect.Size); return RadioGroup.FromChildrenOf(column); } protected override void Populate() { AddRadioGroupColumn("First group — one option starts pre-checked", new[] { "Small", "Medium", "Large" }, preCheckedIndex: 0); RadioGroup units = AddRadioGroupColumn( "Second group — independent of the first, nothing selected by default", new[] { "Metric", "Imperial" }); AddCaption("Clearing a group returns it to no selection"); Button clearButton = new Label(Widgets.ButtonLabelStyle, "Clear second group", Constraints.Unbounded) .WrapIn(UiPacksheetMaterials.Button, ButtonBehavior.Default); clearButton.DebugName = "clear second group button"; clearButton.OnActivate += delegate (ButtonBase _, in KeyboardSnapshot __, KeyboardManager ___) { units.Clear(); }; clearButton.Bounds = Rect.FromPositionAndSize( ContentAggregator.NewRow(clearButton.Bounds.Height).TopLeft, clearButton.Bounds.Size); Add(clearButton); } } }