fix the math

develop
Myk Taylor 2022-12-13 12:39:17 -08:00
parent 38a3bec953
commit 3f43f72731
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 12 additions and 9 deletions

@ -115,23 +115,25 @@ local function Panel_drag_frame(self, mouse_pos)
local max_height = parent_rect.height - (bound_rect.y2-frame_rect.y1+1) local max_height = parent_rect.height - (bound_rect.y2-frame_rect.y1+1)
if frame.t or not frame.b then if frame.t or not frame.b then
local min_pos = frame_rect.y1 - bound_rect.y1 local min_pos = frame_rect.y1 - bound_rect.y1
frame.t = math.max(min_pos, local requested_pos = mouse_pos.y - parent_rect.y1 - offset.y
math.min(max_height, mouse_pos.y - parent_rect.y1 - offset.y)) frame.t = math.max(min_pos, math.min(max_height, requested_pos))
end end
if frame.b or not frame.t then if frame.b or not frame.t then
local min_pos = bound_rect.y2 - frame_rect.y2 local min_pos = bound_rect.y2 - frame_rect.y2
frame.b = math.max(min_pos, local requested_pos = parent_rect.y2 - mouse_pos.y + offset.y -
math.min(max_height, parent_rect.y2 - mouse_pos.y - offset.y)) (frame_rect.y2 - frame_rect.y1)
frame.b = math.max(min_pos, math.min(max_height, requested_pos))
end end
if frame.l or not frame.r then if frame.l or not frame.r then
local min_pos = frame_rect.x1 - bound_rect.x1 local min_pos = frame_rect.x1 - bound_rect.x1
frame.l = math.max(min_pos, local requested_pos = mouse_pos.x - parent_rect.x1 - offset.x
math.min(max_width, mouse_pos.x - parent_rect.x1 - offset.x)) frame.l = math.max(min_pos, math.min(max_width, requested_pos))
end end
if frame.r or not frame.l then if frame.r or not frame.l then
local min_pos = bound_rect.x2 - frame_rect.x2 local min_pos = bound_rect.x2 - frame_rect.x2
frame.r = math.max(min_pos, local requested_pos = parent_rect.x2 - mouse_pos.x + offset.x -
math.min(max_width, parent_rect.x2 - mouse_pos.x - offset.x)) (frame_rect.x2 - frame_rect.x1)
frame.r = math.max(min_pos, math.min(max_width, requested_pos))
end end
return frame return frame
end end
@ -164,7 +166,8 @@ end
function Panel:onInput(keys) function Panel:onInput(keys)
if self.keyboard_drag then if self.keyboard_drag then
if keys.SELECT or keys.LEAVESCREEN then if keys.SELECT or keys.LEAVESCREEN then
Panel_end_drag(self, nil, keys.SELECT) Panel_end_drag(self, keys.LEAVESCREEN and self.saved_frame or nil,
not not keys.SELECT)
return true return true
end end
for code in pairs(keys) do for code in pairs(keys) do