mirror of
https://github.com/kepler155c/opus
synced 2025-01-16 18:32:52 +00:00
sliders in forms + form component setValue (hopefully didnt break anything)
This commit is contained in:
parent
51e40a1dd7
commit
c43fe19f1d
@ -29,10 +29,11 @@ function UI.Form:setValues(values)
|
||||
self.values = values
|
||||
for _,child in pairs(self.children) do
|
||||
if child.formKey then
|
||||
-- this should be child:setValue(self.values[child.formKey])
|
||||
-- so chooser can set default choice if null
|
||||
-- null should be valid as well
|
||||
child.value = self.values[child.formKey] or ''
|
||||
if child.setValue then
|
||||
child:setValue(self.values[child.formKey])
|
||||
else
|
||||
child.value = self.values[child.formKey] or ''
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,13 +12,31 @@ UI.Slider.defaults = {
|
||||
barColor = colors.gray,
|
||||
sliderChar = UI.extChars and '\143' or '\124',
|
||||
sliderColor = colors.blue,
|
||||
leftBorder = '\141',
|
||||
rightBorder = '\142',
|
||||
sliderFocusColor = colors.lightBlue,
|
||||
leftBorder = UI.extChars and '\141' or '\124',
|
||||
rightBorder = UI.extChars and '\142' or '\124',
|
||||
value = 0,
|
||||
min = 0,
|
||||
max = 100,
|
||||
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()
|
||||
local range = self.max - self.min
|
||||
local perc = (self.value - self.min) / range
|
||||
@ -34,7 +52,7 @@ function UI.Slider:draw()
|
||||
table.insert(bar, filler)
|
||||
end
|
||||
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
|
||||
|
||||
function UI.Slider:eventHandler(event)
|
||||
@ -44,5 +62,16 @@ function UI.Slider:eventHandler(event)
|
||||
self.value = self.min + (i * range)
|
||||
self:emit({ type = self.event, value = self.value, element = self })
|
||||
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
|
||||
|
@ -25,7 +25,7 @@ UI.TextEntry.defaults = {
|
||||
}
|
||||
}
|
||||
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 })
|
||||
end
|
||||
|
||||
@ -35,7 +35,7 @@ function UI.TextEntry:layout()
|
||||
end
|
||||
|
||||
function UI.TextEntry:setValue(value)
|
||||
self.value = value
|
||||
self.value = value or ''
|
||||
self.entry:unmark()
|
||||
self.entry.value = tostring(value)
|
||||
self.entry:updateScroll()
|
||||
|
Loading…
Reference in New Issue
Block a user