|
| 1 | +using SadConsole.Input; |
| 2 | +using SadConsole.UI.Controls; |
| 3 | + |
| 4 | +namespace SadConsole.Examples; |
| 5 | + |
| 6 | +internal class DemoControlsScrollbarTests : IDemo |
| 7 | +{ |
| 8 | + public string Title => "Controls (Scrollbar)"; |
| 9 | + |
| 10 | + public string Description => "Test area"; |
| 11 | + |
| 12 | + public string CodeFile => "DemoControlsScrollbarTests.cs"; |
| 13 | + |
| 14 | + public IScreenSurface CreateDemoScreen() => |
| 15 | + new ControlsTest3(); |
| 16 | + |
| 17 | + public override string ToString() => |
| 18 | + Title; |
| 19 | +} |
| 20 | + |
| 21 | +class ControlsTest3 : SadConsole.UI.ControlsConsole |
| 22 | +{ |
| 23 | + public ControlsTest3() : base(GameSettings.ScreenDemoBounds.Width, GameSettings.ScreenDemoBounds.Height) |
| 24 | + { |
| 25 | + Controls.ThemeColors = GameSettings.ControlColorScheme; |
| 26 | + |
| 27 | + CreateBox((1, 1), 10, 10); |
| 28 | + CreateBox((3, 3), 5, 10); |
| 29 | + CreateBox((6, 5), 10, 5); |
| 30 | + |
| 31 | + CreateBox2((20, 1), 10, 1); |
| 32 | + CreateBox2((22, 3), 10, 2); |
| 33 | + CreateBox2((24, 5), 10, 5); |
| 34 | + CreateBox2((26, 7), 10, 10); |
| 35 | + CreateBox2((28, 9), 10, 15); |
| 36 | + CreateBox2((30, 11), 10, 7); |
| 37 | + CreateBox2((32, 13), 2, 7); |
| 38 | + CreateBox2((34, 15), 3, 7); |
| 39 | + CreateBox2((36, 17), 4, 7); |
| 40 | + CreateBox2((38, 19), 5, 7); |
| 41 | + |
| 42 | + CreateBox3((54, 2), 10, 1); |
| 43 | + CreateBox3((54, 5), 10, 2); |
| 44 | + CreateBox3((54, 8), 10, 5); |
| 45 | + CreateBox3((54, 11), 10, 10); |
| 46 | + CreateBox3((54, 14), 10, 15); |
| 47 | + CreateBox3((54, 17), 10, 7); |
| 48 | + CreateBox3((54, 20), 2, 7); |
| 49 | + CreateBox3((54, 23), 3, 1); |
| 50 | + CreateBox3((65, 2), 4, 1); |
| 51 | + CreateBox3((65, 5), 5, 1); |
| 52 | + CreateBox3((65, 8), 6, 1); |
| 53 | + } |
| 54 | + |
| 55 | + private (ScrollBar bar, Label label) CreateBox3(Point position, int height, int max) |
| 56 | + { |
| 57 | + ScrollBar bar1 = new(Orientation.Horizontal, height); |
| 58 | + Label label1 = new(10); |
| 59 | + bar1.Position = position; |
| 60 | + bar1.MaximumValue = max; |
| 61 | + bar1.ArrowsMoveGrip = true; |
| 62 | + bar1.Tag = label1; |
| 63 | + label1.PlaceRelativeTo(bar1, Direction.Types.Up, 0); |
| 64 | + label1.DisplayText = "Label"; |
| 65 | + |
| 66 | + bar1.ValueChanged += Bar2_ValueChanged; |
| 67 | + |
| 68 | + Controls.Add(bar1); |
| 69 | + Controls.Add(label1); |
| 70 | + |
| 71 | + Bar2_ValueChanged(bar1, EventArgs.Empty); |
| 72 | + |
| 73 | + return (bar1, label1); |
| 74 | + } |
| 75 | + |
| 76 | + private (ScrollBar bar, Label label) CreateBox2(Point position, int height, int max) |
| 77 | + { |
| 78 | + ScrollBar bar1 = new(Orientation.Vertical, height); |
| 79 | + Label label1 = new(10); |
| 80 | + bar1.Position = position; |
| 81 | + bar1.MaximumValue = max; |
| 82 | + bar1.MouseWheelMovesGrip = true; |
| 83 | + bar1.Tag = label1; |
| 84 | + label1.PlaceRelativeTo(bar1, Direction.Types.Right); |
| 85 | + label1.DisplayText = "Label"; |
| 86 | + |
| 87 | + bar1.ValueChanged += Bar2_ValueChanged; |
| 88 | + |
| 89 | + Controls.Add(bar1); |
| 90 | + Controls.Add(label1); |
| 91 | + |
| 92 | + Bar2_ValueChanged(bar1, EventArgs.Empty); |
| 93 | + |
| 94 | + return (bar1, label1); |
| 95 | + } |
| 96 | + |
| 97 | + private (ScrollBar bar, Label label) CreateBox(Point position, int height, int max) |
| 98 | + { |
| 99 | + ScrollBar bar1 = new(Orientation.Vertical, height); |
| 100 | + Label label1 = new(10); |
| 101 | + bar1.Position = position; |
| 102 | + bar1.MaximumValue = max; |
| 103 | + bar1.Tag = label1; |
| 104 | + label1.PlaceRelativeTo(bar1, Direction.Types.Right); |
| 105 | + label1.DisplayText = "Label"; |
| 106 | + |
| 107 | + bar1.ValueChanged += Bar1_ValueChanged; |
| 108 | + |
| 109 | + Controls.Add(bar1); |
| 110 | + Controls.Add(label1); |
| 111 | + |
| 112 | + Bar1_ValueChanged(bar1, EventArgs.Empty); |
| 113 | + |
| 114 | + return (bar1, label1); |
| 115 | + } |
| 116 | + |
| 117 | + private void Bar1_ValueChanged(object? sender, EventArgs e) |
| 118 | + { |
| 119 | + ScrollBar control = (ScrollBar)sender!; |
| 120 | + ((Label)control.Tag!).DisplayText = $"{control.Value}/{control.MaximumValue} {control.Style.GripStart}"; |
| 121 | + } |
| 122 | + |
| 123 | + private void Bar2_ValueChanged(object? sender, EventArgs e) |
| 124 | + { |
| 125 | + ScrollBar control = (ScrollBar)sender!; |
| 126 | + ((Label)control.Tag!).DisplayText = $"{control.Value}/{control.MaximumValue} {control.Style.GripStart}"; |
| 127 | + } |
| 128 | + |
| 129 | + public override bool ProcessMouse(MouseScreenObjectState state) |
| 130 | + { |
| 131 | + return base.ProcessMouse(state); |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
0 commit comments