mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 10:26:43 +00:00
misc cleanup
This commit is contained in:
@@ -1,45 +1,34 @@
|
||||
return function (self)
|
||||
|
||||
self.value = 0.5
|
||||
self.flow = 'x' -- TODO: support vertical slider
|
||||
|
||||
local spacer = self:addChild()
|
||||
|
||||
local thumb = self:addChild {
|
||||
type = 'button',
|
||||
align = 'middle center',
|
||||
width = 0,
|
||||
margin = 0,
|
||||
}
|
||||
|
||||
local function unpress ()
|
||||
thumb.pressed = false
|
||||
end
|
||||
|
||||
thumb:onPressStart(unpress)
|
||||
thumb:onPressEnter(unpress)
|
||||
|
||||
self:onPressDrag(function (event)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
self.value = (event.x - x1) / (x2 - x1)
|
||||
if self.value < 0 then self.value = 0 end
|
||||
if self.value > 1 then self.value = 1 end
|
||||
self:reflow()
|
||||
end)
|
||||
|
||||
self:onDisplay(function (event)
|
||||
self:onReshape(function (event)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local padding = self.padding or 0
|
||||
|
||||
local sx1 = math.floor(x1 + self.value * (x2 - x1) - padding) + 0.5
|
||||
local sy1 = math.floor(y1 + padding) + 0.5
|
||||
local sx2 = padding * 2
|
||||
local sy2 = y2 - y1 - padding
|
||||
|
||||
love.graphics.push('all')
|
||||
|
||||
love.graphics.setColor(self.outline)
|
||||
|
||||
love.graphics.rectangle('fill',
|
||||
x1,
|
||||
y1 + ((y2 - y1) / 2),
|
||||
x2 - x1,
|
||||
padding
|
||||
)
|
||||
|
||||
love.graphics.setColor(self.background)
|
||||
|
||||
love.graphics.rectangle('fill', sx1, sy1, sx2, sy2)
|
||||
|
||||
love.graphics.setColor(self.outline)
|
||||
|
||||
love.graphics.rectangle('line', sx1, sy1, sx2, sy2)
|
||||
|
||||
love.graphics.pop()
|
||||
|
||||
return false
|
||||
spacer.width = self.value * (x2 - x1 - thumb:getWidth())
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user