mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
initial commit
This commit is contained in:
35
luigi/widget/sash.lua
Normal file
35
luigi/widget/sash.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
local Widget = require((...):gsub('%.[^.]*$', ''))
|
||||
|
||||
local Sash = Widget:extend()
|
||||
|
||||
function Sash:constructor(layout, data)
|
||||
Widget.constructor(self, layout, data)
|
||||
|
||||
self:onPressDrag(function(event)
|
||||
local axis = self.parent.flow
|
||||
if axis == 'x' then
|
||||
dimension = 'width'
|
||||
else
|
||||
axis = 'y'
|
||||
dimension = 'height'
|
||||
end
|
||||
local prevSibling = self:getPrevious()
|
||||
local nextSibling = self:getNext()
|
||||
local prevSize = prevSibling and prevSibling[dimension]
|
||||
local nextSize = nextSibling and nextSibling[dimension]
|
||||
if prevSize then
|
||||
prevSibling:setDimension(dimension,
|
||||
event[axis] - prevSibling:calculatePosition(axis))
|
||||
end
|
||||
if nextSize then
|
||||
nextSibling:setDimension(dimension,
|
||||
nextSibling:calculatePosition(axis) +
|
||||
nextSibling[dimension] - event[axis])
|
||||
end
|
||||
|
||||
layout:update(true)
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
return Sash
|
||||
52
luigi/widget/slider.lua
Normal file
52
luigi/widget/slider.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
local Widget = require((...):gsub('%.[^.]*$', ''))
|
||||
|
||||
local Slider = Widget:extend()
|
||||
|
||||
function Slider:constructor(layout, data)
|
||||
Widget.constructor(self, layout, data)
|
||||
|
||||
local function getCenter()
|
||||
return self:getX() + self:getWidth() / 2
|
||||
end
|
||||
|
||||
local position = 0.5
|
||||
|
||||
self:onPressDrag(function(event)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
position = (event.x - x1) / (x2 - x1)
|
||||
if position < 0 then position = 0 end
|
||||
if position > 1 then position = 1 end
|
||||
self:update()
|
||||
end)
|
||||
|
||||
self:onDisplay(function(event)
|
||||
-- event:yield()
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local padding = self.padding or 0
|
||||
self.layout.window:fill(
|
||||
x1,
|
||||
y1 + (y2 - y1) / 2 - padding / 2,
|
||||
x2,
|
||||
y1 + (y2 - y1) / 2 + padding / 2,
|
||||
self.background, -(self.bend or 0)
|
||||
)
|
||||
self.layout.window:fill(
|
||||
x1 + position * (x2 - x1) - padding,
|
||||
y1 + padding,
|
||||
x1 + position * (x2 - x1) + padding,
|
||||
y2 - padding,
|
||||
self.background, self.bend
|
||||
)
|
||||
self.layout.window:outline(
|
||||
x1 + position * (x2 - x1) - padding,
|
||||
y1 + padding,
|
||||
x1 + position * (x2 - x1) + padding,
|
||||
y2 - padding,
|
||||
self.outline
|
||||
)
|
||||
return false
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
return Slider
|
||||
9
luigi/widget/text.lua
Normal file
9
luigi/widget/text.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
local Widget = require((...):gsub('%.[^.]*$', ''))
|
||||
|
||||
local Text = Widget:extend()
|
||||
|
||||
function Text:constructor(layout, data)
|
||||
Widget.constructor(self, layout, data)
|
||||
end
|
||||
|
||||
return Text
|
||||
Reference in New Issue
Block a user