Skip to content

Commit

Permalink
UI Improvements (#240)
Browse files Browse the repository at this point in the history
* [Fluid] Removed gui.bitmapColour(); Removed gui.colours.rgb() in favour of key-value lookups
  • Loading branch information
paul-manias authored May 5, 2024
1 parent 04bdc8e commit 1df5f01
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 112 deletions.
2 changes: 1 addition & 1 deletion data/styles/default/window.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ return {
name = 'window_frame',
x=0, y=0, width='100%', height='100%',
strokeWidth=5, stroke='rgb(100,100,100)',
fill=gui.colours.rgb('window')
fill=gui.colours['window']
})
end,
menubar = function(Window)
Expand Down
37 changes: 19 additions & 18 deletions scripts/common.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ table.toXML = function(t)
return out
end

------------------------------------------------------------------------------
-- Usage: for k,v in table.sortByKeys(the_table) do

table.sortByKeys = function(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end

------------------------------------------------------------------------------

string.escXML = function(s)
Expand Down Expand Up @@ -124,23 +141,6 @@ string.endsWith = function(s, cmp)
return cmp == "" or string.sub(s, -#cmp) == cmp
end

------------------------------------------------------------------------------
-- Usage: for k,v in table.sortByKeys(the_table) do

table.sortByKeys = function(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end

------------------------------------------------------------------------------

if file == nil then
Expand Down Expand Up @@ -189,5 +189,6 @@ end
------------------------------------------------------------------------------

file.sanitisePath = function(Path)
return string.gsub(Path, '[:/\\][:/\\]+', function(n) return n:sub(1,1) end)
local v = string.gsub(Path, '[:/\\][:/\\]+', function(n) return n:sub(1,1) end)
return v
end
20 changes: 11 additions & 9 deletions scripts/dev/idl/idl-c.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ function platform(Platform, Function)
elseif (Platform:lower() == 'x11') then
define = '__xwindows__'
Function()
--elseif (Platform:lower() == 'osx') then
-- define = '__xwindows__'
-- Function()
else
error('Unrecognised platform "' .. Platform .. '"')
end
Expand Down Expand Up @@ -882,7 +885,7 @@ end
-- FDL Function
-- Refer to outputClassHeader() for output of the class structure.

function class(Name, Options, Blueprint, Private, Custom)
function class(Name, Options, Spec, Private, Custom)
if (glFeedback == 'verbose') then print('Processing class ' .. nz(Name,'NIL')) end

Options = checkOptions(Options)
Expand Down Expand Up @@ -921,7 +924,7 @@ function class(Name, Options, Blueprint, Private, Custom)

-- Process methods and fields defined in the source code (if available)

local cdef = processClassFields(class, Blueprint)
local cdef = processClassFields(class, Spec)

if nz(Options.references) then
for _, v in pairs(Options.references) do
Expand Down Expand Up @@ -1272,7 +1275,7 @@ function processField(class, extract)
end
f.description = description
elseif (class.meta != nil) then
print("Field '" .. class.name .. "." .. nz(name,'NIL') .. "' is not defined in the FDL or compiled class blueprint.")
print("Field '" .. class.name .. "." .. nz(name,'NIL') .. "' is not defined in the FDL or compiled class spec.")
end
end

Expand Down Expand Up @@ -1398,14 +1401,14 @@ function outputLookup(Name, List)
end

----------------------------------------------------------------------------------------------------------------------
-- Process the formal field definitions in a class blueprint.
-- Process the formal field definitions in a class spec.

function processClassFields(class, ClientBlueprint)
function processClassFields(class, ClientSpec)
local cdef = ''

-- Process fields defined in the FDL

class.fields = extractFields(ClientBlueprint, class.name)
class.fields = extractFields(ClientSpec, class.name)

-- Add compiled fields into the field definitions. NB: Technically this relies on a circular reference, so such
-- information can only be taken advantage of for phase 2 processing (class documentation).
Expand Down Expand Up @@ -2009,7 +2012,7 @@ function processFunction(extract)
local status = extract:match('\n[Ss]tatus:%s+(.-)\n')
local category = extract:match('\n[Cc]ategory:%s+(.-)\n')
local ext_proto = extract:match('\n[Ee]xtPrototype:%s+(.-)\n')
local attrib = extract:match('\n[Aa]ttribute:%s+(.-)\n')
local attrib = extract:match('\n[Aa]ttribute:%s+(.-)\n') -- This value is appended to the jump table name
local description = extract:match('\n\n(.-)\n%-[A-Z]+%-\n')

if (name:find('%(%)') != nil) then
Expand Down Expand Up @@ -2193,7 +2196,7 @@ function idlFunction(Name, Category, Comment, Status, Description, Def)

-- The func.def is used for building the jump table
func.def = " " .. nz(response.type,"NIL")
if Def.attrib then func.def = func.def .. " " .. nz(Def.attrib,"") end
if Def.attrib then func.def = func.def .. " " .. Def.attrib end
func.def = func.def .. " (*_" .. func.name .. ")(" .. nz(jumpArgs,"void") .. ");"

func.c_proto = proto
Expand Down Expand Up @@ -2495,7 +2498,6 @@ end
glProgram = 'idl-c' // FDL's can read this
glSource = arg('src')
glOutputPath = arg('output')
glLanguage = arg('language')
glFeedback = arg('feedback')
glOutputDefs = arg('output-defs')
glOutputProto = arg('output-proto')
Expand Down
6 changes: 3 additions & 3 deletions scripts/dev/idl/idl-def.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
-- dynamically consumed by any language for the purpose of achieving full integration with the Parasol runtime
-- environment, which is written in C.
--
-- Usage: fluid sdk:scripts/idl-fluid.fluid src=source.fdl
-- Example: fluid sdk:scripts/idl-fluid.fluid src=sdk:core/modules/core/core.fdl
-- Usage: parasol sdk:scripts/idl-fluid.fluid src=source.fdl
-- Example: parasol sdk:scripts/idl-fluid.fluid src=sdk:core/modules/core/core.fdl

require 'common'

Expand Down Expand Up @@ -146,7 +146,7 @@ function enum(Prefix, Options, ...)
list[name] = client_val
end
else
error("Invalid flag type for '" .. Prefix .. "', expected string, got '" .. type(enum_def) .. "'")
error("Invalid enum type for '" .. Prefix .. "', expected string, got '" .. type(enum_def) .. "'")
end
inc = inc + 1
end
Expand Down
6 changes: 3 additions & 3 deletions scripts/filesearch.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ This example searches for text files in the 'documents:' folder that include the
end
})

Valid options to use when creating the search object are as follows:
Valid options to use when defining the search table are as follows:

nameFilter: Include file/folder names that match this filter.
contentFilter: Include files that contain this content.
nameWild: Set to true to enable wildcard matching for file names, or 'lua' for Lua expression matching.
contentWild: Set to true to enable wildcard matching for content, or 'lua' for LUa expression matching.
contentWild: Set to true to enable wildcard matching for content, or 'lua' for Lua expression matching.
caseSensitive: All comparisons are case sensitive.
matchFeedback: Call this function each time that a matched file is discovered. Returning ERR_Terminate will stop the search. Synopsis: function(Path, File, Attributes)
ignoreFeedback: Call this function each time that a file fails to pass filter matches.
Expand All @@ -28,7 +28,7 @@ Valid options to use when creating the search object are as follows:
maxDate: Filter out files with a modification time exceeding this timestamp.
scanLinks: Allows symbolically linked files and folders to be included in the file search.
matchFolders: Include matching folder names in the output of the search.
ignoreFiles: Do not scan files (useful only in conjunction with MATCH_FOLDERS)."
ignoreFiles: Do not scan files (useful only in conjunction with matchFolders).

When searching files for content, it is strongly recommended that a filter or size limit is applied so that only a
limited number of files are opened for searching.
Expand Down
32 changes: 4 additions & 28 deletions scripts/gui.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ if (gui == nil) then
iconTheme = 'Default',
iconSize = 20 -- Recommended default size for icons (px) and should be linked to fontSize
},
rgb = { },
counter = 0,
iconThemes = {
default = { first={ r=90,g=90,b=90 }, last={ r=70,g=70,b=110 } },
carbon = { first={ r=90,g=90,b=90 }, last={ r=70,g=70,b=110 } },
Expand All @@ -68,14 +66,10 @@ if (gui == nil) then
pink = { first={ r=0xff,g=0xdd,b=0xe1 }, last={ r=0xee,g=0x9c,b=0xa7 } },
grey = { first={ r=100,g=100,b=100 }, last={ r=70,g=70,b=70 } },
pearl = { first={ r=250,g=249,b=248 }, last={ r=210,g=211,b=212 } }
}
},
_counter = 0
}

