mirror of
https://github.com/kepler155c/opus
synced 2025-01-16 10:25:42 +00:00
optionally show value for slider component - remove some unneeded limits for textEntries
This commit is contained in:
parent
51724ccd78
commit
c24411717a
@ -177,7 +177,6 @@ local Browser = UI.Page {
|
||||
formLabel = 'Program', formKey = 'value',
|
||||
shadowText = 'program',
|
||||
required = true,
|
||||
limit = 128,
|
||||
},
|
||||
add = UI.Button {
|
||||
x = -11, y = 1,
|
||||
|
@ -29,7 +29,6 @@ local page = UI.Page {
|
||||
prompt = UI.TextEntry {
|
||||
y = 2,
|
||||
shadowText = 'enter command',
|
||||
limit = 1024,
|
||||
accelerators = {
|
||||
enter = 'command_enter',
|
||||
up = 'history_back',
|
||||
|
@ -13,7 +13,6 @@ local aliasTab = UI.Tab {
|
||||
},
|
||||
path = UI.TextEntry {
|
||||
y = 3, x = 2, ex = -2,
|
||||
limit = 256,
|
||||
shadowText = 'Program path',
|
||||
accelerators = {
|
||||
enter = 'new_alias',
|
||||
|
@ -26,7 +26,6 @@ local tab = UI.Tab {
|
||||
},
|
||||
custom = UI.TextEntry {
|
||||
x = 13, ex = -3, y = 4,
|
||||
limit = 128,
|
||||
shadowText = 'File name',
|
||||
},
|
||||
button = UI.Button {
|
||||
|
@ -11,7 +11,6 @@ local tab = UI.Tab {
|
||||
},
|
||||
entry = UI.TextEntry {
|
||||
x = 3, y = 3, ex = -3,
|
||||
limit = 256,
|
||||
shadowText = 'enter new path',
|
||||
accelerators = {
|
||||
enter = 'update_path',
|
||||
|
@ -8,7 +8,6 @@ local tab = UI.Tab {
|
||||
tabClose = true,
|
||||
entry = UI.TextEntry {
|
||||
x = 2, y = 2, ex = -2,
|
||||
limit = 256,
|
||||
shadowText = 'Enter new require path',
|
||||
accelerators = {
|
||||
enter = 'update_path',
|
||||
|
@ -27,7 +27,6 @@ return settings and UI.Tab {
|
||||
form = UI.Form {
|
||||
y = 2,
|
||||
value = UI.TextEntry {
|
||||
limit = 256,
|
||||
formIndex = 1,
|
||||
formLabel = 'Value',
|
||||
formKey = 'value',
|
||||
|
@ -114,7 +114,7 @@ function Routine:resume(event, ...)
|
||||
if coroutine.status(self.co) == 'dead' then
|
||||
Array.removeByValue(kernel.routines, self)
|
||||
if self.onDestroy then
|
||||
self.onDestroy(self)
|
||||
pcall(self.onDestroy, self)
|
||||
end
|
||||
if #kernel.routines > 0 then
|
||||
switch(kernel.routines[1])
|
||||
|
@ -50,7 +50,6 @@ function UI.FileSelect:postInit()
|
||||
}
|
||||
self.path = UI.TextEntry {
|
||||
x = 2, y = -2, ex = -11,
|
||||
limit = 256,
|
||||
accelerators = {
|
||||
enter = 'path_enter',
|
||||
}
|
||||
|
@ -13,17 +13,21 @@ UI.Slider.defaults = {
|
||||
sliderFocusColor = 'lightBlue',
|
||||
leftBorder = UI.extChars and '\141' or '\124',
|
||||
rightBorder = UI.extChars and '\142' or '\124',
|
||||
labelWidth = 0,
|
||||
value = 0,
|
||||
min = 0,
|
||||
max = 100,
|
||||
event = 'slider_update',
|
||||
transform = function(v) return Util.round(v, 2) end,
|
||||
accelerators = {
|
||||
right = 'slide_right',
|
||||
left = 'slide_left',
|
||||
}
|
||||
}
|
||||
function UI.Slider:setValue(value)
|
||||
self.value = tonumber(value) or self.min
|
||||
self.value = self.transform(tonumber(value) or self.min)
|
||||
self.value = Util.clamp(self.value, self.min, self.max)
|
||||
self:draw()
|
||||
end
|
||||
|
||||
function UI.Slider:reset() -- form support
|
||||
@ -35,56 +39,69 @@ function UI.Slider:focus()
|
||||
self:draw()
|
||||
end
|
||||
|
||||
function UI.Slider:getSliderWidth()
|
||||
local labelWidth = self.labelWidth > 0 and self.labelWidth + 1
|
||||
return self.width - (labelWidth or 0)
|
||||
end
|
||||
|
||||
function UI.Slider:draw()
|
||||
local labelWidth = self.labelWidth > 0 and self.labelWidth + 1
|
||||
local width = self.width - (labelWidth or 0)
|
||||
local range = self.max - self.min
|
||||
local perc = (self.value - self.min) / range
|
||||
local progress = Util.clamp(1 + self.width * perc, 1, self.width)
|
||||
local progress = Util.clamp(1 + width * perc, 1, width)
|
||||
|
||||
local bar = { }
|
||||
for i = 1, self.width do
|
||||
local filler =
|
||||
i == 1 and self.leftBorder or
|
||||
i == self.width and self.rightBorder or
|
||||
self.barChar
|
||||
|
||||
table.insert(bar, filler)
|
||||
end
|
||||
self:write(1, 1, table.concat(bar), nil, self.barColor)
|
||||
local bar = self.leftBorder .. string.rep(self.barChar, width - 2) .. self.rightBorder
|
||||
self:write(1, 1, bar, nil, self.barColor)
|
||||
self:write(progress, 1, self.sliderChar, nil, self.focused and self.sliderFocusColor or self.sliderColor)
|
||||
if labelWidth then
|
||||
self:write(self.width - labelWidth + 2, 1, Util.widthify(tostring(self.value), self.labelWidth))
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Slider:eventHandler(event)
|
||||
if event.type == "mouse_down" or event.type == "mouse_drag" then
|
||||
|
||||
local pos = event.x - 1
|
||||
if event.type == 'mouse_down' then
|
||||
self.anchor = event.x - 1
|
||||
else
|
||||
pos = self.anchor + event.dx
|
||||
end
|
||||
|
||||
local range = self.max - self.min
|
||||
local i = pos / (self.width - 1)
|
||||
self.value = self.min + (i * range)
|
||||
local i = pos / (self:getSliderWidth() - 1)
|
||||
self:setValue(self.min + (i * range))
|
||||
self:emit({ type = self.event, value = self.value, element = self })
|
||||
self:draw()
|
||||
return true
|
||||
|
||||
elseif event.type == 'slide_left' or event.type == 'slide_right' then
|
||||
local range = self.max - self.min
|
||||
local step = range / self.width
|
||||
local step = range / (self:getSliderWidth() - 1)
|
||||
if event.type == 'slide_left' then
|
||||
self.value = Util.clamp(self.value - step, self.min, self.max)
|
||||
self:setValue(self.value - step)
|
||||
else
|
||||
self.value = Util.clamp(self.value + step, self.min, self.max)
|
||||
self:setValue(self.value + step)
|
||||
end
|
||||
self:emit({ type = self.event, value = self.value, element = self })
|
||||
self:draw()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Slider.example()
|
||||
return UI.Slider {
|
||||
return UI.Window {
|
||||
UI.Slider {
|
||||
y = 2, x = 2, ex = -2,
|
||||
min = 0, max = 1,
|
||||
},
|
||||
UI.Slider {
|
||||
y = 4, x = 2, ex = -2,
|
||||
min = -1, max = 1,
|
||||
labelWidth = 5,
|
||||
},
|
||||
UI.Slider {
|
||||
y = 6, x = 2, ex = -2,
|
||||
min = 0, max = 100,
|
||||
labelWidth = 3,
|
||||
transform = math.floor,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user