using Annulus; using Azimuth; using System.Globalization; namespace Glass.Testbed.TestCases.Controls { /// /// Sliders over whole numbers, tenths and a stepped range, each with a readout, plus a vertical one and a disabled /// one. Drag a thumb, click the track to page, or tab to a slider for the arrow, page, Home and End keys. /// public class SliderTestCase : TestCase { private static readonly Vector HorizontalSize = new Vector(240, 24); private static readonly Vector VerticalSize = new Vector(24, 160); private static readonly Vector ReadoutSize = new Vector(80, 24); private static readonly TextMaterialStyle ReadoutStyle = Widgets.SmallCaptionStyle with { VerticalAlignment = Alignment.Vertical.Center, }; private Slider AddSlider(string debugName, NumberGrid grid, decimal value, Rect bounds, Orientation orientation = Orientation.Horizontal) { var slider = new Slider { DebugName = debugName, Orientation = orientation, SliderMaterial = orientation == Orientation.Horizontal ? UiPacksheetMaterials.HorizontalSlider : UiPacksheetMaterials.VerticalSlider, Grid = grid, Value = value, Bounds = bounds, }; Add(slider); return slider; } private void AddReadout(Slider slider, Rect bounds) { var readout = new Label(ReadoutStyle, "") { DebugName = slider.DebugName + " value", Bounds = bounds }; Add(readout); slider.OnValueChanged += value => readout.Text = value.ToString(CultureInfo.InvariantCulture); readout.Text = slider.Value.ToString(CultureInfo.InvariantCulture); } private void AddHorizontalRow(string debugName, NumberGrid grid, decimal value) { Rect row = ContentAggregator.NewRow(HorizontalSize.Y); Slider slider = AddSlider(debugName, grid, value, row.NewCol(HorizontalSize.X, margin: Gutter)); AddReadout(slider, row.NewCol(ReadoutSize.X)); } protected override void Populate() { AddCaption("Whole numbers, 0 to 100, a page click moves 10"); AddHorizontalRow("whole", new NumberGrid { Max = 100, CoarseStep = 10 }, 40); AddCaption("Tenths, 0 to 1"); AddHorizontalRow("tenths", new NumberGrid { Max = 1, Resolution = 0.1m }, 0.5m); AddCaption("Every 25 from 0 to 100, so the thumb snaps while it drags"); AddHorizontalRow("stepped", new NumberGrid { Max = 100, Resolution = 25 }, 50); AddCaption("Disabled"); Rect disabledRow = ContentAggregator.NewRow(HorizontalSize.Y); Slider disabled = AddSlider("disabled", new NumberGrid { Max = 100 }, 30, disabledRow.NewCol(HorizontalSize.X, margin: Gutter)); AddReadout(disabled, disabledRow.NewCol(ReadoutSize.X)); disabled.Enabled = false; AddCaption("Vertical, 0 to 10"); Rect verticalRow = ContentAggregator.NewRow(VerticalSize.Y); Slider vertical = AddSlider("vertical", new NumberGrid { Max = 10, CoarseStep = 5 }, 5, verticalRow.NewCol(VerticalSize.X, margin: Gutter), Orientation.Vertical); AddReadout(vertical, verticalRow.NewCol(ReadoutSize.X)); } } }