1
1
-- Graphical User Interface functions
2
2
3
3
if (gui == nil) then
4
- -- The following values are the default. They can be overridden by the "style:values.xml" file.
4
+ -- The following values are the default 'light' theme . They can be overridden by the "style:values.xml" file.
5
5
gui = {
6
+ theme = 'light',
6
7
dpi = 160,
7
8
fonts = {
8
9
-- Use percentages for scalable sizes, where 100% is equivalent to the value of gui.interface.fontSize
9
- default = { face='Noto Sans,Source Sans 3 ', size='100%' },
10
- window = { face='Noto Sans,Source Sans 3 ', size='100%' }, -- For text that is not inside a widget
11
- button = { face='Noto Sans,Source Sans 3 ', size='100%' }, -- Text inside buttons
12
- icon = { face='Noto Sans,Source Sans 3 ', size='100%' }, -- Text at the bottom of icons
13
- menu = { face='Noto Sans,Source Sans 3 ', size='100%' }, -- Menu item text
10
+ default = { face='Noto Sans,Source Sans Pro ', size='100%' },
11
+ window = { face='Noto Sans,Source Sans Pro ', size='100%' }, -- For text that is not inside a widget
12
+ button = { face='Noto Sans,Source Sans Pro ', size='100%' }, -- Text inside buttons
13
+ icon = { face='Noto Sans,Source Sans Pro ', size='100%' }, -- Text at the bottom of icons
14
+ menu = { face='Noto Sans,Source Sans Pro ', size='100%' }, -- Menu item text
14
15
titlebar = { face='Noto Sans', size='100%' }, -- Window titlebar text
15
16
small = { face='Tiny', size='60%' }, -- Recommended text for small sizes
16
- large = { face='Noto Sans,Source Sans 3 ', size='130%' }, -- Recommended text for headers
17
- widget = { face='Noto Sans,Source Sans 3 ', size='100%' }, -- Text inside widgets (e.g. combobox)
18
- label = { face='Noto Sans,Source Sans 3 ::bold', size='100%' } -- Text for labels and outside widgets
17
+ large = { face='Noto Sans,Source Sans Pro ', size='130%' }, -- Recommended text for headers
18
+ widget = { face='Noto Sans,Source Sans Pro ', size='100%' }, -- Text inside widgets (e.g. combobox)
19
+ label = { face='Noto Sans,Source Sans Pro ::bold', size='100%' } -- Text for labels and outside widgets
19
20
},
20
- colours = {
21
+ style = {
21
22
-- These are all fills, so any SVG compliant fill value can potentially be used to define a 'colour'.
22
- widgetText = 'rgb(255,255,255)',
23
- widgetBkgd = 'rgb(0,0,0,100)',
24
- widgetStroke = 'rgb(255,255,255,60)',
25
- widgetStrokeFocus = 'rgb(255,255,255,160)',
26
- widgetStrokeDisabled = 'rgb(255,255,255,60)',
27
- shadow = 'rgb(0,0,0,100)', -- Base colour/alpha value for stroked shadows
28
- highlight = 'rgb(255,255,255,150)', -- Base colour/alpha value for stroked highlights
29
- button = 'rgb(230,230,230)', -- Button background (raised)
30
- buttonClick = 'rgb(200,200,200)', -- Button background when clicked (depressed)
31
- menubar = 'rgb(190,190,190)', -- Menubar background fill
32
- menu = 'rgb(240,240,240)', -- Menu background fill
33
- border = 'rgb(144,144,144)', -- Standard border for any area filled with 'background'
34
- borderFocus = 'rgb(160,160,160)', -- Colour to use when 'border' has the user's focus
35
- menuborder = 'rgb(200,200,200)', -- Menu border
36
- desktop = 'rgb(160,160,160)', -- Background colour for the desktop
37
- recess = 'rgb(160,160,160)', -- Background colour for recessed areas with no content.
38
- background = 'rgb(255,255,255)', -- Standard background for hosting text & paper-based layouts
39
- textHighlight = 'rgb(224,224,240)', -- Background fill for text that is highlighted
40
- window = 'rgb(220,220,220)', -- Background fill for windows
41
- windowText = 'rgb(0,0,0)' -- Colour for text that is drawn directly to the window
23
+ widget = {
24
+ text = 'rgb(255,255,255)',
25
+ bkgd = 'rgb(0,0,0,100)',
26
+ stroke = 'rgb(255,255,255,60)',
27
+ strokeFocus = 'rgb(255,255,255,160)',
28
+ strokeDisabled = 'rgb(255,255,255,60)',
29
+ strokeWidth = 2,
30
+ width = 160, -- Default width for common widgets (px)
31
+ gap = 6, -- Recommended gap between widgets (px)
32
+ margin = 6 -- Recommended internal margin for widgets (px)
33
+ },
34
+ button = {
35
+ bkgd = 'rgb(230,230,230)', -- Background when raised / default
36
+ bkgdActive = 'rgb(200,200,200)' -- Background when temporarily clicked (depressed)
37
+ },
38
+ page = {
39
+ bkgd = 'rgb(255,255,255)', -- Background for hosting text & paper-based layouts
40
+ border = 'rgb(144,144,144)', -- Border stroke for any area surrounding 'bkgd'
41
+ borderFocus = 'rgb(160,160,160)', -- Stroke to use when 'border' has the user's focus
42
+ text = 'rgb(0,0,0)', -- Default colour for text drawn over 'bkgd'
43
+ textHighlight = 'rgb(0,0,0)', -- Colour for 'text' when temporarily highlighted
44
+ textHighlightBkgd = 'rgb(224,224,240)' -- Background fill for 'text' that is highlighted
45
+ },
46
+ window = {
47
+ bkgd = 'rgb(220,220,220)',
48
+ text = 'rgb(0,0,0)' -- Colour for text that is drawn directly to the window
49
+ },
50
+ menubar = {
51
+ bkgd = 'rgb(190,190,190)'
52
+ },
53
+ menu = {
54
+ bkgd = 'rgb(240,240,240)',
55
+ border = 'rgb(200,200,200)' -- Stroke for menu border
56
+ },
57
+ desktop = {
58
+ bkgd = 'rgb(160,160,160)'
59
+ },
60
+ recess = 'rgb(160,160,160)', -- Fill for recessed areas with no content.
61
+ strokeShadow = 'rgb(0,0,0,100)', -- Base colour/alpha value for stroked shadows
62
+ strokeHighlight = 'rgb(255,255,255,150)' -- Base colour/alpha value for stroked highlights
42
63
},
43
64
interface = {
44
- inputBorder = 1, -- Stroke size for borders that receive keyboard input
45
- outputBorder = 1, -- Stroke size for borders containing immutable content
46
- widgetMargin = 5, -- Recommended internal margin for widgets (px)
47
- widgetGap = 6, -- Recommended gap between widgets (px)
48
- fontSize = 11, -- Default font-size for everything (pt)
49
- sliderSize = 16, -- Max size for slider widgets (px)
50
- scrollSize = 18, -- Max size for scroll widgets (px)
51
- scrollOpacity = 100, -- Opacity for scrollbar background fills
52
- iconTheme = 'Default',
53
- iconSize = 20 -- Recommended default size for icons (px) and should be linked to fontSize
65
+ fontSize = 11, -- Default font-size for everything (pt)
66
+ iconTheme = 'Default',
67
+ iconSize = 20 -- Recommended default size for icons (px) and should be linked to fontSize
54
68
},
55
69
iconThemes = {
56
70
default = { first={ r=90,g=90,b=90 }, last={ r=70,g=70,b=110 } },
@@ -67,7 +81,10 @@ if (gui == nil) then
67
81
grey = { first={ r=100,g=100,b=100 }, last={ r=70,g=70,b=70 } },
68
82
pearl = { first={ r=250,g=249,b=248 }, last={ r=210,g=211,b=212 } }
69
83
},
70
- _counter = 0
84
+ _counter = 0,
85
+ configureScene = function(Window, Scene)
86
+ -- A custom configure function can be defined that adds definitions to the window scene, e.g. images and patterns for fills.
87
+ end
71
88
}
72
89
73
90
function convertFontSizes() -- Convert font percentage sizes to their px size
@@ -92,14 +109,15 @@ if (gui == nil) then
92
109
local xml = obj.new('xml', { path=path })
93
110
94
111
if (xml != nil) then
112
+ --[[
95
113
local err, index = xml.mtFindTag('/colours')
96
114
if (err == ERR_Okay) then
97
- for k,v in pairs(gui.colours ) do
115
+ for k,v in pairs(gui.style ) do
98
116
err, colour = xml.mtGetAttrib(index, k)
99
- if (err == ERR_Okay) then gui.colours [k] = colour end
117
+ if (err == ERR_Okay) then gui.style [k] = colour end
100
118
end
101
119
end
102
-
120
+ --]]
103
121
local err, index = xml.mtFindTag('/interface')
104
122
if (err == ERR_Okay) then
105
123
for k,v in pairs(gui.interface) do
@@ -170,11 +188,11 @@ gui.pixel = function(val)
170
188
return num
171
189
elseif (alpha == 'in') then
172
190
return gui.dpi * num
173
- elseif (alpha == 'mm') then // 25.4 units per inch
191
+ elseif (alpha == 'mm') then -- 25.4 units per inch
174
192
return gui.dpi * (num / 25.4)
175
- elseif (alpha == 'pt') then // 72 units per inch
193
+ elseif (alpha == 'pt') then -- 72 units per inch
176
194
return gui.dpi * (num / 72)
177
- elseif (alpha == 'dp') then // 160dpi relative value
195
+ elseif (alpha == 'dp') then -- 160dpi relative value
178
196
return num * (gui.dpi * 0.00625)
179
197
end
180
198
end
188
206
-- Convert an RGB string to an RGB table.
189
207
190
208
gui.strToRGB = function(Value)
209
+ if not Value then
210
+ error('Empty value passed to strToRGB()\n' .. debug.traceback())
211
+ end
212
+
191
213
if (string.byte(Value) == 35) then
192
214
local colour = tonumber(Value)
193
215
if (Value:len() == 7) then
262
284
-- Convert HSV table to RGB
263
285
264
286
gui.hsvToRGB = function(Value)
287
+ if not Value then
288
+ error('Empty value passed to hsvToRGB()\n' .. debug.traceback())
289
+ end
290
+
265
291
local h = Value.h / 60
266
292
local s = Value.s
267
293
local v = Value.v
302
328
-- Convert RGB table to HSV
303
329
304
330
gui.rgbToHSV = function(Value)
331
+ if not Value then
332
+ error('Empty value passed to rgbToHSV()\n' .. debug.traceback())
333
+ end
334
+
305
335
local max = gui.rgbValue(Value)
306
336
local hsv = { v = max }
307
337
if max > 0 then
361
391
-- Generate a simple gradient fill for vectors.
362
392
363
393
gui.simpleGradient = function(Scene, Name, Colours, X1, Y1, X2, Y2, Units, IgnoreClashes)
364
- if not Name then error('A name for the gradient is required.') end
394
+ if not Name then
395
+ error('A name for the gradient is required.\n' .. debug.traceback())
396
+ end
365
397
366
398
local stops = { }
367
399
local i = 0
0 commit comments