mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
fixes to offsets and width calculations, init hbar to 0
This commit is contained in:
parent
e54d5b3d85
commit
47599b8ff6
@ -69,23 +69,31 @@ function element.new(args)
|
||||
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
|
||||
|
||||
-- check frame
|
||||
assert(protected.frame.x >= 1, "graphics.element: frame x not >= 1")
|
||||
assert(protected.frame.y >= 1, "graphics.element: frame y not >= 1")
|
||||
assert(protected.frame.w >= 1, "graphics.element: frame width not >= 1")
|
||||
assert(protected.frame.h >= 1, "graphics.element: frame height not >= 1")
|
||||
|
||||
-- create window
|
||||
-- adjust window frame if applicable
|
||||
local f = protected.frame
|
||||
local x = f.x
|
||||
local y = f.y
|
||||
|
||||
-- apply offsets
|
||||
if args.parent ~= nil then
|
||||
-- offset x/y
|
||||
local offset_x, offset_y = args.parent.get_offset()
|
||||
x = x + offset_x
|
||||
y = y + offset_y
|
||||
|
||||
-- constrain to parent inner width/height
|
||||
local w, h = self.p_window.getSize()
|
||||
f.w = math.min(f.w, w - (2 * offset_x) - f.x)
|
||||
f.y = math.min(f.h, h - (2 * offset_y) - f.y)
|
||||
end
|
||||
|
||||
-- check frame
|
||||
assert(f.x >= 1, "graphics.element: frame x not >= 1")
|
||||
assert(f.y >= 1, "graphics.element: frame y not >= 1")
|
||||
assert(f.w >= 1, "graphics.element: frame width not >= 1")
|
||||
assert(f.h >= 1, "graphics.element: frame height not >= 1")
|
||||
|
||||
-- create window
|
||||
protected.window = window.create(self.p_window, x, y, f.w, f.h, true)
|
||||
|
||||
-- init colors
|
||||
|
@ -93,6 +93,9 @@ local function hbar(args)
|
||||
end
|
||||
end
|
||||
|
||||
-- initialize to 0
|
||||
e.on_update(0)
|
||||
|
||||
return e.get()
|
||||
end
|
||||
|
||||
|
@ -19,13 +19,13 @@ local element = require("graphics.element")
|
||||
local function rectangle(args)
|
||||
-- offset children
|
||||
if args.border ~= nil then
|
||||
args.offsetx = args.border.width
|
||||
args.offsety = args.border.width
|
||||
args.offset_x = args.border.width
|
||||
args.offset_y = args.border.width
|
||||
|
||||
-- slightly different y offset if the border is set to even
|
||||
if args.border.even then
|
||||
local width_x2 = (2 * args.border.width)
|
||||
args.offsety = (width_x2 // 3) + util.trinary(width_x2 % 3 > 0, 1, 0)
|
||||
args.offset_y = math.floor(width_x2 / 3) + util.trinary(width_x2 % 3 > 0, 1, 0)
|
||||
end
|
||||
end
|
||||
|
||||
@ -37,8 +37,8 @@ local function rectangle(args)
|
||||
if args.border ~= nil then
|
||||
e.window.setCursorPos(1, 1)
|
||||
|
||||
local border_width = args.offsetx
|
||||
local border_height = args.offsety
|
||||
local border_width = args.offset_x
|
||||
local border_height = args.offset_y
|
||||
local border_blit = colors.toBlit(args.border.color)
|
||||
local width_x2 = border_width * 2
|
||||
local inner_width = e.frame.w - width_x2
|
||||
|
Loading…
Reference in New Issue
Block a user