fixed reposition not repositioning frame for mouse events

This commit is contained in:
Mikayla Fischler 2023-10-21 13:58:42 -04:00
parent 7b374f8618
commit d477b33774
2 changed files with 23 additions and 2 deletions

View File

@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
local core = {} local core = {}
core.version = "2.0.5" core.version = "2.0.6"
core.flasher = flasher core.flasher = flasher
core.events = events core.events = events

View File

@ -91,6 +91,8 @@ function element.new(args, child_offset_x, child_offset_y)
p_window = nil, ---@type table p_window = nil, ---@type table
position = events.new_coord_2d(1, 1), position = events.new_coord_2d(1, 1),
bounds = { x1 = 1, y1 = 1, x2 = 1, y2 = 1 }, ---@class element_bounds 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_y = 1, -- next child y coordinate
next_id = 0, -- next child ID next_id = 0, -- next child ID
subscriptions = {}, 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 offset_y integer y offset for mouse events
---@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(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 -- 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
@ -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 -- 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 x integer x position relative to parent frame
---@param y integer y 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 -- -- FUNCTION CALLBACKS --