From d477b33774e4ef3e22e970ac2df20d7e6ec3a125 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 21 Oct 2023 13:58:42 -0400 Subject: [PATCH] fixed reposition not repositioning frame for mouse events --- graphics/core.lua | 2 +- graphics/element.lua | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/graphics/core.lua b/graphics/core.lua index a6fead5..abafb44 100644 --- a/graphics/core.lua +++ b/graphics/core.lua @@ -7,7 +7,7 @@ local flasher = require("graphics.flasher") local core = {} -core.version = "2.0.5" +core.version = "2.0.6" core.flasher = flasher core.events = events diff --git a/graphics/element.lua b/graphics/element.lua index 517e230..6debaf4 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -91,6 +91,8 @@ function element.new(args, child_offset_x, child_offset_y) p_window = nil, ---@type table position = events.new_coord_2d(1, 1), bounds = { x1 = 1, y1 = 1, x2 = 1, y2 = 1 }, ---@class element_bounds + offset_x = 0, + offset_y = 0, next_y = 1, -- next child y coordinate next_id = 0, -- next child ID subscriptions = {}, @@ -194,6 +196,10 @@ function element.new(args, child_offset_x, child_offset_y) ---@param offset_y integer y offset for mouse events ---@param next_y integer next line if no y was provided function protected.prepare_template(offset_x, offset_y, next_y) + -- record offsets in case there is a reposition + self.offset_x = offset_x + self.offset_y = offset_y + -- get frame coordinates/size if args.gframe ~= nil then protected.frame.x = args.gframe.x @@ -694,7 +700,22 @@ function element.new(args, child_offset_x, child_offset_y) -- offsets relative to parent frame are where (1, 1) would be on top of the parent's top left corner ---@param x integer x position relative to parent frame ---@param y integer y position relative to parent frame - function public.reposition(x, y) protected.window.reposition(x, y) end + function public.reposition(x, y) + protected.window.reposition(x, y) + + -- record position + self.position.x, self.position.y = protected.window.getPosition() + + -- shift per parent child offset + self.position.x = self.position.x + self.offset_x + self.position.y = self.position.y + self.offset_y + + -- calculate mouse event bounds + self.bounds.x1 = self.position.x + self.bounds.x2 = self.position.x + protected.frame.w - 1 + self.bounds.y1 = self.position.y + self.bounds.y2 = self.position.y + protected.frame.h - 1 + end -- FUNCTION CALLBACKS --