From c1b25d204568a3fa2d8b55aad06f08fc2664d89a Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 17 Nov 2021 17:23:48 -0600 Subject: [PATCH] Fixed centered text with unequal margins/paddings/border thicknesses being offset, fixed text wrapping using parents #width (which includes padding and margins) instead of the correct #content_width (which is only the parents content width; which the text is part of) --- lib/cyberarm_engine/ui/elements/text_block.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cyberarm_engine/ui/elements/text_block.rb b/lib/cyberarm_engine/ui/elements/text_block.rb index 7ba896e..519620f 100644 --- a/lib/cyberarm_engine/ui/elements/text_block.rb +++ b/lib/cyberarm_engine/ui/elements/text_block.rb @@ -47,8 +47,8 @@ module CyberarmEngine when :left @text.x = @style.border_thickness_left + @style.padding_left + @x when :center - @text.x = if @text.width <= outer_width - @x + outer_width / 2 - @text.width / 2 + @text.x = if @text.width <= width + @x + width / 2 - @text.width / 2 else # Act as left aligned @style.border_thickness_left + @style.padding_left + @x end @@ -61,7 +61,7 @@ module CyberarmEngine end def handle_text_wrapping(max_width) - max_width ||= @parent&.width + max_width ||= @parent&.content_width max_width ||= @x - (window.width + noncontent_width) wrap_behavior = style.text_wrap copy = @raw_text.to_s.dup