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