mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
simplify style system
This commit is contained in:
@@ -2,38 +2,74 @@ local RESOURCE = (...):gsub('%.', '/') .. '/'
|
||||
|
||||
return function (config)
|
||||
config = config or {}
|
||||
|
||||
local resources = config.resources or RESOURCE
|
||||
local backColor = config.backColor or { 240, 240, 240 }
|
||||
local lineColor = config.lineColor or { 220, 220, 220 }
|
||||
local textColor = config.textColor or { 0, 0, 0 }
|
||||
local highlight = config.highlight or { 0x19, 0xAE, 0xFF }
|
||||
|
||||
local function getButtonSlices (self)
|
||||
return self.pressed and resources .. 'button_pressed.png'
|
||||
or self.focused and resources .. 'button_focused.png'
|
||||
or self.hovered and resources .. 'button_hovered.png'
|
||||
or resources .. 'button.png'
|
||||
end
|
||||
|
||||
local function getCheckOrRadioIcon (self)
|
||||
local prefix = resources .. self.type
|
||||
if self.pressed then
|
||||
if self.value then
|
||||
return prefix .. '_checked_pressed.png'
|
||||
else
|
||||
return prefix .. '_unchecked_pressed.png'
|
||||
end
|
||||
elseif self.focused then
|
||||
if self.value then
|
||||
return prefix .. '_checked_focused.png'
|
||||
else
|
||||
return prefix .. '_unchecked_focused.png'
|
||||
end
|
||||
else
|
||||
if self.value then
|
||||
return prefix .. '_checked.png'
|
||||
else
|
||||
return prefix .. '_unchecked.png'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function getMenuItemBackground (self)
|
||||
return self.active and highlight
|
||||
end
|
||||
|
||||
local function getSashBackground (self)
|
||||
return self.hovered and highlight or lineColor
|
||||
end
|
||||
|
||||
local function getTextSlices (self)
|
||||
return self.focused and resources .. 'text_focused.png'
|
||||
or resources .. 'text.png'
|
||||
end
|
||||
|
||||
return {
|
||||
button = {
|
||||
align = 'center middle',
|
||||
padding = 6,
|
||||
slices = RESOURCE .. 'button.png',
|
||||
slices = getButtonSlices,
|
||||
minwidth = 24,
|
||||
minheight = 24,
|
||||
focusable = true
|
||||
},
|
||||
button_hovered = {
|
||||
slices = RESOURCE .. 'button_hovered.png'
|
||||
},
|
||||
button_focused = {
|
||||
slices = RESOURCE .. 'button_focused.png',
|
||||
},
|
||||
button_pressed = {
|
||||
slices = RESOURCE .. 'button_pressed.png',
|
||||
focusable = true,
|
||||
color = textColor,
|
||||
},
|
||||
|
||||
['stepper.left'] = {
|
||||
type = 'button',
|
||||
icon = RESOURCE .. 'triangle_left.png',
|
||||
icon = resources .. 'triangle_left.png',
|
||||
},
|
||||
|
||||
['stepper.right'] = {
|
||||
type = 'button',
|
||||
icon = RESOURCE .. 'triangle_right.png',
|
||||
icon = resources .. 'triangle_right.png',
|
||||
},
|
||||
menu = {
|
||||
height = 24,
|
||||
@@ -41,107 +77,72 @@ return function (config)
|
||||
['menu.item'] = {
|
||||
padding = 4,
|
||||
align = 'left middle',
|
||||
color = { 0, 0, 0 }
|
||||
},
|
||||
['menu.item_active'] = {
|
||||
background = highlight,
|
||||
color = textColor,
|
||||
background = getMenuItemBackground,
|
||||
},
|
||||
['menu.expander'] = {
|
||||
icon = RESOURCE .. 'triangle_right.png',
|
||||
icon = resources .. 'triangle_right.png',
|
||||
},
|
||||
submenu = {
|
||||
padding = 10,
|
||||
margin = -10,
|
||||
slices = RESOURCE .. 'submenu.png',
|
||||
slices = resources .. 'submenu.png',
|
||||
color = textColor,
|
||||
},
|
||||
sash = {
|
||||
background = lineColor
|
||||
},
|
||||
sash_hovered = {
|
||||
background = highlight
|
||||
background = getSashBackground
|
||||
},
|
||||
slider = {
|
||||
slices = RESOURCE .. 'button_pressed.png',
|
||||
slices = resources .. 'button_pressed.png',
|
||||
padding = 0,
|
||||
minwidth = 24,
|
||||
minheight = 24
|
||||
},
|
||||
panel = {
|
||||
background = backColor,
|
||||
color = textColor,
|
||||
},
|
||||
progress = {
|
||||
slices = RESOURCE .. 'button_pressed.png',
|
||||
slices = resources .. 'button_pressed.png',
|
||||
padding = 0,
|
||||
minwidth = 24,
|
||||
minheight = 24
|
||||
},
|
||||
['progress.bar'] = {
|
||||
slices = RESOURCE .. 'progress.png',
|
||||
slices = resources .. 'progress.png',
|
||||
padding = 0,
|
||||
minwidth = 12,
|
||||
},
|
||||
slider_hovered = {
|
||||
},
|
||||
stepper = {
|
||||
slices = RESOURCE .. 'button_pressed.png',
|
||||
slices = resources .. 'button_pressed.png',
|
||||
},
|
||||
['stepper.item'] = {
|
||||
align = 'center middle',
|
||||
color = textColor,
|
||||
},
|
||||
status = {
|
||||
type = 'panel',
|
||||
},
|
||||
text = {
|
||||
align = 'left middle',
|
||||
slices = RESOURCE .. 'text.png',
|
||||
slices = getTextSlices,
|
||||
padding = 6,
|
||||
minwidth = 24,
|
||||
minheight = 24,
|
||||
focusable = true,
|
||||
cursor = 'ibeam',
|
||||
highlight = highlight,
|
||||
},
|
||||
text_focused = {
|
||||
slices = RESOURCE .. 'text_focused.png',
|
||||
color = textColor,
|
||||
},
|
||||
check = {
|
||||
focusable = true,
|
||||
},
|
||||
['check.unchecked'] = {
|
||||
icon = RESOURCE .. 'check_unchecked.png',
|
||||
},
|
||||
['check.checked'] = {
|
||||
icon = RESOURCE .. 'check_checked.png',
|
||||
},
|
||||
['check.unchecked_pressed'] = {
|
||||
icon = RESOURCE .. 'check_unchecked_pressed.png',
|
||||
},
|
||||
['check.checked_pressed'] = {
|
||||
icon = RESOURCE .. 'check_checked_pressed.png',
|
||||
},
|
||||
['check.unchecked_focused'] = {
|
||||
icon = RESOURCE .. 'check_unchecked_focused.png',
|
||||
},
|
||||
['check.checked_focused'] = {
|
||||
icon = RESOURCE .. 'check_checked_focused.png',
|
||||
color = textColor,
|
||||
icon = getCheckOrRadioIcon
|
||||
},
|
||||
radio = {
|
||||
focusable = true,
|
||||
},
|
||||
['radio.unchecked'] = {
|
||||
icon = RESOURCE .. 'radio_unchecked.png',
|
||||
},
|
||||
['radio.checked'] = {
|
||||
icon = RESOURCE .. 'radio_checked.png',
|
||||
},
|
||||
['radio.unchecked_pressed'] = {
|
||||
icon = RESOURCE .. 'radio_unchecked_pressed.png',
|
||||
},
|
||||
['radio.checked_pressed'] = {
|
||||
icon = RESOURCE .. 'radio_checked_pressed.png',
|
||||
},
|
||||
['radio.unchecked_focused'] = {
|
||||
icon = RESOURCE .. 'radio_unchecked_focused.png',
|
||||
},
|
||||
['radio.checked_focused'] = {
|
||||
icon = RESOURCE .. 'radio_checked_focused.png',
|
||||
color = textColor,
|
||||
icon = getCheckOrRadioIcon
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user