77using ConstraintSDK . ConstraintArithmetic ;
88
99namespace ConstraintSDK . Controls {
10+ public struct Color {
11+ public float Red ;
12+ public float Green ;
13+ public float Blue ;
14+ public float Alpha ;
15+
16+ public Color ( float red , float green , float blue , float alpha ) {
17+ Red = red ;
18+ Green = green ;
19+ Blue = blue ;
20+ Alpha = alpha ;
21+ }
22+
23+ public int Pack ( ) {
24+ return ( int ) ( Red * 0xFF ) | ( int ) ( Green * 0xFF ) << 8 | ( int ) ( Blue * 0xFF ) << 16 | ( int ) ( Alpha * 0xFF ) << 24 ;
25+ }
26+ }
27+
1028 public class Label {
29+ public class Style {
30+ public Color TextColor ;
31+
32+ public Style ( Color textColor ) {
33+ TextColor = textColor ;
34+ }
35+ }
36+
1137 public ArithmeticVariable Left ;
1238 public ArithmeticVariable Top ;
1339
@@ -25,6 +51,8 @@ public class Label {
2551 public string FontFamily ;
2652 public float FontSize ;
2753
54+ public Style CurrentStyle ;
55+
2856 public UIntPtr Control = UIntPtr . Zero ;
2957
3058 public Label ( LayoutContext context , string text , string fontFamily , float fontSize ) {
@@ -36,11 +64,29 @@ public Label(LayoutContext context, string text, string fontFamily, float fontSi
3664 FontFamily = fontFamily ;
3765 FontSize = fontSize ;
3866
67+ CurrentStyle = context . DefaultLabelStyle ;
68+
3969 context . Labels . Add ( this ) ;
4070 }
4171 }
4272
4373 public class Button {
74+ public class Style {
75+ public Color TextColor ;
76+
77+ public Color BackgroundColor ;
78+
79+ public float BorderSize ;
80+ public Color BorderColor ;
81+
82+ public Style ( Color textColor , Color backgroundColor , float borderSize , Color borderColor ) {
83+ TextColor = textColor ;
84+ BackgroundColor = backgroundColor ;
85+ BorderSize = borderSize ;
86+ BorderColor = borderColor ;
87+ }
88+ }
89+
4490 public ArithmeticVariable Left ;
4591 public ArithmeticVariable Top ;
4692
@@ -58,6 +104,8 @@ public class Button {
58104 public string FontFamily ;
59105 public float FontSize ;
60106
107+ public Style CurrentStyle ;
108+
61109 public event Action Press = null ;
62110
63111 public UIntPtr Control = UIntPtr . Zero ;
@@ -74,6 +122,8 @@ public Button(LayoutContext context, string text, string fontFamily, float fontS
74122 FontFamily = fontFamily ;
75123 FontSize = fontSize ;
76124
125+ CurrentStyle = context . DefaultButtonStyle ;
126+
77127 context . Buttons . Add ( this ) ;
78128 }
79129
@@ -85,6 +135,22 @@ public void OnPress() {
85135 }
86136
87137 public class TextInput {
138+ public class Style {
139+ public Color TextColor ;
140+
141+ public Color BackgroundColor ;
142+
143+ public float BorderSize ;
144+ public Color BorderColor ;
145+
146+ public Style ( Color textColor , Color backgroundColor , float borderSize , Color borderColor ) {
147+ TextColor = textColor ;
148+ BackgroundColor = backgroundColor ;
149+ BorderSize = borderSize ;
150+ BorderColor = borderColor ;
151+ }
152+ }
153+
88154 public ArithmeticVariable Left ;
89155 public ArithmeticVariable Top ;
90156
@@ -102,6 +168,8 @@ public class TextInput {
102168 public string FontFamily ;
103169 public float FontSize ;
104170
171+ public Style CurrentStyle ;
172+
105173 public event Action < string > Change = null ;
106174
107175 public UIntPtr Control = UIntPtr . Zero ;
@@ -118,6 +186,8 @@ public TextInput(LayoutContext context, string text, string fontFamily, float fo
118186 FontFamily = fontFamily ;
119187 FontSize = fontSize ;
120188
189+ CurrentStyle = context . DefaultTextInputStyle ;
190+
121191 context . TextInputs . Add ( this ) ;
122192 }
123193
@@ -145,10 +215,30 @@ public class LayoutContext {
145215 public List < Button > Buttons = new List < Button > ( ) ;
146216 public List < TextInput > TextInputs = new List < TextInput > ( ) ;
147217
218+ public Color BackgroundColor = new Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
219+
220+ public Label . Style DefaultLabelStyle = new Label . Style (
221+ new Color ( 0.0f , 0.0f , 0.0f , 1.0f )
222+ ) ;
223+
224+ public Button . Style DefaultButtonStyle = new Button . Style (
225+ new Color ( 0.0f , 0.0f , 0.0f , 1.0f ) ,
226+ new Color ( 0.9f , 0.9f , 0.9f , 1.0f ) ,
227+ 1.0f ,
228+ new Color ( 0.7f , 0.7f , 0.7f , 1.0f )
229+ ) ;
230+
231+ public TextInput . Style DefaultTextInputStyle = new TextInput . Style (
232+ new Color ( 0.0f , 0.0f , 0.0f , 1.0f ) ,
233+ new Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ,
234+ 1.0f ,
235+ new Color ( 0.7f , 0.7f , 0.7f , 1.0f )
236+ ) ;
237+
148238 public event Action < float , float > FrameResize = null ;
149239
150240 public void PerformLayout ( ) {
151- clear_controls ( ) ;
241+ clear_controls ( BackgroundColor . Pack ( ) ) ;
152242
153243 ArithmeticContext . Solve ( ) ;
154244
@@ -163,7 +253,8 @@ public void PerformLayout() {
163253 ( UIntPtr ) textBytes . Length ,
164254 fontFamilyBytes ,
165255 ( UIntPtr ) fontFamilyBytes . Length ,
166- label . FontSize
256+ label . FontSize ,
257+ label . CurrentStyle . TextColor . Pack ( )
167258 ) ;
168259 }
169260
@@ -180,7 +271,11 @@ public void PerformLayout() {
180271 ( UIntPtr ) textBytes . Length ,
181272 fontFamilyBytes ,
182273 ( UIntPtr ) fontFamilyBytes . Length ,
183- button . FontSize
274+ button . FontSize ,
275+ button . CurrentStyle . TextColor . Pack ( ) ,
276+ button . CurrentStyle . BackgroundColor . Pack ( ) ,
277+ button . CurrentStyle . BorderSize ,
278+ button . CurrentStyle . BorderColor . Pack ( )
184279 ) ;
185280 }
186281
@@ -197,7 +292,11 @@ public void PerformLayout() {
197292 ( UIntPtr ) textBytes . Length ,
198293 fontFamilyBytes ,
199294 ( UIntPtr ) fontFamilyBytes . Length ,
200- textInput . FontSize
295+ textInput . FontSize ,
296+ textInput . CurrentStyle . TextColor . Pack ( ) ,
297+ textInput . CurrentStyle . BackgroundColor . Pack ( ) ,
298+ textInput . CurrentStyle . BorderSize ,
299+ textInput . CurrentStyle . BorderColor . Pack ( )
201300 ) ;
202301 }
203302
0 commit comments