mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
support vertical slider
This commit is contained in:
@@ -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