mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
sidebar updates
This commit is contained in:
parent
0c6c7bf9a5
commit
3cd832ca20
@ -96,21 +96,23 @@ local function sidebar(args)
|
|||||||
if e.enabled then
|
if e.enabled then
|
||||||
local cur_idx = find_tab(event.current.y)
|
local cur_idx = find_tab(event.current.y)
|
||||||
local ini_idx = find_tab(event.initial.y)
|
local ini_idx = find_tab(event.initial.y)
|
||||||
|
local tab = tabs[cur_idx]
|
||||||
|
|
||||||
if tabs[cur_idx] ~= nil then
|
-- handle press if a callback was provided
|
||||||
|
if tab ~= nil and type(tab.callback) == "function" then
|
||||||
if event.type == MOUSE_CLICK.TAP then
|
if event.type == MOUSE_CLICK.TAP then
|
||||||
e.value = cur_idx
|
e.value = cur_idx
|
||||||
draw(true)
|
draw(true)
|
||||||
-- show as unpressed in 0.25 seconds
|
-- show as unpressed in 0.25 seconds
|
||||||
tcd.dispatch(0.25, function () draw(false) end)
|
tcd.dispatch(0.25, function () draw(false) end)
|
||||||
tabs[cur_idx].callback()
|
tab.callback()
|
||||||
elseif event.type == MOUSE_CLICK.DOWN then
|
elseif event.type == MOUSE_CLICK.DOWN then
|
||||||
draw(true, cur_idx)
|
draw(true, cur_idx)
|
||||||
elseif event.type == MOUSE_CLICK.UP then
|
elseif event.type == MOUSE_CLICK.UP then
|
||||||
if cur_idx == ini_idx and e.in_frame_bounds(event.current.x, event.current.y) then
|
if cur_idx == ini_idx and e.in_frame_bounds(event.current.x, event.current.y) then
|
||||||
e.value = cur_idx
|
e.value = cur_idx
|
||||||
draw(false)
|
draw(false)
|
||||||
tabs[cur_idx].callback()
|
tab.callback()
|
||||||
else draw(false) end
|
else draw(false) end
|
||||||
end
|
end
|
||||||
elseif event.type == MOUSE_CLICK.UP then
|
elseif event.type == MOUSE_CLICK.UP then
|
||||||
@ -126,7 +128,7 @@ local function sidebar(args)
|
|||||||
draw(false)
|
draw(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update the sidebar nav options
|
-- update the sidebar navigation options
|
||||||
---@param items table sidebar entries
|
---@param items table sidebar entries
|
||||||
function e.on_update(items)
|
function e.on_update(items)
|
||||||
local next_y = 1
|
local next_y = 1
|
||||||
@ -139,12 +141,12 @@ local function sidebar(args)
|
|||||||
|
|
||||||
---@class sidebar_tab
|
---@class sidebar_tab
|
||||||
local entry = {
|
local entry = {
|
||||||
y_start = next_y,
|
y_start = next_y, ---@type integer
|
||||||
y_end = next_y + height - 1,
|
y_end = next_y + height - 1, ---@type integer
|
||||||
tall = item.tall,
|
tall = item.tall, ---@type boolean
|
||||||
label = item.label,
|
label = item.label, ---@type string
|
||||||
color = item.color,
|
color = item.color, ---@type cpair
|
||||||
callback = item.callback
|
callback = item.callback ---@type function|nil
|
||||||
}
|
}
|
||||||
|
|
||||||
next_y = next_y + height
|
next_y = next_y + height
|
||||||
|
Loading…
Reference in New Issue
Block a user