#243 changed rectangle to use content window, significant simplification of offset logic, improved delete rendering
This commit is contained in:
parent
de9cb3bd3a
commit
4c35233289
@ -20,7 +20,7 @@ local sounder = require("coordinator.sounder")
|
|||||||
|
|
||||||
local apisessions = require("coordinator.session.apisessions")
|
local apisessions = require("coordinator.session.apisessions")
|
||||||
|
|
||||||
local COORDINATOR_VERSION = "v0.15.4"
|
local COORDINATOR_VERSION = "v0.15.5"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
|||||||
@ -12,8 +12,6 @@ local element = {}
|
|||||||
---@field id? string element id
|
---@field id? string element id
|
||||||
---@field x? integer 1 if omitted
|
---@field x? integer 1 if omitted
|
||||||
---@field y? integer next line if omitted
|
---@field y? integer next line if omitted
|
||||||
---@field offset_x? integer 0 if omitted
|
|
||||||
---@field offset_y? integer 0 if omitted
|
|
||||||
---@field width? integer parent width if omitted
|
---@field width? integer parent width if omitted
|
||||||
---@field height? integer parent height if omitted
|
---@field height? integer parent height if omitted
|
||||||
---@field gframe? graphics_frame frame instead of x/y/width/height
|
---@field gframe? graphics_frame frame instead of x/y/width/height
|
||||||
@ -103,10 +101,8 @@ function element.new(args)
|
|||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
-- prepare the template
|
-- prepare the template
|
||||||
---@param offset_x integer x offset
|
|
||||||
---@param offset_y integer y offset
|
|
||||||
---@param next_y integer next line if no y was provided
|
---@param next_y integer next line if no y was provided
|
||||||
function protected.prepare_template(offset_x, offset_y, next_y)
|
function protected.prepare_template(next_y)
|
||||||
-- get frame coordinates/size
|
-- get frame coordinates/size
|
||||||
if args.gframe ~= nil then
|
if args.gframe ~= nil then
|
||||||
protected.frame.x = args.gframe.x
|
protected.frame.x = args.gframe.x
|
||||||
@ -116,36 +112,18 @@ function element.new(args)
|
|||||||
else
|
else
|
||||||
local w, h = self.p_window.getSize()
|
local w, h = self.p_window.getSize()
|
||||||
protected.frame.x = args.x or 1
|
protected.frame.x = args.x or 1
|
||||||
|
|
||||||
if args.parent ~= nil then
|
|
||||||
protected.frame.y = args.y or (next_y - offset_y)
|
|
||||||
else
|
|
||||||
protected.frame.y = args.y or next_y
|
protected.frame.y = args.y or next_y
|
||||||
end
|
|
||||||
|
|
||||||
protected.frame.w = args.width or w
|
protected.frame.w = args.width or w
|
||||||
protected.frame.h = args.height or h
|
protected.frame.h = args.height or h
|
||||||
end
|
end
|
||||||
|
|
||||||
-- inner offsets
|
|
||||||
if args.offset_x ~= nil then self.child_offset.x = args.offset_x end
|
|
||||||
if args.offset_y ~= nil then self.child_offset.y = args.offset_y end
|
|
||||||
|
|
||||||
-- adjust window frame if applicable
|
-- adjust window frame if applicable
|
||||||
local f = protected.frame
|
local f = protected.frame
|
||||||
local x = f.x
|
|
||||||
local y = f.y
|
|
||||||
|
|
||||||
-- apply offsets
|
|
||||||
if args.parent ~= nil then
|
if args.parent ~= nil then
|
||||||
-- constrain to parent inner width/height
|
-- constrain to parent inner width/height
|
||||||
local w, h = self.p_window.getSize()
|
local w, h = self.p_window.getSize()
|
||||||
f.w = math.min(f.w, w - ((2 * offset_x) + (f.x - 1)))
|
f.w = math.min(f.w, w - (f.x - 1))
|
||||||
f.h = math.min(f.h, h - ((2 * offset_y) + (f.y - 1)))
|
f.h = math.min(f.h, h - (f.y - 1))
|
||||||
|
|
||||||
-- offset x/y
|
|
||||||
f.x = x + offset_x
|
|
||||||
f.y = y + offset_y
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check frame
|
-- check frame
|
||||||
@ -304,7 +282,7 @@ function element.new(args)
|
|||||||
|
|
||||||
-- prepare the template
|
-- prepare the template
|
||||||
if args.parent == nil then
|
if args.parent == nil then
|
||||||
protected.prepare_template(0, 0, 1)
|
protected.prepare_template(1)
|
||||||
else
|
else
|
||||||
self.id = args.parent.__add_child(args.id, protected)
|
self.id = args.parent.__add_child(args.id, protected)
|
||||||
end
|
end
|
||||||
@ -319,14 +297,16 @@ function element.new(args)
|
|||||||
|
|
||||||
-- delete this element (hide and unsubscribe from PSIL)
|
-- delete this element (hide and unsubscribe from PSIL)
|
||||||
function public.delete()
|
function public.delete()
|
||||||
-- grab parent fg/bg so we can clear cleanly
|
local fg_bg = protected.fg_bg
|
||||||
|
|
||||||
if args.parent ~= nil then
|
if args.parent ~= nil then
|
||||||
local fg_bg = args.parent.get_fg_bg()
|
-- grab parent fg/bg so we can clear cleanly as a child element
|
||||||
protected.window.setBackgroundColor(fg_bg.bkg)
|
fg_bg = args.parent.get_fg_bg()
|
||||||
protected.window.setTextColor(fg_bg.fgd)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- clear, hide, and stop animations
|
-- clear, hide, and stop animations
|
||||||
|
protected.window.setBackgroundColor(fg_bg.bkg)
|
||||||
|
protected.window.setTextColor(fg_bg.fgd)
|
||||||
protected.window.clear()
|
protected.window.clear()
|
||||||
public.hide()
|
public.hide()
|
||||||
|
|
||||||
@ -351,12 +331,7 @@ function element.new(args)
|
|||||||
---@param child graphics_base
|
---@param child graphics_base
|
||||||
---@return integer|string key
|
---@return integer|string key
|
||||||
function public.__add_child(key, child)
|
function public.__add_child(key, child)
|
||||||
-- offset first automatic placement
|
child.prepare_template(self.next_y)
|
||||||
if self.next_y <= self.child_offset.y then
|
|
||||||
self.next_y = self.child_offset.y + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
child.prepare_template(self.child_offset.x, self.child_offset.y, self.next_y)
|
|
||||||
|
|
||||||
self.next_y = child.frame.y + child.frame.h
|
self.next_y = child.frame.y + child.frame.h
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ local element = require("graphics.element")
|
|||||||
|
|
||||||
---@class displaybox_args
|
---@class displaybox_args
|
||||||
---@field window table
|
---@field window table
|
||||||
|
---@field id? string element id
|
||||||
---@field x? integer 1 if omitted
|
---@field x? integer 1 if omitted
|
||||||
---@field y? integer 1 if omitted
|
---@field y? integer 1 if omitted
|
||||||
---@field width? integer parent width if omitted
|
---@field width? integer parent width if omitted
|
||||||
@ -15,6 +16,7 @@ local element = require("graphics.element")
|
|||||||
-- new root display box
|
-- new root display box
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
---@param args displaybox_args
|
---@param args displaybox_args
|
||||||
|
---@return graphics_element element, element_id id
|
||||||
local function displaybox(args)
|
local function displaybox(args)
|
||||||
-- create new graphics element base object
|
-- create new graphics element base object
|
||||||
return element.new(args).complete()
|
return element.new(args).complete()
|
||||||
|
|||||||
@ -31,27 +31,35 @@ local function rectangle(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- offset children
|
-- offset children
|
||||||
|
local offset_x = 0
|
||||||
|
local offset_y = 0
|
||||||
if args.border ~= nil then
|
if args.border ~= nil then
|
||||||
args.offset_x = args.border.width
|
offset_x = args.border.width
|
||||||
args.offset_y = args.border.width
|
offset_y = args.border.width
|
||||||
|
|
||||||
-- slightly different y offset if the border is set to even
|
-- slightly different y offset if the border is set to even
|
||||||
if args.border.even then
|
if args.border.even then
|
||||||
local width_x2 = (2 * args.border.width)
|
local width_x2 = (2 * args.border.width)
|
||||||
args.offset_y = math.floor(width_x2 / 3) + util.trinary(width_x2 % 3 > 0, 1, 0)
|
offset_y = math.floor(width_x2 / 3) + util.trinary(width_x2 % 3 > 0, 1, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create new graphics element base object
|
-- create new graphics element base object
|
||||||
local e = element.new(args)
|
local e = element.new(args)
|
||||||
|
|
||||||
|
-- create content window for child elements
|
||||||
|
e.content_window = window.create(e.window, 1 + offset_x, 1 + offset_y, e.frame.w - (2 * offset_x), e.frame.h - (2 * offset_y))
|
||||||
|
e.content_window.setBackgroundColor(e.fg_bg.bkg)
|
||||||
|
e.content_window.setTextColor(e.fg_bg.fgd)
|
||||||
|
e.content_window.clear()
|
||||||
|
|
||||||
-- draw bordered box if requested
|
-- draw bordered box if requested
|
||||||
-- element constructor will have drawn basic colored rectangle regardless
|
-- element constructor will have drawn basic colored rectangle regardless
|
||||||
if args.border ~= nil then
|
if args.border ~= nil then
|
||||||
e.window.setCursorPos(1, 1)
|
e.window.setCursorPos(1, 1)
|
||||||
|
|
||||||
local border_width = args.offset_x
|
local border_width = offset_x
|
||||||
local border_height = args.offset_y
|
local border_height = offset_y
|
||||||
local border_blit = colors.toBlit(args.border.color)
|
local border_blit = colors.toBlit(args.border.color)
|
||||||
local width_x2 = border_width * 2
|
local width_x2 = border_width * 2
|
||||||
local inner_width = e.frame.w - width_x2
|
local inner_width = e.frame.w - width_x2
|
||||||
|
|||||||
@ -17,7 +17,7 @@ local coreio = require("pocket.coreio")
|
|||||||
local pocket = require("pocket.pocket")
|
local pocket = require("pocket.pocket")
|
||||||
local renderer = require("pocket.renderer")
|
local renderer = require("pocket.renderer")
|
||||||
|
|
||||||
local POCKET_VERSION = "alpha-v0.3.4"
|
local POCKET_VERSION = "alpha-v0.3.5"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
|||||||
@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
|
|||||||
local renderer = require("reactor-plc.renderer")
|
local renderer = require("reactor-plc.renderer")
|
||||||
local threads = require("reactor-plc.threads")
|
local threads = require("reactor-plc.threads")
|
||||||
|
|
||||||
local R_PLC_VERSION = "v1.3.4"
|
local R_PLC_VERSION = "v1.3.5"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
|||||||
@ -28,7 +28,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
|||||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||||
|
|
||||||
local RTU_VERSION = "v1.2.4"
|
local RTU_VERSION = "v1.2.5"
|
||||||
|
|
||||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||||
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
||||||
|
|||||||
@ -19,7 +19,7 @@ local supervisor = require("supervisor.supervisor")
|
|||||||
|
|
||||||
local svsessions = require("supervisor.session.svsessions")
|
local svsessions = require("supervisor.session.svsessions")
|
||||||
|
|
||||||
local SUPERVISOR_VERSION = "v0.16.4"
|
local SUPERVISOR_VERSION = "v0.16.5"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user