scrap widget inheritance

This commit is contained in:
airstruck
2015-10-27 19:27:14 -04:00
parent ca67432b66
commit f19ef288ca
7 changed files with 101 additions and 125 deletions

View File

@@ -1,33 +1,30 @@
local Widget = require((...):gsub('%.[^.]*$', ''))
return function (self)
local Sash = Widget:extend()
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
Sash:onPressDrag(function (event)
local self = event.target
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
prevSibling:reflow()
nextSibling:reflow()
self:reflow()
end)
prevSibling:reflow()
nextSibling:reflow()
self:reflow()
end)
return Sash
end

View File

@@ -1,53 +1,45 @@
local Widget = require((...):gsub('%.[^.]*$', ''))
local Slider = Widget:extend()
function Slider:constructor (layout, data)
Widget.constructor(self, layout, data)
return function (self)
self.value = 0.5
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
end)
self:onDisplay(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
end)
end
Slider:onPressDrag(function (event)
local self = event.target
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
end)
Slider:onDisplay(function (event)
local self = event.target
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
end)
return Slider

View File

@@ -1,9 +1,4 @@
local Widget = require((...):gsub('%.[^.]*$', ''))
local Stepper = Widget:extend()
function Stepper:constructor (layout, data)
Widget.constructor(self, layout, data)
return function (self)
self.flow = 'x'
self.index = 1
@@ -58,6 +53,5 @@ function Stepper:constructor (layout, data)
end)
updateValue()
end
return Stepper
end

View File

@@ -1,9 +1,3 @@
local Widget = require((...):gsub('%.[^.]*$', ''))
return function (self)
local Text = Widget:extend()
function Text:constructor (layout, data)
Widget.constructor(self, layout, data)
end
return Text