gui.colours.rgb = function(Name)
if not gui.colours[Name] then error('Invalid colour name "' .. Name .. '"') end
return gui.colours[Name]
end

function convertFontSizes() -- Convert font percentage sizes to their px size
for k,v in pairs(gui.fonts) do
if gui.fonts[k].size then
Expand Down Expand Up @@ -163,22 +157,6 @@ gui.getFontHeight = function(Font)
return Font.spacing, Font.height
end

------------------------------------------------------------------------------

gui.bitmapColour = function(Bitmap, ColourName)
if (gui.rgb[ColourName] == nil) then
local str = gui.colours[ColourName]
if (str == nil) then
error('Unrecognised colour "' .. nz(ColourName,'NIL') .. '"')
end
gui.rgb[ColourName] = gui.strToRGB(str)
end

local rgb = gui.rgb[ColourName]
local err, col = Bitmap.mtGetColour(rgb.r, rgb.g, rgb.b, rgb.a)
return col
end

------------------------------------------------------------------------------
-- Read a style value and return it in pixel units.

Expand Down Expand Up @@ -452,8 +430,8 @@ gui.createIcon = function(Scene, Path, Size, Theme, Name)
end
end

gui.counter = gui.counter + 1
local gname = 'icon_grd' .. gui.counter
gui._counter = gui._counter + 1
local gname = 'icon_grd' .. gui._counter
icon.pattern = Scene.new('VectorPattern', { pageWidth=Size, pageHeight=Size, spreadMethod=VSPREAD_PAD })
icon.gradient = gui.simpleGradient(icon.pattern.scene, gname, { lGradient.first, lGradient.last }, 0, 0, 0, 1)
if string.find(Path, 'icons:') != 1 then
Expand Down Expand Up @@ -495,6 +473,4 @@ gui.createIcon = function(Scene, Path, Size, Theme, Name)
end

