mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 16:28:23 +00:00
style system overhaul
This commit is contained in:
@@ -35,19 +35,19 @@ local style = {
|
|||||||
local mainForm = { id = 'mainWindow', type = 'panel',
|
local mainForm = { id = 'mainWindow', type = 'panel',
|
||||||
{ type = 'menu', id = 'menubar', flow = 'x',
|
{ type = 'menu', id = 'menubar', flow = 'x',
|
||||||
{ text = 'File', id = 'menuFile',
|
{ text = 'File', id = 'menuFile',
|
||||||
{ text = 'Save', id = 'menuFileSave', },
|
{ text = 'Save', id = 'menuFileSave', key = 'ctrl-s' },
|
||||||
{ text = 'Quit' },
|
{ text = 'Quit', id = 'menuQuit', key = 'escape' },
|
||||||
},
|
},
|
||||||
{ text = 'Edit',
|
{ text = 'Edit',
|
||||||
{ text = 'Cut' },
|
{ text = 'Cut', key = 'ctrl-c' },
|
||||||
{ text = 'Copy' },
|
{ text = 'Copy', key = 'ctrl-x' },
|
||||||
{ text = 'Paste' },
|
{ text = 'Paste', key = 'ctrl-v' },
|
||||||
{ type = 'slider' },
|
{ type = 'slider' },
|
||||||
},
|
},
|
||||||
{ text = 'View',
|
{ text = 'View',
|
||||||
{ text = 'Theme',
|
{ text = 'Theme',
|
||||||
{ text = 'Light' },
|
{ text = 'Light', key = 'ctrl-l' },
|
||||||
{ text = 'Dark' },
|
{ text = 'Dark', key = 'ctrl-d' },
|
||||||
},
|
},
|
||||||
{ text = 'Style',
|
{ text = 'Style',
|
||||||
{ text = 'Default' },
|
{ text = 'Default' },
|
||||||
@@ -161,4 +161,12 @@ erge rg eg erg er ergs erg er ge rh erh rth]]
|
|||||||
|
|
||||||
layout.mainCanvas.align = 'top'
|
layout.mainCanvas.align = 'top'
|
||||||
|
|
||||||
|
print(layout.menuQuit)
|
||||||
|
--[[
|
||||||
|
Layout.menuQuit:onPress(function (event)
|
||||||
|
love.event.quit()
|
||||||
|
end)
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
layout:show()
|
layout:show()
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ A tree of widget data.
|
|||||||
A Layout instance.
|
A Layout instance.
|
||||||
--]]--
|
--]]--
|
||||||
function Layout:constructor (data)
|
function Layout:constructor (data)
|
||||||
|
data = data or {}
|
||||||
self.accelerators = {}
|
self.accelerators = {}
|
||||||
self:addDefaultHandlers()
|
self:addDefaultHandlers()
|
||||||
self:setStyle()
|
self:setStyle()
|
||||||
@@ -46,8 +47,8 @@ function Layout:constructor (data)
|
|||||||
|
|
||||||
self.isShown = false
|
self.isShown = false
|
||||||
self.hooks = {}
|
self.hooks = {}
|
||||||
self.root = data or {}
|
self.root = data
|
||||||
Widget(self, self.root)
|
Widget(self, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
|
|||||||
@@ -9,73 +9,43 @@ function Style:constructor (rules, lookupNames)
|
|||||||
self.lookupNames = lookupNames
|
self.lookupNames = lookupNames
|
||||||
end
|
end
|
||||||
|
|
||||||
function Style:getProperty (object, property)
|
function Style:getProperty (object, property, original)
|
||||||
local ownProperty = rawget(object, property)
|
local value = rawget(object, property)
|
||||||
if ownProperty ~= nil then return ownProperty end
|
if value ~= nil then return value end
|
||||||
for styleDef in self:each(object) do
|
|
||||||
local result = self:getProperty(styleDef, property)
|
|
||||||
if result ~= nil then return result end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Style:each (object)
|
original = original or object
|
||||||
local rules = self.rules
|
|
||||||
local nextStyleName = self:eachName(object)
|
|
||||||
return function ()
|
|
||||||
local styleName = nextStyleName()
|
|
||||||
while styleName do
|
|
||||||
local styleDef = rules[styleName]
|
|
||||||
if styleDef then return styleDef end
|
|
||||||
styleName = nextStyleName()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Style:eachName (object)
|
for _, lookupName in ipairs(self.lookupNames) do
|
||||||
local lookupNames = self.lookupNames
|
local lookup = rawget(object, lookupName)
|
||||||
local lookupNameIndex = 0
|
if lookup then
|
||||||
local lookupPropIndex = 0
|
if type(lookup) ~= 'table' then
|
||||||
local lookupProp
|
lookup = { lookup }
|
||||||
|
|
||||||
local returnedSpecialName = {}
|
|
||||||
|
|
||||||
local function checkLookupProp()
|
|
||||||
if type(lookupProp) == 'table' and lookupPropIndex >= #lookupProp then
|
|
||||||
lookupProp = nil
|
|
||||||
end
|
|
||||||
while not lookupProp do
|
|
||||||
returnedSpecialName = {}
|
|
||||||
lookupPropIndex = 0
|
|
||||||
lookupNameIndex = lookupNameIndex + 1
|
|
||||||
if lookupNameIndex > #lookupNames then return end
|
|
||||||
lookupProp = rawget(object, lookupNames[lookupNameIndex])
|
|
||||||
if type(lookupProp) == 'string' then
|
|
||||||
lookupProp = { lookupProp }
|
|
||||||
end
|
end
|
||||||
end
|
for _, lookupValue in ipairs(lookup) do
|
||||||
return true
|
for _, rule in ipairs(self:getRules(original, lookupValue)) do
|
||||||
end
|
local value = self:getProperty(rule, property, original)
|
||||||
local function getSpecialName (names)
|
if value ~= nil then return value end
|
||||||
for k, name in ipairs(names) do
|
|
||||||
if not returnedSpecialName[name] then
|
|
||||||
returnedSpecialName[name] = true
|
|
||||||
if rawget(object, name) then
|
|
||||||
return lookupProp[lookupPropIndex + 1] .. '_' .. name
|
|
||||||
else
|
|
||||||
return lookupProp[lookupPropIndex + 1] .. '_not_' .. name
|
|
||||||
end
|
end
|
||||||
end
|
end -- lookup values
|
||||||
|
end -- if lookup
|
||||||
|
end -- lookup names
|
||||||
|
end
|
||||||
|
|
||||||
|
function Style:getRules (object, lookupValue)
|
||||||
|
local rules = self.rules
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
for _, flag in ipairs { 'pressed', 'focused', 'hovered', 'active' } do
|
||||||
|
if rawget(object, flag) then
|
||||||
|
result[#result + 1] = rules[lookupValue .. '_' .. flag]
|
||||||
|
else
|
||||||
|
result[#result + 1] = rules[lookupValue .. '_not_' .. flag]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return function ()
|
|
||||||
if not checkLookupProp() then return end
|
result[#result + 1] = rules[lookupValue]
|
||||||
local specialName = getSpecialName {
|
|
||||||
'pressed', 'focused', 'hovered', 'active',
|
return result
|
||||||
}
|
|
||||||
if specialName then return specialName end
|
|
||||||
lookupPropIndex = lookupPropIndex + 1
|
|
||||||
return lookupProp[lookupPropIndex]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Style
|
return Style
|
||||||
|
|||||||
@@ -25,16 +25,32 @@ return function (config)
|
|||||||
button_pressed = {
|
button_pressed = {
|
||||||
slices = RESOURCE .. 'button_pressed.png',
|
slices = RESOURCE .. 'button_pressed.png',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
['stepper.left'] = {
|
||||||
|
type = 'button',
|
||||||
|
icon = RESOURCE .. 'triangle_left.png',
|
||||||
|
},
|
||||||
|
|
||||||
|
['stepper.right'] = {
|
||||||
|
type = 'button',
|
||||||
|
icon = RESOURCE .. 'triangle_right.png',
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
menu = {
|
menu = {
|
||||||
height = 24,
|
height = 24,
|
||||||
},
|
},
|
||||||
['menu.item'] = {
|
['menu.item'] = {
|
||||||
padding = 4,
|
padding = 4,
|
||||||
align = 'left middle',
|
align = 'left middle',
|
||||||
|
textColor = { 0, 0, 0 }
|
||||||
},
|
},
|
||||||
['menu.item_active'] = {
|
['menu.item_active'] = {
|
||||||
background = highlight,
|
background = highlight,
|
||||||
},
|
},
|
||||||
|
['menu.expander'] = {
|
||||||
|
icon = RESOURCE .. 'triangle_right.png',
|
||||||
|
},
|
||||||
submenu = {
|
submenu = {
|
||||||
padding = 10,
|
padding = 10,
|
||||||
margin = -10,
|
margin = -10,
|
||||||
|
|||||||
Binary file not shown.
BIN
luigi/theme/light/triangle_left.png
Normal file
BIN
luigi/theme/light/triangle_left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 189 B |
BIN
luigi/theme/light/triangle_right.png
Normal file
BIN
luigi/theme/light/triangle_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 193 B |
@@ -13,10 +13,11 @@ local function deactivateSiblings (target)
|
|||||||
end
|
end
|
||||||
|
|
||||||
while sibling do
|
while sibling do
|
||||||
local layout = sibling.menuLayout
|
|
||||||
|
|
||||||
sibling.active = nil
|
sibling.active = nil
|
||||||
|
|
||||||
|
local layout = sibling.menuLayout
|
||||||
|
|
||||||
if layout and layout.isShown then
|
if layout and layout.isShown then
|
||||||
wasSiblingOpen = true
|
wasSiblingOpen = true
|
||||||
layout:hide()
|
layout:hide()
|
||||||
@@ -109,9 +110,12 @@ show = function (self)
|
|||||||
menuLayout:onPressStart(function (event)
|
menuLayout:onPressStart(function (event)
|
||||||
if not event.hit then
|
if not event.hit then
|
||||||
menuLayout:hide()
|
menuLayout:hide()
|
||||||
deactivateSiblings(self.rootMenu[1])
|
if self.parentMenu == self.rootMenu then
|
||||||
|
deactivateSiblings(self.rootMenu[1])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
activate(event)
|
||||||
end
|
end
|
||||||
activate(event)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
menuLayout:onEnter(activate)
|
menuLayout:onEnter(activate)
|
||||||
@@ -144,12 +148,22 @@ return function (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if isSubmenu then
|
if isSubmenu then
|
||||||
key = #self.items > 0 and '>' or key
|
local tc = self.textColor or { 0, 0, 0 }
|
||||||
|
local keyColor = { tc[1], tc[2], tc[3], 0x90 }
|
||||||
|
local edgeType
|
||||||
|
if #self.items > 0 then
|
||||||
|
key = ' '
|
||||||
|
edgeType = 'menu.expander'
|
||||||
|
else
|
||||||
|
key = key:gsub('%f[%w].', string.upper)
|
||||||
|
end
|
||||||
self.height = self.fontData:getLineHeight() + pad * 2
|
self.height = self.fontData:getLineHeight() + pad * 2
|
||||||
self.flow = 'x'
|
self.flow = 'x'
|
||||||
self:addChild({ icon = icon, width = self.height })
|
self:addChild({ icon = icon, width = self.height })
|
||||||
self:addChild({ text = text, width = textWidth })
|
self:addChild({ text = text, width = textWidth })
|
||||||
self:addChild({ text = key, align = 'right', minwidth = self.height })
|
self:addChild({ text = key, align = 'middle right',
|
||||||
|
minwidth = self.height,
|
||||||
|
textColor = keyColor, type = edgeType })
|
||||||
|
|
||||||
self.icon = nil
|
self.icon = nil
|
||||||
self.text = nil
|
self.text = nil
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ return function (self)
|
|||||||
self.flow = 'x' -- TODO: support vertical stepper
|
self.flow = 'x' -- TODO: support vertical stepper
|
||||||
|
|
||||||
local decrement = self:addChild {
|
local decrement = self:addChild {
|
||||||
type = 'button',
|
type = 'stepper.left',
|
||||||
text = '<',
|
|
||||||
align = 'middle center',
|
|
||||||
margin = 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local view = self:addChild {
|
local view = self:addChild {
|
||||||
@@ -18,10 +15,7 @@ return function (self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
local increment = self:addChild {
|
local increment = self:addChild {
|
||||||
type = 'button',
|
type = 'stepper.right',
|
||||||
text = '>',
|
|
||||||
align = 'middle center',
|
|
||||||
margin = 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self:onReshape(function (event)
|
self:onReshape(function (event)
|
||||||
|
|||||||
Reference in New Issue
Block a user