mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
#107 Better scale text adjust by height for multiline text nodes
This commit is contained in:
parent
ab3f5f8e31
commit
ba312742d2
@ -247,3 +247,4 @@ Have a good day.
|
||||
- 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
|
||||
- **#107** Better scale text adjust by height for multiline text nodes (but still not perfect)
|
@ -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
|
||||
|
||||
|
@ -35,12 +35,12 @@ local function setup_texts(self)
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user