diff --git a/docs_md/changelog.md b/docs_md/changelog.md index fa31363..a9df50e 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -246,4 +246,5 @@ Have a good day. - `Button:set_enabled` has more priority than this to check button availability - The `check_function` should return _true_ of _false_. If true - button can be clicked - The `failure_callback`will be called if `check_function` will return false. It's callback for you if button is not available - - Example with `set_check_function` exists in general:buttons example collection \ No newline at end of file + - Example with `set_check_function` exists in general:buttons example collection +- **#107** Better scale text adjust by height for multiline text nodes (but still not perfect) \ No newline at end of file diff --git a/druid/base/text.lua b/druid/base/text.lua index f4f4c7d..bf844e2 100644 --- a/druid/base/text.lua +++ b/druid/base/text.lua @@ -78,19 +78,21 @@ local function update_text_area_size(self) local max_height = self.text_area.y local metrics = gui.get_text_metrics_from_node(self.node) - local cur_scale = gui.get_scale(self.node) local scale_modifier = max_width / metrics.width scale_modifier = math.min(scale_modifier, self.start_scale.x) - local scale_modifier_height = max_height / metrics.height - scale_modifier = math.min(scale_modifier, scale_modifier_height) + if self:is_multiline() then + local max_text_area_square = max_width * max_height + local cur_text_area_square = metrics.height * metrics.width * self.start_scale.x + scale_modifier = self.start_scale.x * math.sqrt(max_text_area_square / cur_text_area_square) + end if self._minimal_scale then scale_modifier = math.max(scale_modifier, self._minimal_scale) end - local new_scale = vmath.vector3(scale_modifier, scale_modifier, cur_scale.z) + local new_scale = vmath.vector3(scale_modifier, scale_modifier, self.start_scale.z) gui.set_scale(self.node, new_scale) self.scale = new_scale diff --git a/example/examples/texts/texts_general/texts_general.gui_script b/example/examples/texts/texts_general/texts_general.gui_script index d2e1e60..495a956 100644 --- a/example/examples/texts/texts_general/texts_general.gui_script +++ b/example/examples/texts/texts_general/texts_general.gui_script @@ -29,18 +29,18 @@ local function setup_texts(self) timer.delay(0.3, true, function() anchoring:set_pivot(pivots[pivot_index]) - pivot_index = pivot_index + 1 + pivot_index = pivot_index + 1 if pivot_index > #pivots then pivot_index = 1 end end) - timer.delay(0.2, true, function() - big_text = big_text .. " max" + timer.delay(0.3, true, function() + big_text = big_text .. " m a x" width:set_to(big_text) height:set_to(big_text) - if #big_text > 50 then + if #big_text > 120 then big_text = "Check max size" end end)