diff --git a/graphics/element.lua b/graphics/element.lua index cd69dd4..77012fd 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -45,6 +45,7 @@ local element = {} ---|colormap_args ---|displaybox_args ---|div_args +---|multipane_args ---|pipenet_args ---|rectangle_args ---|textbox_args diff --git a/graphics/elements/multipane.lua b/graphics/elements/multipane.lua new file mode 100644 index 0000000..8e25bab --- /dev/null +++ b/graphics/elements/multipane.lua @@ -0,0 +1,42 @@ +-- Multi-Pane Display Graphics Element + +local element = require("graphics.element") + +---@class multipane_args +---@field panes table panes to swap between +---@field parent graphics_element +---@field id? string element id +---@field x? integer 1 if omitted +---@field y? integer 1 if omitted +---@field width? integer parent width if omitted +---@field height? integer parent height if omitted +---@field gframe? graphics_frame frame instead of x/y/width/height +---@field fg_bg? cpair foreground/background colors + +-- new multipane element +---@nodiscard +---@param args multipane_args +---@return graphics_element element, element_id id +local function multipane(args) + assert(type(args.panes) == "table", "graphics.elements.multipane: panes is a required field") + + -- create new graphics element base object + local e = element.new(args) + + -- select which pane is shown + ---@param value integer pane to show + function e.set_value(value) + if (e.value ~= value) and (value > 0) and (value <= #args.panes) then + e.value = value + + for i = 1, #args.panes do args.panes[i].hide() end + args.panes[value].show() + end + end + + e.set_value(1) + + return e.get() +end + +return multipane diff --git a/pocket/startup.lua b/pocket/startup.lua index 4e820b1..90837d3 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -16,7 +16,7 @@ local config = require("pocket.config") local pocket = require("pocket.pocket") local renderer = require("pocket.renderer") -local POCKET_VERSION = "alpha-v0.1.0" +local POCKET_VERSION = "alpha-v0.1.1" -- local print = util.print local println = util.println diff --git a/pocket/ui/components/boiler_page.lua b/pocket/ui/components/boiler_page.lua new file mode 100644 index 0000000..204896a --- /dev/null +++ b/pocket/ui/components/boiler_page.lua @@ -0,0 +1,22 @@ +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.div") +local TextBox = require("graphics.elements.textbox") + +local cpair = core.graphics.cpair + +local TEXT_ALIGN = core.graphics.TEXT_ALIGN + +-- new boiler page view +---@param root graphics_element parent +local function new_view(root) + local main = Div{parent=root,x=1,y=1} + + TextBox{parent=main,text="BOILERS",x=1,y=1,height=1,alignment=TEXT_ALIGN.CENTER} + + return main +end + +return new_view diff --git a/pocket/ui/components/home_page.lua b/pocket/ui/components/home_page.lua new file mode 100644 index 0000000..6715f19 --- /dev/null +++ b/pocket/ui/components/home_page.lua @@ -0,0 +1,22 @@ +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.div") +local TextBox = require("graphics.elements.textbox") + +local cpair = core.graphics.cpair + +local TEXT_ALIGN = core.graphics.TEXT_ALIGN + +-- new home page view +---@param root graphics_element parent +local function new_view(root) + local main = Div{parent=root,x=1,y=1} + + TextBox{parent=main,text="HOME",x=1,y=1,height=1,alignment=TEXT_ALIGN.CENTER} + + return main +end + +return new_view diff --git a/pocket/ui/components/reactor_page.lua b/pocket/ui/components/reactor_page.lua new file mode 100644 index 0000000..4775d81 --- /dev/null +++ b/pocket/ui/components/reactor_page.lua @@ -0,0 +1,22 @@ +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.div") +local TextBox = require("graphics.elements.textbox") + +local cpair = core.graphics.cpair + +local TEXT_ALIGN = core.graphics.TEXT_ALIGN + +-- new reactor page view +---@param root graphics_element parent +local function new_view(root) + local main = Div{parent=root,x=1,y=1} + + TextBox{parent=main,text="REACTOR",x=1,y=1,height=1,alignment=TEXT_ALIGN.CENTER} + + return main +end + +return new_view diff --git a/pocket/ui/components/turbine_page.lua b/pocket/ui/components/turbine_page.lua new file mode 100644 index 0000000..9c060cc --- /dev/null +++ b/pocket/ui/components/turbine_page.lua @@ -0,0 +1,22 @@ +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.div") +local TextBox = require("graphics.elements.textbox") + +local cpair = core.graphics.cpair + +local TEXT_ALIGN = core.graphics.TEXT_ALIGN + +-- new turbine page view +---@param root graphics_element parent +local function new_view(root) + local main = Div{parent=root,x=1,y=1} + + TextBox{parent=main,text="TURBINES",x=1,y=1,height=1,alignment=TEXT_ALIGN.CENTER} + + return main +end + +return new_view diff --git a/pocket/ui/components/unit_page.lua b/pocket/ui/components/unit_page.lua new file mode 100644 index 0000000..60c91b1 --- /dev/null +++ b/pocket/ui/components/unit_page.lua @@ -0,0 +1,22 @@ +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.div") +local TextBox = require("graphics.elements.textbox") + +local cpair = core.graphics.cpair + +local TEXT_ALIGN = core.graphics.TEXT_ALIGN + +-- new unit page view +---@param root graphics_element parent +local function new_view(root) + local main = Div{parent=root,x=1,y=1} + + TextBox{parent=main,text="UNITS",x=1,y=1,height=1,alignment=TEXT_ALIGN.CENTER} + + return main +end + +return new_view diff --git a/pocket/ui/main.lua b/pocket/ui/main.lua index 94f6ca5..3360b9b 100644 --- a/pocket/ui/main.lua +++ b/pocket/ui/main.lua @@ -8,11 +8,18 @@ local style = require("pocket.ui.style") local conn_waiting = require("pocket.ui.components.conn_waiting") +local home_page = require("pocket.ui.components.home_page") +local unit_page = require("pocket.ui.components.unit_page") +local reactor_page = require("pocket.ui.components.reactor_page") +local boiler_page = require("pocket.ui.components.boiler_page") +local turbine_page = require("pocket.ui.components.turbine_page") + local core = require("graphics.core") local ColorMap = require("graphics.elements.colormap") local DisplayBox = require("graphics.elements.displaybox") local Div = require("graphics.elements.div") +local MultiPane = require("graphics.elements.multipane") local TextBox = require("graphics.elements.textbox") local PushButton = require("graphics.elements.controls.push_button") @@ -59,7 +66,19 @@ local function init(monitor) } } - local sidebar = Sidebar{parent=main,x=1,y=2,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=function()end} + local mp_div = Div{parent=main,x=4,y=2} + + local pane_1 = home_page(mp_div) + local pane_2 = unit_page(mp_div) + local pane_3 = reactor_page(mp_div) + local pane_4 = boiler_page(mp_div) + local pane_5 = turbine_page(mp_div) + + local panes = { pane_1, pane_2, pane_3, pane_4, pane_5 } + + local multipane = MultiPane{parent=mp_div,x=1,y=1,panes=panes} + + local sidebar = Sidebar{parent=main,x=1,y=2,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=multipane.set_value} return main end