using Annulus; using Azimuth; namespace Glass.Testbed { /// /// 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); public RadioButtonTestCase(string name) : base(name) { } /// /// 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 { UncheckedMaterial = UiPacksheetMaterials.RadioButtonUnchecked, CheckedMaterial = UiPacksheetMaterials.RadioButtonChecked, Bounds = rowSlot, Checked = index == preCheckedIndex, DebugName = $"{label} radio button", }; Panel fieldLabel = Widgets.FieldText(label) .BuildControl(Constraints.Tight(radioButton.CanvasRect.Size), out TextOverflow? truncation); fieldLabel.DebugName = $"{label} label"; radioButton.CanvasChildren.Add(fieldLabel); if (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 = Widgets.ButtonLabel("Clear second group") .BuildControl(Constraints.Unbounded) .WrapIn(UiPacksheetMaterials.Button); clearButton.DebugName = "clear second group button"; clearButton.OnClick += delegate (in MouseState _, MouseButtonFlags __) { units.Clear(); }; clearButton.Bounds = Rect.FromPositionAndSize( ContentAggregator.NewRow(clearButton.Bounds.Height).TopLeft, clearButton.Bounds.Size); Add(clearButton); } } }