Skip to content

Commit 1a0dab4

Browse files
committed
OkLAB test in uitest
I can just add whatever random shit I want in there, nobody will stop me
1 parent dff5b5f commit 1a0dab4

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

Robust.Client/Console/Commands/UITestCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public UITestControl()
158158
_tabContainer.AddChild(_sprite);
159159
_tabContainer.AddChild(TabCursorShapes());
160160
_tabContainer.AddChild(new TabWrapContainer { Name = nameof(Tab.WrapContainer) });
161+
_tabContainer.AddChild(new TabOkLab());
161162
}
162163

163164
public void OnClosed()
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
using System.Collections.Generic;
2+
using System.Numerics;
3+
using System.Text;
4+
using Robust.Client.Graphics;
5+
using Robust.Client.UserInterface;
6+
using Robust.Client.UserInterface.Controls;
7+
using Robust.Shared.Maths;
8+
9+
namespace Robust.Client.Console.Commands;
10+
11+
internal sealed partial class UITestControl
12+
{
13+
private sealed class TabOkLab : Control
14+
{
15+
public TabOkLab()
16+
{
17+
string[] colors = ["#d52800", "#fd9954", "#ffffff", "#d261a3", "#a30061"];
18+
19+
var controls = new List<ColorControl>();
20+
var box = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Horizontal };
21+
22+
foreach (var c in colors)
23+
{
24+
var control = new ColorControl(c);
25+
controls.Add(control);
26+
box.AddChild(control);
27+
}
28+
29+
var slider = new Slider
30+
{
31+
MaxValue = 1,
32+
Value = 0.85f,
33+
};
34+
35+
var slider2 = new Slider
36+
{
37+
MaxValue = 1,
38+
Value = 1,
39+
};
40+
41+
slider.OnValueChanged += _ => UpdateValue();
42+
slider2.OnValueChanged += _ => UpdateValue();
43+
UpdateValue();
44+
45+
AddChild(new BoxContainer
46+
{
47+
Orientation = BoxContainer.LayoutOrientation.Vertical,
48+
Children =
49+
{
50+
slider,
51+
slider2,
52+
box
53+
}
54+
});
55+
56+
return;
57+
58+
void UpdateValue()
59+
{
60+
foreach (var control in controls)
61+
{
62+
var sb = new StringBuilder();
63+
64+
var origLab = Color.ToLab(Color.FromSrgb(control.OrigColor));
65+
66+
sb.AppendLine($"ORIG:\n{control.OrigColor.ToHex()}");
67+
sb.AppendLine($"LAB:\n{origLab}");
68+
69+
var lch = Color.ToLch(origLab);
70+
sb.AppendLine($"LCH:\n{lch}");
71+
72+
lch = Color.ToLch(origLab);
73+
lch.X *= slider.Value;
74+
lch.Y *= slider2.Value;
75+
76+
var newLab = Color.FromLch(lch);
77+
78+
var newColor = Color.ToSrgb(Color.FromLab(newLab));
79+
80+
sb.AppendLine($"NEW:\n{newColor.ToHex()}");
81+
sb.AppendLine($"LAB:\n{newLab}");
82+
sb.AppendLine($"LCH:\n{lch}");
83+
84+
control.DataLabel.Text = sb.ToString();
85+
86+
var newLab2 = Vector4.Lerp(new Vector4(0, 0, 0, 1), origLab, slider.Value);
87+
88+
control.PanelModifiedLightnessNaive.BackgroundColor = newColor;
89+
control.PanelModifiedScaleAll.BackgroundColor = Color.ToSrgb(Color.FromLab(newLab2));
90+
}
91+
}
92+
}
93+
94+
private sealed class ColorControl : Control
95+
{
96+
public readonly StyleBoxFlat PanelModifiedLightnessNaive = new();
97+
public readonly StyleBoxFlat PanelModifiedScaleAll = new();
98+
public readonly Label DataLabel = new();
99+
public readonly Color OrigColor;
100+
101+
public ColorControl(string color)
102+
{
103+
HorizontalExpand = true;
104+
105+
OrigColor = Color.FromHex(color);
106+
107+
var panelSize = new Vector2(200, 200);
108+
109+
AddChild(new BoxContainer
110+
{
111+
Orientation = BoxContainer.LayoutOrientation.Vertical,
112+
Children =
113+
{
114+
new AspectRatioPanel
115+
{
116+
Children =
117+
{
118+
new PanelContainer
119+
{
120+
PanelOverride = new StyleBoxFlat(OrigColor),
121+
MinSize = panelSize
122+
},
123+
}
124+
},
125+
DataLabel,
126+
new AspectRatioPanel
127+
{
128+
Children =
129+
{
130+
new PanelContainer
131+
{
132+
PanelOverride = PanelModifiedLightnessNaive,
133+
MinSize = panelSize
134+
},
135+
}
136+
},
137+
new AspectRatioPanel
138+
{
139+
Children =
140+
{
141+
new PanelContainer
142+
{
143+
PanelOverride = PanelModifiedScaleAll,
144+
MinSize = panelSize
145+
},
146+
}
147+
},
148+
}
149+
});
150+
}
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)