mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 16:28:23 +00:00
support vertical slider
This commit is contained in:
@@ -27,6 +27,9 @@ function Style:getProperty (object, property, original)
|
||||
local rule = rules[lookupValue]
|
||||
if rule then
|
||||
local value = self:getProperty(rule, property, original)
|
||||
if type(value) == 'function' then
|
||||
value = value(original)
|
||||
end
|
||||
if value ~= nil then return value end
|
||||
end
|
||||
end -- lookup values
|
||||
|
||||
@@ -38,6 +38,14 @@ return function (config)
|
||||
end
|
||||
end
|
||||
|
||||
local function getControlHeight (self)
|
||||
return self.flow == 'x' and 32
|
||||
end
|
||||
|
||||
local function getControlWidth (self)
|
||||
return self.flow ~= 'x' and 32
|
||||
end
|
||||
|
||||
local function getMenuItemBackground (self)
|
||||
return self.active and highlight
|
||||
end
|
||||
@@ -46,13 +54,30 @@ return function (config)
|
||||
return self.hovered and highlight or lineColor
|
||||
end
|
||||
|
||||
local function getSashHeight (self)
|
||||
return self.parent.flow ~= 'x' and 4
|
||||
end
|
||||
|
||||
local function getSashWidth (self)
|
||||
return self.parent.flow == 'x' and 4
|
||||
end
|
||||
|
||||
local function getTextSlices (self)
|
||||
return self.focused and resources .. 'text_focused.png'
|
||||
or resources .. 'text.png'
|
||||
end
|
||||
|
||||
return {
|
||||
control = {
|
||||
flow = 'x',
|
||||
height = getControlHeight,
|
||||
width = getControlWidth,
|
||||
color = textColor,
|
||||
minheight = 28,
|
||||
minwidth = 28,
|
||||
},
|
||||
button = {
|
||||
type = 'control',
|
||||
align = 'center middle',
|
||||
padding = 6,
|
||||
slices = getButtonSlices,
|
||||
@@ -61,26 +86,83 @@ return function (config)
|
||||
focusable = true,
|
||||
color = textColor,
|
||||
},
|
||||
|
||||
['stepper.left'] = {
|
||||
type = 'button',
|
||||
icon = resources .. 'triangle_left.png',
|
||||
check = {
|
||||
type = 'control',
|
||||
focusable = true,
|
||||
color = textColor,
|
||||
icon = getCheckOrRadioIcon,
|
||||
padding = 4,
|
||||
},
|
||||
|
||||
['stepper.right'] = {
|
||||
type = 'button',
|
||||
icon = resources .. 'triangle_right.png',
|
||||
label = {
|
||||
type = 'control',
|
||||
background = backColor,
|
||||
padding = 4,
|
||||
},
|
||||
menu = {
|
||||
height = 24,
|
||||
},
|
||||
['menu.expander'] = {
|
||||
icon = resources .. 'triangle_right.png',
|
||||
},
|
||||
['menu.item'] = {
|
||||
padding = 4,
|
||||
align = 'left middle',
|
||||
color = textColor,
|
||||
background = getMenuItemBackground,
|
||||
},
|
||||
['menu.expander'] = {
|
||||
panel = {
|
||||
background = backColor,
|
||||
color = textColor,
|
||||
},
|
||||
progress = {
|
||||
type = 'control',
|
||||
slices = resources .. 'button_pressed.png',
|
||||
padding = 0,
|
||||
},
|
||||
['progress.bar'] = {
|
||||
type = 'control',
|
||||
slices = resources .. 'progress.png',
|
||||
padding = 0,
|
||||
minwidth = 12,
|
||||
},
|
||||
radio = {
|
||||
type = 'control',
|
||||
focusable = true,
|
||||
color = textColor,
|
||||
icon = getCheckOrRadioIcon,
|
||||
padding = 4,
|
||||
},
|
||||
sash = {
|
||||
background = getSashBackground,
|
||||
height = getSashHeight,
|
||||
width = getSashWidth,
|
||||
},
|
||||
slider = {
|
||||
type = 'control',
|
||||
slices = resources .. 'button_pressed.png',
|
||||
padding = 0,
|
||||
},
|
||||
status = {
|
||||
type = 'panel',
|
||||
align = 'left middle',
|
||||
padding = 4,
|
||||
height = 22,
|
||||
},
|
||||
stepper = {
|
||||
type = 'control',
|
||||
slices = resources .. 'button_pressed.png',
|
||||
},
|
||||
['stepper.item'] = {
|
||||
type = 'control',
|
||||
align = 'center middle',
|
||||
color = textColor,
|
||||
},
|
||||
['stepper.left'] = {
|
||||
type = 'button',
|
||||
icon = resources .. 'triangle_left.png',
|
||||
},
|
||||
['stepper.right'] = {
|
||||
type = 'button',
|
||||
icon = resources .. 'triangle_right.png',
|
||||
},
|
||||
submenu = {
|
||||
@@ -89,60 +171,14 @@ return function (config)
|
||||
slices = resources .. 'submenu.png',
|
||||
color = textColor,
|
||||
},
|
||||
sash = {
|
||||
background = getSashBackground
|
||||
},
|
||||
slider = {
|
||||
slices = resources .. 'button_pressed.png',
|
||||
padding = 0,
|
||||
minwidth = 24,
|
||||
minheight = 24
|
||||
},
|
||||
panel = {
|
||||
background = backColor,
|
||||
color = textColor,
|
||||
},
|
||||
progress = {
|
||||
slices = resources .. 'button_pressed.png',
|
||||
padding = 0,
|
||||
minwidth = 24,
|
||||
minheight = 24
|
||||
},
|
||||
['progress.bar'] = {
|
||||
slices = resources .. 'progress.png',
|
||||
padding = 0,
|
||||
minwidth = 12,
|
||||
},
|
||||
stepper = {
|
||||
slices = resources .. 'button_pressed.png',
|
||||
},
|
||||
['stepper.item'] = {
|
||||
align = 'center middle',
|
||||
color = textColor,
|
||||
},
|
||||
status = {
|
||||
type = 'panel',
|
||||
},
|
||||
text = {
|
||||
type = 'control',
|
||||
align = 'left middle',
|
||||
slices = getTextSlices,
|
||||
padding = 6,
|
||||
minwidth = 24,
|
||||
minheight = 24,
|
||||
focusable = true,
|
||||
cursor = 'ibeam',
|
||||
highlight = highlight,
|
||||
color = textColor,
|
||||
},
|
||||
check = {
|
||||
focusable = true,
|
||||
color = textColor,
|
||||
icon = getCheckOrRadioIcon
|
||||
},
|
||||
radio = {
|
||||
focusable = true,
|
||||
color = textColor,
|
||||
icon = getCheckOrRadioIcon
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -47,30 +47,30 @@ function Widget.register (name, decorator)
|
||||
end
|
||||
|
||||
local function maybeCall (something, ...)
|
||||
if type(something) == 'function' then
|
||||
return something(...)
|
||||
end
|
||||
return something
|
||||
end
|
||||
|
||||
-- look for properties in attributes, Widget, style, and theme
|
||||
local function metaIndex (self, property)
|
||||
-- look in widget's own attributes
|
||||
local A = Attribute[property]
|
||||
if A then
|
||||
local value = A.get and A.get(self) or self.attributes[property]
|
||||
if value ~= nil then return maybeCall(value, self) end
|
||||
if type(value) == 'function' then value = value(self) end
|
||||
if value ~= nil then return value end
|
||||
end
|
||||
|
||||
-- look in Widget class properties
|
||||
local value = Widget[property]
|
||||
if value ~= nil then return value end
|
||||
|
||||
-- look in style
|
||||
local layout = self.layout
|
||||
local style = layout:getStyle()
|
||||
value = style and maybeCall(style:getProperty(self, property), self)
|
||||
value = layout:getStyle():getProperty(self, property)
|
||||
if value ~= nil then return value end
|
||||
|
||||
local theme = layout:getTheme()
|
||||
return theme and maybeCall(theme:getProperty(self, property), self)
|
||||
-- look in theme
|
||||
return layout:getTheme():getProperty(self, property)
|
||||
end
|
||||
|
||||
-- setting attributes triggers special behavior
|
||||
|
||||
@@ -5,22 +5,22 @@ Buttons have no special behavior beyond that of generic widgets,
|
||||
but themes should give buttons an appropriate appearance.
|
||||
|
||||
@usage
|
||||
-- create a layout containing only a button
|
||||
local layout = Layout {
|
||||
type = 'button',
|
||||
id = 'exampleButton',
|
||||
text = 'Press me',
|
||||
width = 100,
|
||||
height = 32,
|
||||
}
|
||||
-- create a layout containing only a button
|
||||
local layout = Layout {
|
||||
type = 'button',
|
||||
id = 'exampleButton',
|
||||
text = 'Press me',
|
||||
width = 100,
|
||||
height = 32,
|
||||
}
|
||||
|
||||
-- handle Press events
|
||||
layout.exampleButton:onPress(function (event)
|
||||
print 'You pressed the button.'
|
||||
end)
|
||||
-- handle Press events
|
||||
layout.exampleButton:onPress(function (event)
|
||||
print 'You pressed the button.'
|
||||
end)
|
||||
|
||||
-- show the layout
|
||||
layout:show()
|
||||
-- show the layout
|
||||
layout:show()
|
||||
|
||||
@widget button
|
||||
--]]--
|
||||
|
||||
@@ -10,16 +10,16 @@ then either or both of the siblings adjacent to the sash
|
||||
should have a specified @{attribute.width|width} attribute.
|
||||
|
||||
@usage
|
||||
-- create a layout containing two widgets separated by a sash
|
||||
local layout = Layout {
|
||||
type = 'panel', flow = 'x',
|
||||
{ text = 'This is the left side', wrap = true, width = 100 },
|
||||
{ type = 'sash' },
|
||||
{ text = 'This is the right side', wrap = true },
|
||||
}
|
||||
-- create a layout containing two widgets separated by a sash
|
||||
local layout = Layout {
|
||||
type = 'panel', flow = 'x',
|
||||
{ text = 'This is the left side', wrap = true, width = 100 },
|
||||
{ type = 'sash' },
|
||||
{ text = 'This is the right side', wrap = true },
|
||||
}
|
||||
|
||||
-- show the layout
|
||||
layout:show()
|
||||
-- show the layout
|
||||
layout:show()
|
||||
|
||||
@widget sash
|
||||
--]]--
|
||||
|
||||
@@ -8,21 +8,18 @@ number between 0 and 1, inclusive.
|
||||
--]]--
|
||||
|
||||
return function (self)
|
||||
|
||||
local function clamp (value)
|
||||
return value < 0 and 0 or value > 1 and 1 or value
|
||||
end
|
||||
|
||||
self.value = clamp(self.value or 0.5)
|
||||
self.step = self.step or 0.01
|
||||
self.flow = 'x' -- TODO: support vertical slider
|
||||
|
||||
local spacer = self:addChild()
|
||||
|
||||
local thumb = self:addChild {
|
||||
type = 'button',
|
||||
align = 'middle center',
|
||||
width = 0,
|
||||
margin = 0,
|
||||
}
|
||||
|
||||
@@ -46,9 +43,15 @@ return function (self)
|
||||
local function press (event)
|
||||
local x1, y1, w, h = self:getRectangle(true, true)
|
||||
local x2, y2 = x1 + w, y1 + h
|
||||
local halfThumb = thumb:getWidth() / 2
|
||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||
self.value = clamp((event.x - x1) / (x2 - x1))
|
||||
if self.flow == 'x' then
|
||||
local halfThumb = thumb:getWidth() / 2
|
||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||
self.value = clamp((event.x - x1) / (x2 - x1))
|
||||
else
|
||||
local halfThumb = thumb:getHeight() / 2
|
||||
y1, y2 = y1 + halfThumb, y2 - halfThumb
|
||||
self.value = 1 - clamp((event.y - y1) / (y2 - y1))
|
||||
end
|
||||
thumb:focus()
|
||||
end
|
||||
|
||||
@@ -68,11 +71,22 @@ return function (self)
|
||||
end)
|
||||
|
||||
self:onReshape(function (event)
|
||||
-- TODO: eliminate redundancy with `press`
|
||||
local x1, y1, w, h = self:getRectangle(true, true)
|
||||
local x2, y2 = x1 + w, y1 + h
|
||||
local halfThumb = thumb:getWidth() / 2
|
||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||
spacer.width = self.value * (x2 - x1)
|
||||
if self.flow == 'x' then
|
||||
thumb.width = 0
|
||||
thumb.height = false
|
||||
local halfThumb = thumb:getWidth() / 2
|
||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||
spacer.width = self.value * (x2 - x1)
|
||||
spacer.height = false
|
||||
else
|
||||
thumb.width = false
|
||||
thumb.height = 0
|
||||
local halfThumb = thumb:getHeight() / 2
|
||||
y1, y2 = y1 + halfThumb, y2 - halfThumb
|
||||
spacer.width = false
|
||||
spacer.height = (1 - self.value) * (y2 - y1)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -7,21 +7,20 @@ status widgets exist in the same layout, only the last one created will
|
||||
display status messages.
|
||||
|
||||
@usage
|
||||
-- create a layout containing some buttons and a status bar
|
||||
local layout = Layout {
|
||||
{ type = 'panel', flow = 'x',
|
||||
{ text = 'Do stuff', status = 'Press to do stuff' },
|
||||
{ text = 'Quit', status = 'Press to quit' },
|
||||
},
|
||||
{ type = 'status', height = 24 },
|
||||
}
|
||||
-- create a layout containing some buttons and a status bar
|
||||
local layout = Layout {
|
||||
{ type = 'panel', flow = 'x',
|
||||
{ text = 'Do stuff', status = 'Press to do stuff' },
|
||||
{ text = 'Quit', status = 'Press to quit' },
|
||||
},
|
||||
{ type = 'status', height = 24 },
|
||||
}
|
||||
|
||||
-- show the layout
|
||||
layout:show()
|
||||
-- show the layout
|
||||
layout:show()
|
||||
|
||||
@widget status
|
||||
--]]--
|
||||
|
||||
return function (self)
|
||||
self.layout.statusWidget = self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user