mirror of
https://github.com/kepler155c/opus
synced 2025-01-30 09:04:46 +00:00
sliders in forms + form component setValue (hopefully didnt break anything)
This commit is contained in:
parent
51e40a1dd7
commit
c43fe19f1d
@ -29,12 +29,13 @@ function UI.Form:setValues(values)
|
|||||||
self.values = values
|
self.values = values
|
||||||
for _,child in pairs(self.children) do
|
for _,child in pairs(self.children) do
|
||||||
if child.formKey then
|
if child.formKey then
|
||||||
-- this should be child:setValue(self.values[child.formKey])
|
if child.setValue then
|
||||||
-- so chooser can set default choice if null
|
child:setValue(self.values[child.formKey])
|
||||||
-- null should be valid as well
|
else
|
||||||
child.value = self.values[child.formKey] or ''
|
child.value = self.values[child.formKey] or ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Form:createForm()
|
function UI.Form:createForm()
|
||||||
|
@ -12,13 +12,31 @@ UI.Slider.defaults = {
|
|||||||
barColor = colors.gray,
|
barColor = colors.gray,
|
||||||
sliderChar = UI.extChars and '\143' or '\124',
|
sliderChar = UI.extChars and '\143' or '\124',
|
||||||
sliderColor = colors.blue,
|
sliderColor = colors.blue,
|
||||||
leftBorder = '\141',
|
sliderFocusColor = colors.lightBlue,
|
||||||
rightBorder = '\142',
|
leftBorder = UI.extChars and '\141' or '\124',
|
||||||
|
rightBorder = UI.extChars and '\142' or '\124',
|
||||||
value = 0,
|
value = 0,
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 100,
|
max = 100,
|
||||||
event = 'slider_update',
|
event = 'slider_update',
|
||||||
|
accelerators = {
|
||||||
|
right = 'slide_right',
|
||||||
|
left = 'slide_left',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
function UI.Slider:setValue(value)
|
||||||
|
self.value = tonumber(value) or self.min
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Slider:reset() -- form support
|
||||||
|
self.value = self.min
|
||||||
|
self:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Slider:focus()
|
||||||
|
self:draw()
|
||||||
|
end
|
||||||
|
|
||||||
function UI.Slider:draw()
|
function UI.Slider:draw()
|
||||||
local range = self.max - self.min
|
local range = self.max - self.min
|
||||||
local perc = (self.value - self.min) / range
|
local perc = (self.value - self.min) / range
|
||||||
@ -34,7 +52,7 @@ function UI.Slider:draw()
|
|||||||
table.insert(bar, filler)
|
table.insert(bar, filler)
|
||||||
end
|
end
|
||||||
self:write(1, 1, table.concat(bar), nil, self.barColor)
|
self:write(1, 1, table.concat(bar), nil, self.barColor)
|
||||||
self:write(progress, 1, self.sliderChar, nil, self.sliderColor)
|
self:write(progress, 1, self.sliderChar, nil, self.focused and self.sliderFocusColor or self.sliderColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Slider:eventHandler(event)
|
function UI.Slider:eventHandler(event)
|
||||||
@ -44,5 +62,16 @@ function UI.Slider:eventHandler(event)
|
|||||||
self.value = self.min + (i * range)
|
self.value = self.min + (i * range)
|
||||||
self:emit({ type = self.event, value = self.value, element = self })
|
self:emit({ type = self.event, value = self.value, element = self })
|
||||||
self:draw()
|
self:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'slide_left' or event.type == 'slide_right' then
|
||||||
|
local range = self.max - self.min
|
||||||
|
local step = range / self.width
|
||||||
|
if event.type == 'slide_left' then
|
||||||
|
self.value = Util.clamp(self.value - step, self.min, self.max)
|
||||||
|
else
|
||||||
|
self.value = Util.clamp(self.value + step, self.min, self.max)
|
||||||
|
end
|
||||||
|
self:emit({ type = self.event, value = self.value, element = self })
|
||||||
|
self:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ UI.TextEntry.defaults = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function UI.TextEntry:postInit()
|
function UI.TextEntry:postInit()
|
||||||
self.value = tostring(self.value)
|
self.value = tostring(self.value) -- is this right ? shouldnt raw numbers be allowed
|
||||||
self.entry = entry({ limit = self.limit, offset = 2 })
|
self.entry = entry({ limit = self.limit, offset = 2 })
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ function UI.TextEntry:layout()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UI.TextEntry:setValue(value)
|
function UI.TextEntry:setValue(value)
|
||||||
self.value = value
|
self.value = value or ''
|
||||||
self.entry:unmark()
|
self.entry:unmark()
|
||||||
self.entry.value = tostring(value)
|
self.entry.value = tostring(value)
|
||||||
self.entry:updateScroll()
|
self.entry:updateScroll()
|
||||||
|
Loading…
Reference in New Issue
Block a user