misc cleanup

This commit is contained in:
airstruck
2015-10-28 00:06:47 -04:00
parent f19ef288ca
commit 18f51c2ac3
6 changed files with 38 additions and 52 deletions

View File

@@ -60,9 +60,9 @@ local mainForm = { title = "Test window", id = 'mainWindow', type = 'panel',
{ type = 'sash', width = 4, }, { type = 'sash', width = 4, },
{ type = 'panel', id = 'rightSideBox', width = 200, { type = 'panel', id = 'rightSideBox', width = 200,
{ type = 'panel', text = 'A slider', align = 'bottom', height = 24, padding = 4 }, { type = 'panel', text = 'A slider', align = 'bottom', height = 24, padding = 4 },
{ type = 'slider', height = 32, padding = 4, id = 'slidey', }, { type = 'slider', height = 32, margin = 4, id = 'slidey', },
{ type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 }, { type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 },
{ type = 'stepper', height = 32, padding = 4, options = { { type = 'stepper', height = 32, margin = 4, options = {
{ value = 1, text = 'Thing One' }, { value = 1, text = 'Thing One' },
{ value = 2, text = 'Thing Two' }, { value = 2, text = 'Thing Two' },
{ value = 3, text = 'Thing Three' }, { value = 3, text = 'Thing Three' },

View File

@@ -55,8 +55,8 @@ function Style:eachName (object)
end end
return true return true
end end
local function getSpecialName (...) local function getSpecialName (names)
for k, name in ipairs({ ... }) do for k, name in ipairs(names) do
if not returnedSpecialName[name] then if not returnedSpecialName[name] then
returnedSpecialName[name] = true returnedSpecialName[name] = true
if rawget(object, name) then if rawget(object, name) then
@@ -69,7 +69,7 @@ function Style:eachName (object)
end end
return function () return function ()
if not checkLookupProp() then return end if not checkLookupProp() then return end
local specialName = getSpecialName('pressed', 'hovered') local specialName = getSpecialName { 'pressed', 'hovered' }
if specialName then return specialName end if specialName then return specialName end
lookupPropIndex = lookupPropIndex + 1 lookupPropIndex = lookupPropIndex + 1
return lookupProp[lookupPropIndex] return lookupProp[lookupPropIndex]

View File

@@ -13,7 +13,6 @@ return function (config)
background = backColor, background = backColor,
}, },
button = { button = {
type = 'panel',
align = 'center middle', align = 'center middle',
padding = 6, padding = 6,
slices = RESOURCE .. 'button.png', slices = RESOURCE .. 'button.png',
@@ -40,16 +39,14 @@ return function (config)
background = highlight background = highlight
}, },
slider = { slider = {
type = 'panel', slices = RESOURCE .. 'button_pressed.png',
outline = lineColor, padding = 0,
background = white, },
slider_hovered = {
}, },
stepper = { stepper = {
type = 'panel', type = 'panel',
}, },
slider_hovered = {
outline = highlight,
},
} }
end end

View File

@@ -76,7 +76,7 @@ end
function Widget:addChild (data) function Widget:addChild (data)
local layout = self.layout local layout = self.layout
local child = Widget(layout, data) local child = Widget(layout, data or {})
table.insert(self.children, child) table.insert(self.children, child)
child.parent = self child.parent = self

View File

@@ -1,45 +1,34 @@
return function (self) return function (self)
self.value = 0.5 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) self:onPressDrag(function (event)
local x1, y1, x2, y2 = self:getRectangle(true, true) local x1, y1, x2, y2 = self:getRectangle(true, true)
self.value = (event.x - x1) / (x2 - x1) self.value = (event.x - x1) / (x2 - x1)
if self.value < 0 then self.value = 0 end if self.value < 0 then self.value = 0 end
if self.value > 1 then self.value = 1 end if self.value > 1 then self.value = 1 end
self:reflow()
end) end)
self:onDisplay(function (event) self:onReshape(function (event)
local x1, y1, x2, y2 = self:getRectangle(true, true) local x1, y1, x2, y2 = self:getRectangle(true, true)
local padding = self.padding or 0 spacer.width = self.value * (x2 - x1 - thumb:getWidth())
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)
end end

View File

@@ -1,9 +1,9 @@
return function (self) return function (self)
self.flow = 'x'
self.index = 1 self.index = 1
self.flow = 'x' -- TODO: support vertical stepper
local left = self:addChild { local decrement = self:addChild {
type = 'button', type = 'button',
text = '<', text = '<',
align = 'middle center', align = 'middle center',
@@ -15,7 +15,7 @@ return function (self)
margin = 0, margin = 0,
} }
local right = self:addChild { local increment = self:addChild {
type = 'button', type = 'button',
text = '>', text = '>',
align = 'middle center', align = 'middle center',
@@ -23,8 +23,8 @@ return function (self)
} }
self:onReshape(function (event) self:onReshape(function (event)
left.width = left:getHeight() decrement.width = decrement:getHeight()
right.width = right:getHeight() increment.width = increment:getHeight()
end) end)
local function updateValue () local function updateValue ()
@@ -34,7 +34,7 @@ return function (self)
view.text = option.text view.text = option.text
end end
left:onPress(function (event) decrement:onPress(function (event)
if not self.options then return end if not self.options then return end
self.index = self.index - 1 self.index = self.index - 1
if self.index < 1 then if self.index < 1 then
@@ -43,7 +43,7 @@ return function (self)
updateValue() updateValue()
end) end)
right:onPress(function (event) increment:onPress(function (event)
if not self.options then return end if not self.options then return end
self.index = self.index + 1 self.index = self.index + 1
if self.index > #self.options then if self.index > #self.options then