From 375b7f680ef60d386a931060613329eb55a3bf36 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 5 Jun 2024 19:38:22 -0400 Subject: [PATCH] fixes to graphics constraint logic --- graphics/element.lua | 2 +- graphics/elements/textbox.lua | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/graphics/element.lua b/graphics/element.lua index 6f859ab..d086408 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -230,7 +230,7 @@ function element.new(args, constraint, child_offset_x, child_offset_y) if type(constraint) == "function" then -- constrain per provided constraint function (can only get smaller than available space) - w, h = constraint(w, h) + w, h = constraint(f) f.w = math.min(f.w, w) f.h = math.min(f.h, h) end diff --git a/graphics/elements/textbox.lua b/graphics/elements/textbox.lua index 5a02579..0761471 100644 --- a/graphics/elements/textbox.lua +++ b/graphics/elements/textbox.lua @@ -33,7 +33,13 @@ local function textbox(args) -- provide a constraint condition to element creation to prevent an pointlessly tall text box ---@param frame graphics_frame local function constrain(frame) - return frame.w, math.max(args.height, math.max(1, #util.strwrap(args.text, frame.w))) + local new_height = math.max(1, #util.strwrap(args.text, frame.w)) + + if args.height then + new_height = math.max(frame.h, new_height) + end + + return frame.w, new_height end -- create new graphics element base object