1
1
local lwtk = require " lwtk"
2
2
3
+ local lower = string.lower
4
+ local upper = string.upper
3
5
local Color = lwtk .Color
4
6
local get = lwtk .StyleRef .get
5
7
local scale = lwtk .StyleRef .scale
@@ -9,102 +11,115 @@ local DefaultStyle = lwtk.newClass("lwtk.DefaultStyle", Super)
9
11
10
12
function DefaultStyle .override :new (initParams )
11
13
12
- local function par (name )
13
- local rslt = initParams and initParams [name ]
14
- if rslt ~= nil then
15
- initParams [name ] = nil
16
- return rslt
14
+ local function par (name , defaultValue )
15
+ if initParams then
16
+ local rslt = initParams [name ]
17
+ if rslt ~= nil then
18
+ initParams [name ] = nil
19
+ return rslt
20
+ end
21
+ local name2 = lower (name :sub (1 ,1 )).. name :sub (2 )
22
+ rslt = initParams [name2 ]
23
+ if rslt ~= nil then
24
+ initParams [name2 ] = nil
25
+ return rslt
26
+ end
27
+ name2 = upper (name :sub (1 ,1 )).. name :sub (2 )
28
+ rslt = initParams [name2 ]
29
+ if rslt ~= nil then
30
+ initParams [name2 ] = nil
31
+ return rslt
32
+ end
17
33
end
34
+ return defaultValue
18
35
end
19
36
20
- local scaleFactor = par " scaleFactor" or 1
21
- local screenScale = par " screenScale" or 1
22
- local backgroundColor = par " backgroundColor" or Color " f9f9fa"
23
- local textColor = par " textColor" or Color " 000000"
24
- local accentColor = par " accentColor" or Color " 006fc7" -- "0078d7"
25
-
37
+ local function parRule (name , defaultValue )
38
+ return { name , par (name , defaultValue ) }
39
+ end
40
+
26
41
local ruleList = {
27
42
28
- scaleFactor = scaleFactor * screenScale ,
43
+ scaleFactor = par ( " ScaleFactor " , 1 ) * par ( " ScreenScale " , 1 ) ,
29
44
30
- { " *TransitionSeconds" , 0.05 } ,
31
- { " VisibilityTransitionSeconds" , 0.05 } ,
32
- { " VisibilityTransitionSeconds:invisible" , 0.10 } ,
33
- { " FrameTransitionSeconds" , 0.05 } ,
34
- { " HoverTransitionSeconds" , 0.20 } ,
35
- { " PressedTransitionSeconds" , 0.05 } ,
36
- { " SimulateButtonClickSeconds" , 0.10 } ,
45
+ parRule ( " *TransitionSeconds" , 0.05 ) ,
46
+ parRule ( " VisibilityTransitionSeconds" , 0.05 ) ,
47
+ parRule ( " VisibilityTransitionSeconds:invisible" , 0.10 ) ,
48
+ parRule ( " FrameTransitionSeconds" , 0.05 ) ,
49
+ parRule ( " HoverTransitionSeconds" , 0.20 ) ,
50
+ parRule ( " PressedTransitionSeconds" , 0.05 ) ,
51
+ parRule ( " SimulateButtonClickSeconds" , 0.10 ) ,
37
52
38
- { " TextSize" , 12 } ,
39
- { " FontFamily" , " sans-serif" } ,
40
- { " ScrollBarSize" , 12 } ,
53
+ parRule ( " TextSize" , 12 ) ,
54
+ parRule ( " FontFamily" , " sans-serif" ) ,
55
+ parRule ( " ScrollBarSize" , 12 ) ,
41
56
42
- { " BackgroundColor" , backgroundColor } ,
43
- { " TextColor" , textColor } ,
44
- { " AccentColor" , accentColor },
57
+ parRule ( " BackgroundColor" , Color " f9f9fa " ) ,
58
+ parRule ( " TextColor" , Color " 000000 " ) ,
59
+ parRule ( " AccentColor" , Color " 006fc7 " ), -- "0078d7"
45
60
46
- { " TextOffset" , 0 } ,
61
+ parRule ( " TextOffset" , 0 ) ,
47
62
48
- { " CursorColor" , Color " 00000000" } , -- Color"adadad" } ,
49
- { " CursorColor:focused" , Color " 000000" } ,
50
- { " CursorWidth" , 2 } ,
63
+ parRule ( " CursorColor" , Color " 00000000" ) , -- Color"adadad" ) ,
64
+ parRule ( " CursorColor:focused" , Color " 000000" ) ,
65
+ parRule ( " CursorWidth" , 2 ) ,
51
66
52
- { " Margin@Control" , 8 } ,
53
- { " *Margin@Control" , get " Margin" } ,
54
- { " Height@Control" , 24 } ,
55
- { " BorderPadding@Control" , 3 } ,
56
- { " TextFullVisible@Control" , true } ,
67
+ parRule ( " Margin@Control" , 8 ) ,
68
+ parRule ( " *Margin@Control" , get " Margin" ) ,
69
+ parRule ( " Height@Control" , 24 ) ,
70
+ parRule ( " BorderPadding@Control" , 3 ) ,
71
+ parRule ( " TextFullVisible@Control" , true ) ,
57
72
58
- { " BorderSize@Box" , 1 } ,
59
- { " BorderPadding@Box" , 3 } ,
60
- { " BorderColor@Box" , Color " adadad" } ,
73
+ parRule ( " BorderSize@Box" , 1 ) ,
74
+ parRule ( " BorderPadding@Box" , 3 ) ,
75
+ parRule ( " BorderColor@Box" , Color " adadad" ) ,
61
76
62
- { " BorderPadding@TextLabel" , 0 } ,
63
- { " BorderSize@TextLabel" , 0 } ,
64
- { " BorderColor@TextLabel" , nil } ,
77
+ parRule ( " BorderPadding@TextLabel" , 0 ) ,
78
+ parRule ( " BorderSize@TextLabel" , 0 ) ,
79
+ parRule ( " BorderColor@TextLabel" , nil ) ,
65
80
66
- { " Width@PushButton" , 80 } ,
67
- { " BorderSize@PushButton" , 1 } ,
68
- { " BorderSize@PushButton:focused" , 2 } ,
81
+ parRule ( " Width@PushButton" , 80 ) ,
82
+ parRule ( " BorderSize@PushButton" , 1 ) ,
83
+ parRule ( " BorderSize@PushButton:focused" , 2 ) ,
69
84
70
- { " LeftPadding@PushButton" ,
71
- " RightPadding@PushButton" , 10 } ,
72
- { " TextOffset@PushButton:pressed+hover" , 0.3 } ,
85
+ parRule ( " LeftPadding@PushButton" , 10 ) ,
86
+ parRule ( " RightPadding@PushButton" , 10 ) ,
87
+ parRule ( " TextOffset@PushButton:pressed+hover" , 0.3 ) ,
73
88
74
- { " BackgroundColor@PushButton" , Color " e1e1e1" } ,
75
- { " BackgroundColor@PushButton:hover" , Color " c9c9ca" } ,
76
- { " BackgroundColor@PushButton:pressed" , Color " c9c9ca" } ,
77
- { " BackgroundColor@PushButton:pressed+hover" , Color " b1b1b2" } ,
78
- { " BackgroundColor@PushButton:default" , Color " e5f1fb" } ,
79
- { " BackgroundColor@PushButton:default+hover" , Color " d5e1eb" } ,
80
- { " BackgroundColor@PushButton:default+pressed" , Color " c5d1db" } ,
81
- { " BackgroundColor@PushButton:focused" , Color " e5f1fb" } ,
82
- { " BackgroundColor@PushButton:focused+hover" , Color " d5e1eb" } ,
83
- { " BackgroundColor@PushButton:focused+pressed" , Color " c5d1db" } ,
89
+ parRule ( " BackgroundColor@PushButton" , Color " e1e1e1" ) ,
90
+ parRule ( " BackgroundColor@PushButton:hover" , Color " c9c9ca" ) ,
91
+ parRule ( " BackgroundColor@PushButton:pressed" , Color " c9c9ca" ) ,
92
+ parRule ( " BackgroundColor@PushButton:pressed+hover" , Color " b1b1b2" ) ,
93
+ parRule ( " BackgroundColor@PushButton:default" , Color " e5f1fb" ) ,
94
+ parRule ( " BackgroundColor@PushButton:default+hover" , Color " d5e1eb" ) ,
95
+ parRule ( " BackgroundColor@PushButton:default+pressed" , Color " c5d1db" ) ,
96
+ parRule ( " BackgroundColor@PushButton:focused" , Color " e5f1fb" ) ,
97
+ parRule ( " BackgroundColor@PushButton:focused+hover" , Color " d5e1eb" ) ,
98
+ parRule ( " BackgroundColor@PushButton:focused+pressed" , Color " c5d1db" ) ,
84
99
85
- { " TextColor@PushButton:disabled" , Color " adadad" } ,
100
+ parRule ( " TextColor@PushButton:disabled" , Color " adadad" ) ,
86
101
87
- { " BorderColor@PushButton" , Color " adadad" } ,
88
- { " BorderColor@PushButton:focused" , get " AccentColor" } ,
89
- { " BorderColor@PushButton:default" , get " AccentColor" } ,
102
+ parRule ( " BorderColor@PushButton" , Color " adadad" ) ,
103
+ parRule ( " BorderColor@PushButton:focused" , get " AccentColor" ) ,
104
+ parRule ( " BorderColor@PushButton:default" , get " AccentColor" ) ,
90
105
91
- { " MinColumns@TextInput" , 10 } ,
92
- { " Columns@TextInput" , 20 } ,
93
- { " MaxColumns@TextInput" , - 1 } ,
94
- { " BorderColor@TextInput" , Color " adadad" } ,
95
- { " BorderColor@TextInput:focused" , get " AccentColor" } ,
96
- { " BorderSize@TextInput" , 1 } ,
97
- { " BorderSize@TextInput:focused" , 2 } ,
98
- { " FontFamily@TextInput" , " monospace" } ,
99
- { " TextFullVisible@TextInput" , false } ,
106
+ parRule ( " MinColumns@TextInput" , 10 ) ,
107
+ parRule ( " Columns@TextInput" , 20 ) ,
108
+ parRule ( " MaxColumns@TextInput" , - 1 ) ,
109
+ parRule ( " BorderColor@TextInput" , Color " adadad" ) ,
110
+ parRule ( " BorderColor@TextInput:focused" , get " AccentColor" ) ,
111
+ parRule ( " BorderSize@TextInput" , 1 ) ,
112
+ parRule ( " BorderSize@TextInput:focused" , 2 ) ,
113
+ parRule ( " FontFamily@TextInput" , " monospace" ) ,
114
+ parRule ( " TextFullVisible@TextInput" , false ) ,
100
115
101
- { " TextSize@TitleText" , scale (2 , get " TextSize" )} ,
116
+ parRule ( " TextSize@TitleText" , scale (2 , get " TextSize" )) ,
102
117
103
- { " BorderColor@FocusGroup" , Color " adadad" } ,
104
- { " BorderColor@FocusGroup:focused" , get " AccentColor" } ,
105
- { " BorderSize@FocusGroup" , 1 } ,
106
- { " BorderSize@FocusGroup:focused" , 2 } ,
107
- { " BorderSize@FocusGroup:focused+entered" , 1 } ,
118
+ parRule ( " BorderColor@FocusGroup" , Color " adadad" ) ,
119
+ parRule ( " BorderColor@FocusGroup:focused" , get " AccentColor" ) ,
120
+ parRule ( " BorderSize@FocusGroup" , 1 ) ,
121
+ parRule ( " BorderSize@FocusGroup:focused" , 2 ) ,
122
+ parRule ( " BorderSize@FocusGroup:focused+entered" , 1 ) ,
108
123
}
109
124
110
125
Super .new (self , ruleList )
0 commit comments