diff --git a/data/styles/default/values.xml b/data/styles/default/values.xml index 7f5a2642a..8fee10c4e 100644 --- a/data/styles/default/values.xml +++ b/data/styles/default/values.xml @@ -7,7 +7,7 @@ and their default settings. - icon = { face='Noto Sans,Source Sans 3', size='100%', colour='255,255,255' }, -- Text at the bottom of icons - menu = { face='Noto Sans,Source Sans 3', size='100%', colour='255,255,255', highlight='255,255,255' }, -- Menu item text - titlebar = { face='Noto Sans', size='100%', colour='255,255,255' }, -- Title bar text (in standalone OS mode) - small = { face='Tiny', size='6' }, -- Recommended text for small sizes --> - large = { face='Noto Sans,Source Sans 3', size='130%' }, -- Recommended text for headers --> - widget = { face='Noto Sans,Source Sans 3', size=11, colour='255,255,255' }, -- Text inside widgets (e.g. combobox) - label = { face='Noto Sans,Source Sans 3:11:bold', size=11, colour='0,0,0' } -- Text for labels and outside widgets + -- Use percentages for scalable sizes, where 100% is equivalent to the value of gui.interface.fontSize + default = { face='Noto Sans,Source Sans 3', size='100%' }, + window = { face='Noto Sans,Source Sans 3', size='100%' }, -- For text that is not inside a widget + button = { face='Noto Sans,Source Sans 3', size='100%' }, -- Text inside buttons + icon = { face='Noto Sans,Source Sans 3', size='100%' }, -- Text at the bottom of icons + menu = { face='Noto Sans,Source Sans 3', size='100%' }, -- Menu item text + titlebar = { face='Noto Sans', size='100%' }, -- Window titlebar text + small = { face='Tiny', size='60%' }, -- Recommended text for small sizes + large = { face='Noto Sans,Source Sans 3', size='130%' }, -- Recommended text for headers + widget = { face='Noto Sans,Source Sans 3', size='100%' }, -- Text inside widgets (e.g. combobox) + label = { face='Noto Sans,Source Sans 3::bold', size='100%' } -- Text for labels and outside widgets }, colours = { -- These are all fills, so any SVG compliant fill value can potentially be used to define a 'colour'. - shadow = 'rgb(0,0,0,100)', - highlight = 'rgb(255,255,255,150)', - colour = 'rgb(220,220,220)', - window = 'rgb(220,220,220)', widgetText = 'rgb(255,255,255)', widgetBkgd = 'rgb(0,0,0,100)', widgetStroke = 'rgb(255,255,255,60)', widgetStrokeFocus = 'rgb(255,255,255,160)', widgetStrokeDisabled = 'rgb(255,255,255,60)', - button = 'rgb(230,230,230)', - buttonclick = 'rgb(200,200,200)', - menubar = 'rgb(190,190,190)', - menu = 'rgb(240,240,240)', - border = '#909090', - menuborder = 'rgb(200,200,200)', - desktop = 'rgb(160,160,160)', - recess = 'rgb(160,160,160)', - background = 'rgb(255,255,255)', - texthighlight = '#e0e0f0', - boxedText = 'rgb(255,255,255)', - windowText = 'rgb(0,0,0)' + shadow = 'rgb(0,0,0,100)', -- Base colour/alpha value for stroked shadows + highlight = 'rgb(255,255,255,150)', -- Base colour/alpha value for stroked highlights + button = 'rgb(230,230,230)', -- Button background (raised) + buttonClick = 'rgb(200,200,200)', -- Button background when clicked (depressed) + menubar = 'rgb(190,190,190)', -- Menubar background fill + menu = 'rgb(240,240,240)', -- Menu background fill + border = 'rgb(144,144,144)', -- Standard border for any area filled with 'background' + borderFocus = 'rgb(160,160,160)', -- Colour to use when 'border' has the user's focus + menuborder = 'rgb(200,200,200)', -- Menu border + desktop = 'rgb(160,160,160)', -- Background colour for the desktop + recess = 'rgb(160,160,160)', -- Background colour for recessed areas with no content. + background = 'rgb(255,255,255)', -- Standard background for hosting text & paper-based layouts + textHighlight = 'rgb(224,224,240)', -- Background fill for text that is highlighted + window = 'rgb(220,220,220)', -- Background fill for windows + windowText = 'rgb(0,0,0)' -- Colour for text that is drawn directly to the window }, interface = { - inputBorder = 1, - outputBorder = 1, - widgetMargin = 5, - widgetGap = 6, - textBorder = 1, - fontSize = 11, - sliderSize = 16, - scrollSize = 18, - scrollOpacity = 100, - iconRatio = '7%', + inputBorder = 1, -- Stroke size for borders that receive keyboard input + outputBorder = 1, -- Stroke size for borders containing immutable content + widgetMargin = 5, -- Recommended internal margin for widgets (px) + widgetGap = 6, -- Recommended gap between widgets (px) + fontSize = 11, -- Default font-size for everything (pt) + sliderSize = 16, -- Max size for slider widgets (px) + scrollSize = 18, -- Max size for scroll widgets (px) + scrollOpacity = 100, -- Opacity for scrollbar background fills iconTheme = 'Default', - iconSize = 0 + iconSize = 20 -- Recommended default size for icons (px) and should be linked to fontSize }, rgb = { }, counter = 0, @@ -79,61 +76,77 @@ if (gui == nil) then return gui.colours[Name] end - do - local path = 'style:values.xml' + function convertFontSizes() -- Convert font percentage sizes to their px size + for k,v in pairs(gui.fonts) do + if gui.fonts[k].size then + if string.match(gui.fonts[k].size, '^%-?%d+%%$') then + pct = tonumber(string.match(gui.fonts[k].size, '^(%-?%d+)%%$')) + gui.fonts[k].size = math.floor(gui.interface.fontSize * (pct / 100)) + end + end + end + end + + local path = 'style:values.xml' + if mSys.AnalysePath(path) != ERR_Okay then + path = 'environment:config/values.xml' if mSys.AnalysePath(path) != ERR_Okay then - path = 'environment:config/values.xml' - if mSys.AnalysePath(path) != ERR_Okay then - path = 'styles:default/values.xml' + path = 'styles:default/values.xml' + end + end + + local xml = obj.new('xml', { path=path }) + + if (xml != nil) then + local err, index = xml.mtFindTag('/colours') + if (err == ERR_Okay) then + for k,v in pairs(gui.colours) do + err, colour = xml.mtGetAttrib(index, k) + if (err == ERR_Okay) then gui.colours[k] = colour end end end - local xml = obj.new('xml', { path=path }) - - if (xml != nil) then - local total = 0 - xml.mtFindTag('/fonts/font', - function(XML, TagIndex, Attrib) - local font = { } - local err, name = xml.mtGetAttrib(TagIndex, 'name') - if nz(name) then - err, font.face = xml.mtGetAttrib(TagIndex, 'face') - if nz(font.face) then - err, font.size = xml.mtGetAttrib(TagIndex, 'size') - err, font.colour = xml.mtGetAttrib(TagIndex, 'colour') - err, font.highlight = xml.mtGetAttrib(TagIndex, 'highlight') - gui.fonts[name] = font - total = total + 1 - end + local err, index = xml.mtFindTag('/interface') + if (err == ERR_Okay) then + for k,v in pairs(gui.interface) do + err, val = xml.mtGetAttrib(index, k) + if (err == ERR_Okay) then + if string.match(val, '^%-?%d+$') then + gui.interface[k] = tonumber(val) + else + gui.interface[k] = val end - end) - - local err, index = xml.mtFindTag('/colours') - if (err == ERR_Okay) then - for k,v in pairs(gui.colours) do - err, colour = xml.mtGetAttrib(index, k) - if (err == ERR_Okay) then gui.colours[k] = colour end end end + end + + convertFontSizes() - local err, index = xml.mtFindTag('/interface') - if (err == ERR_Okay) then - for k,v in pairs(gui.interface) do - err, val = xml.mtGetAttrib(index, k) + local err, index = xml.mtFindTag('/fonts') + if (err == ERR_Okay) then + for k,v in pairs(gui.fonts) do + local err, index = xml.mtFindTag("/fonts/font(@name='" .. k .. "')") + if (err == ERR_Okay) then + local err, face = xml.mtGetAttrib(index, 'face') + if (err == ERR_Okay) then gui.fonts[k].face = face end + local err, size = xml.mtGetAttrib(index, 'size') if (err == ERR_Okay) then - if string.match(val, '^%-?%d+$') then - gui.interface[k] = tonumber(val) + if string.match(size, '^%-?%d+$') then + gui.fonts[k].size = tonumber(size) + elseif string.match(size, '^%-?%d+%%$') then + pct = tonumber(string.match(size, '^(%-?%d+)%%$')) + gui.fonts[k].size = math.floor(gui.interface.fontSize * (pct / 100)) else - gui.interface[k] = val + gui.fonts[k].size = size end end end end - - xml = nil - else - error('Failed to retrieve style information.') end + + xml = nil + else + convertFontSizes() end end diff --git a/scripts/gui/libview.fluid b/scripts/gui/libview.fluid index 45f000010..c0215b351 100644 --- a/scripts/gui/libview.fluid +++ b/scripts/gui/libview.fluid @@ -7,9 +7,6 @@ if (not mGfx) then mGfx = mod.load('display') end if (not mVec) then mVec = mod.load('vector') end - local lColBackground = 'rgb(255,255,255)' - local lColBorder = 'rgb(160,160,160)' - local lColBorderHighlight = 'rgb(160,160,160)' local lItemCounter = 1 ---------------------------------------------------------------------------------------------------------------------- @@ -478,7 +475,7 @@ gui.initView = function(Options, BuildUI, NewItems) vw.bkgd = vw.viewport.new('VectorRectangle', { name = 'view_bkgd', - fill = lColBackground, + fill = gui.colours.background, width = '100%', height = '100%' }) @@ -490,7 +487,7 @@ gui.initView = function(Options, BuildUI, NewItems) name = 'view_border', width = '100%', height = '100%', - stroke = lColBorder, + stroke = gui.colours.border, strokeWidth = 1.5 }) @@ -521,11 +518,11 @@ gui.initView = function(Options, BuildUI, NewItems) vw.viewport.mtSubscribeFeedback(bit.bor(FM_HAS_FOCUS, FM_CHILD_HAS_FOCUS, FM_LOST_FOCUS), function(Viewport, Event) if (Event == FM_LOST_FOCUS) then vw.hasFocus = false - vw.border.stroke = lColBorder + vw.border.stroke = gui.colours.border if vw.events.lostFocus then vw.events.lostFocus(vw) end else vw.hasFocus = true - vw.border.stroke = lColBorderHighlight + vw.border.stroke = gui.colours.borderFocus if vw.events.focus then vw.events.focus(vw) end end vw.viewport.acDraw() diff --git a/scripts/gui/scrollbar.fluid b/scripts/gui/scrollbar.fluid index a2c9635dc..3192a8abc 100644 --- a/scripts/gui/scrollbar.fluid +++ b/scripts/gui/scrollbar.fluid @@ -155,7 +155,7 @@ gui.scrollbar = function(Options) local bar if (Direction == 'V') then - local vp = lTarget.new('VectorViewport', { y = 0, xOffset = 0, yOffset = 0, width = lBreadth }) + local vp = lTarget.new('VectorViewport', { y = 0, xOffset = 0, yOffset = 0, width = lBreadth, overflow = VOF_HIDDEN }) bar = vp.state() bar.viewport = vp @@ -163,10 +163,10 @@ gui.scrollbar = function(Options) lStyle.background(bar, bar.viewport) - bar.negVP = vp.new('VectorViewport', { width = lBreadth, height = lBreadth }) - bar.posVP = vp.new('VectorViewport', { yOffset = 0, width = lBreadth, height = lBreadth }) - bar.sliderHostVP = vp.new('VectorViewport', { y = lBreadth, width = '100%', yOffset = lBreadth }) - bar.sliderVP = bar.sliderHostVP.new('VectorViewport', { width = lBreadth, height = bar.sliderHostVP.height }) + bar.negVP = vp.new('VectorViewport', { width = lBreadth, height = lBreadth, overflow = VOF_HIDDEN }) + bar.posVP = vp.new('VectorViewport', { yOffset = 0, width = lBreadth, height = lBreadth, overflow = VOF_HIDDEN }) + bar.sliderHostVP = vp.new('VectorViewport', { y = lBreadth, width = '100%', yOffset = lBreadth, overflow = VOF_HIDDEN }) + bar.sliderVP = bar.sliderHostVP.new('VectorViewport', { width = lBreadth, height = bar.sliderHostVP.height, overflow = VOF_HIDDEN }) -- Respond to the user dragging the slider. Moving the page is all that is necessary; this -- will result in downstream callbacks making the necessary updates. @@ -194,10 +194,10 @@ gui.scrollbar = function(Options) lStyle.background(bar, bar.viewport) - bar.negVP = vp.new('VectorViewport', { width = lBreadth, height = lBreadth }) - bar.posVP = vp.new('VectorViewport', { xOffset = 0, width = lBreadth, height = lBreadth }) - bar.sliderHostVP = vp.new('VectorViewport', { x = lBreadth, height = '100%', xOffset = lBreadth }) - bar.sliderVP = bar.sliderHostVP.new('VectorViewport', { width = bar.sliderHostVP.height, height = lBreadth }) + bar.negVP = vp.new('VectorViewport', { width = lBreadth, height = lBreadth, overflow = VOF_HIDDEN }) + bar.posVP = vp.new('VectorViewport', { xOffset = 0, width = lBreadth, height = lBreadth, overflow = VOF_HIDDEN }) + bar.sliderHostVP = vp.new('VectorViewport', { x = lBreadth, height = '100%', xOffset = lBreadth, overflow = VOF_HIDDEN }) + bar.sliderVP = bar.sliderHostVP.new('VectorViewport', { width = bar.sliderHostVP.height, height = lBreadth, overflow = VOF_HIDDEN }) bar.sliderVP.dragCallback = function(Viewport, X, Y) local slider_width = Viewport.width diff --git a/scripts/gui/toolbar.fluid b/scripts/gui/toolbar.fluid index 37ea6cf89..3dd7d290f 100644 --- a/scripts/gui/toolbar.fluid +++ b/scripts/gui/toolbar.fluid @@ -67,7 +67,7 @@ gui.toolbar = function(HostVP, Options) _cellMargin = nz(Options.cellMargin, 6), _disabled = false, _lookup = { }, - _iconSize = nz(Options.iconSize, 20), + _iconSize = nz(Options.iconSize, gui.interface.iconSize), _hasFocus = false }