check(Scene.mtAddDef(Name, icon.pattern))

return icon
end
22 changes: 11 additions & 11 deletions scripts/gui/button.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ gui.button = function(Options)
self.disabled = true
self.viewport.acDisable()
self.text.opacity = 0.5
self.bkgd.fill = gui.colours.rgb('widgetBkgd')
self.bkgd.fill = gui.colours['widgetBkgd']
if self.events.disable then self.events.disable(self) end
self.viewport.acDraw()
end
Expand All @@ -67,7 +67,7 @@ gui.button = function(Options)
self.disabled = false
self.viewport.acDisable()
self.text.opacity = 1.0
self.bkgd.fill = gui.colours.rgb('widgetBkgd')
self.bkgd.fill = gui.colours['widgetBkgd']
if self.events.enable then self.events.enable(self) end
self.viewport.acDraw()
end
Expand Down Expand Up @@ -102,14 +102,14 @@ gui.button = function(Options)
self.viewport = self.parentViewport.new('VectorViewport', vps)

self.bkgd = self.viewport.new('VectorRectangle', {
fill = gui.colours.rgb('widgetBkgd'),
fill = gui.colours['widgetBkgd'],
x = STROKE_WIDTH * 0.5,
y = STROKE_WIDTH * 0.5,
width = self.viewport.width - STROKE_WIDTH,
height = HEIGHT - STROKE_WIDTH,
roundX = STROKE_WIDTH * 2,
roundY = STROKE_WIDTH * 2,
stroke = gui.colours.rgb('widgetStroke'),
stroke = gui.colours['widgetStroke'],
strokeWidth = STROKE_WIDTH,
resizeEvent = function(Viewport, Vector, X, Y, Width, Height)
if (Vector.width != Width) then
Expand All @@ -124,7 +124,7 @@ gui.button = function(Options)

if Options.icon then
pcall(function()
self.icon = gui.createIcon(self.viewport.scene, Options.icon, ICON_SIZE, iconTheme())
gui.createIcon(self.viewport.scene, Options.icon, ICON_SIZE, iconTheme())

self.iconRender = self.viewport.new('VectorViewport', {
x = GAP,
Expand All @@ -147,7 +147,7 @@ gui.button = function(Options)
y = FONT_HEIGHT + math.floor((HEIGHT - FONT_HEIGHT - STROKE_WIDTH - STROKE_WIDTH) * 0.5),
face = gui.fonts.widget.face,
fontSize = string.format('%.2fpt', gui.fonts.widget.size),
fill = gui.colours.rgb('widgetText'),
fill = gui.colours['widgetText'],
string = Options.text,
lineLimit = 1
})
Expand All @@ -158,13 +158,13 @@ gui.button = function(Options)

self.viewport.mtSubscribeFeedback(bit.bor(FM_HAS_FOCUS, FM_CHILD_HAS_FOCUS, FM_LOST_FOCUS), function(Viewport, Event)
if (Event == FM_LOST_FOCUS) then
self.bkgd.stroke = gui.colours.rgb('widgetStroke')
self.bkgd.stroke = gui.colours['widgetStroke']
if self.events.lostFocus then self.events.lostFocus(self) end
else
if self.disabled then
self.bkgd.stroke = gui.colours.rgb('widgetStroke')
self.bkgd.stroke = gui.colours['widgetStroke']
else
self.bkgd.stroke = gui.colours.rgb('widgetStrokeFocus')
self.bkgd.stroke = gui.colours['widgetStrokeFocus']
if self.events.focus then self.events.focus(self) end
end
end
Expand All @@ -183,14 +183,14 @@ gui.button = function(Options)
self.viewport.mtSubscribeInput(bit.bor(JTYPE_CROSSING, JTYPE_BUTTON, JTYPE_REPEATED), function(Viewport, Msg)
repeat
if (Msg.type == JET_CROSSED_IN) then
local highlight = gui.strToRGB(gui.colours.rgb('widgetBkgd'))
local highlight = gui.strToRGB(gui.colours['widgetBkgd'])
highlight.a = highlight.a * 0.5
self.bkgd.fill = gui.rgbToSVG(highlight)
if self.events.cursorEntry then
self.events.cursorEntry(self)
end
elseif (Msg.type == JET_CROSSED_OUT) then
self.bkgd.fill = gui.colours.rgb('widgetBkgd')
self.bkgd.fill = gui.colours['widgetBkgd']
if self.events.cursorExit then
self.events.cursorExit(self)
end
Expand Down
Loading

0 comments on commit 1df5f01

Please sign in to comment.