From d3f28a68820d364417b85767a879518dd93669da Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 19 Jun 2022 11:35:17 -0400 Subject: [PATCH] #75 handle edge case on rectangle border width, renamed inner_* to offset_* --- graphics/element.lua | 8 ++++---- graphics/elements/rectangle.lua | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/graphics/element.lua b/graphics/element.lua index 23cee8a..662570d 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -13,8 +13,8 @@ local element = {} ---@field parent? graphics_element ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ----@field inner_x? integer 0 if omitted ----@field inner_y? integer 0 if omitted +---@field offset_x? integer 0 if omitted +---@field offset_y? integer 0 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 @@ -66,8 +66,8 @@ function element.new(args) end -- inner offsets - if args.inner_x ~= nil then self.child_offset.x = args.inner_x end - if args.inner_y ~= nil then self.child_offset.y = args.inner_y end + 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") diff --git a/graphics/elements/rectangle.lua b/graphics/elements/rectangle.lua index 69452b5..9e8c3ec 100644 --- a/graphics/elements/rectangle.lua +++ b/graphics/elements/rectangle.lua @@ -19,13 +19,13 @@ local element = require("graphics.element") local function rectangle(args) -- offset children if args.border ~= nil then - args.inner_x = args.border.width - args.inner_y = args.border.width + args.offsetx = args.border.width + args.offsety = 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.inner_y = (width_x2 // 3) + util.trinary(width_x2 % 3 > 0, 1, 0) + args.offsety = (width_x2 // 3) + util.trinary(width_x2 % 3 > 0, 1, 0) end end @@ -37,7 +37,8 @@ local function rectangle(args) if args.border ~= nil then e.window.setCursorPos(1, 1) - local border_width = args.border.width + local border_width = args.offsetx + local border_height = args.offsety local border_blit = colors.toBlit(args.border.color) local width_x2 = border_width * 2 local inner_width = e.frame.w - width_x2 @@ -73,9 +74,9 @@ local function rectangle(args) -- draw rectangle with borders for y = 1, e.frame.h do e.window.setCursorPos(1, y) - if y <= border_width then + if y <= border_height then -- partial pixel fill - if args.border.even and y == border_width then + if args.border.even and y == border_height then if width_x2 % 3 == 1 then e.window.blit(p_b, p_inv_bg, p_inv_fg) elseif width_x2 % 3 == 2 then