mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Add set_pivot to text component
This commit is contained in:
parent
c3752dba54
commit
59c9dc8a9b
@ -12,9 +12,9 @@ M.interest = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function M.init(self, node, lang_id)
|
function M.init(self, node, lang_id, no_adjust)
|
||||||
self.druid = helper.get_druid(self)
|
self.druid = helper.get_druid(self)
|
||||||
self.text = self.druid:new_text(node)
|
self.text = self.druid:new_text(node, lang_id, no_adjust)
|
||||||
self:translate(lang_id)
|
self:translate(lang_id)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@ -2,23 +2,27 @@
|
|||||||
-- Good working with localization system
|
-- Good working with localization system
|
||||||
-- @module base.text
|
-- @module base.text
|
||||||
|
|
||||||
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
M.interest = {}
|
|
||||||
|
|
||||||
|
|
||||||
function M.init(self, node, value, no_text_adjust)
|
function M.init(self, node, value, no_adjust)
|
||||||
self.node = helper.node(node)
|
self.node = helper.node(node)
|
||||||
self.start_scale = gui.get_scale(self.node)
|
|
||||||
self.start_pivot = gui.get_pivot(self.node)
|
self.start_pivot = gui.get_pivot(self.node)
|
||||||
|
|
||||||
|
self.start_pos = gui.get_position(self.node)
|
||||||
|
self.pos = gui.get_position(self.node)
|
||||||
|
|
||||||
|
self.start_scale = gui.get_scale(self.node)
|
||||||
|
self.scale = gui.get_scale(self.node)
|
||||||
|
|
||||||
self.text_area = gui.get_size(self.node)
|
self.text_area = gui.get_size(self.node)
|
||||||
self.text_area.x = self.text_area.x * self.start_scale.x
|
self.text_area.x = self.text_area.x * self.start_scale.x
|
||||||
self.text_area.y = self.text_area.y * self.start_scale.y
|
self.text_area.y = self.text_area.y * self.start_scale.y
|
||||||
|
|
||||||
self.is_no_text_adjust = no_text_adjust
|
self.is_no_adjust = no_adjust
|
||||||
self.scale = self.start_scale
|
|
||||||
self.last_color = gui.get_color(self.node)
|
self.last_color = gui.get_color(self.node)
|
||||||
|
|
||||||
self:set_to(value or 0)
|
self:set_to(value or 0)
|
||||||
@ -54,7 +58,7 @@ function M.set_to(self, set_to)
|
|||||||
self.last_value = set_to
|
self.last_value = set_to
|
||||||
gui.set_text(self.node, set_to)
|
gui.set_text(self.node, set_to)
|
||||||
|
|
||||||
if not self.is_no_text_adjust then
|
if not self.is_no_adjust then
|
||||||
update_text_area_size(self)
|
update_text_area_size(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -90,8 +94,26 @@ function M.set_scale(self, scale)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set text pivot. Text will re-anchor inside
|
||||||
|
-- his text area
|
||||||
|
-- @function text:set_pivot
|
||||||
|
-- @tparam table self Component instance
|
||||||
|
-- @tparam gui.pivot pivot Gui pivot constant
|
||||||
function M.set_pivot(self, pivot)
|
function M.set_pivot(self, pivot)
|
||||||
|
local prev_pivot = gui.get_pivot(self.node)
|
||||||
|
local prev_offset = const.PIVOTS[prev_pivot]
|
||||||
|
|
||||||
|
gui.set_pivot(self.node, pivot)
|
||||||
|
local cur_offset = const.PIVOTS[pivot]
|
||||||
|
|
||||||
|
local pos_offset = vmath.vector3(
|
||||||
|
self.text_area.x * (cur_offset.x - prev_offset.x),
|
||||||
|
self.text_area.y * (cur_offset.y - prev_offset.y),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
|
||||||
|
self.pos = self.pos + pos_offset
|
||||||
|
gui.set_position(self.node, self.pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ M.PIVOTS = {
|
|||||||
[gui.PIVOT_S] = vmath.vector3(0, -0.5, 0),
|
[gui.PIVOT_S] = vmath.vector3(0, -0.5, 0),
|
||||||
[gui.PIVOT_SW] = vmath.vector3(-0.5, -0.5, 0),
|
[gui.PIVOT_SW] = vmath.vector3(-0.5, -0.5, 0),
|
||||||
[gui.PIVOT_W] = vmath.vector3(-0.5, 0, 0),
|
[gui.PIVOT_W] = vmath.vector3(-0.5, 0, 0),
|
||||||
[gui.PIVOT_NW] = vmath.vector3(-0.5, -0.5, 0),
|
[gui.PIVOT_NW] = vmath.vector3(-0.5, 0.5, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
M.SIDE = {
|
M.SIDE = {
|
||||||
|
@ -840,7 +840,7 @@ nodes {
|
|||||||
}
|
}
|
||||||
type: TYPE_TEXT
|
type: TYPE_TEXT
|
||||||
blend_mode: BLEND_MODE_ALPHA
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
text: "SImple"
|
text: "Simple"
|
||||||
font: "game"
|
font: "game"
|
||||||
id: "text_simple"
|
id: "text_simple"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
|
@ -12,12 +12,13 @@ end
|
|||||||
local function init_top_panel(self)
|
local function init_top_panel(self)
|
||||||
self.druid:new_button("button_left/button", on_control_button, "left")
|
self.druid:new_button("button_left/button", on_control_button, "left")
|
||||||
self.druid:new_button("button_right/button", on_control_button, "right")
|
self.druid:new_button("button_right/button", on_control_button, "right")
|
||||||
self.header = self.druid:new_text("text_header", "main_page", true)
|
self.header = self.druid:new_locale("text_header", "main_page")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
druid.set_default_style(empty_style)
|
druid.set_default_style(empty_style)
|
||||||
|
druid.set_default_style(bounce_style)
|
||||||
self.druid = druid.new(self)
|
self.druid = druid.new(self)
|
||||||
|
|
||||||
init_top_panel(self)
|
init_top_panel(self)
|
||||||
|
@ -26,17 +26,17 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function setup_texts(self)
|
local function setup_texts(self)
|
||||||
self.druid:new_text("text_button", "ui_section_button", true)
|
self.druid:new_locale("text_button", "ui_section_button")
|
||||||
self.druid:new_text("text_text", "ui_section_text", true)
|
self.druid:new_locale("text_text", "ui_section_text")
|
||||||
self.druid:new_text("text_timer", "ui_section_timer", true)
|
self.druid:new_locale("text_timer", "ui_section_timer")
|
||||||
self.druid:new_text("text_progress", "ui_section_progress", true)
|
self.druid:new_locale("text_progress", "ui_section_progress")
|
||||||
self.druid:new_text("text_slider", "ui_section_slider", true)
|
self.druid:new_locale("text_slider", "ui_section_slider")
|
||||||
self.druid:new_text("text_radio", "ui_section_radio", true)
|
self.druid:new_locale("text_radio", "ui_section_radio")
|
||||||
self.druid:new_text("text_checkbox", "ui_section_checkbox", true)
|
self.druid:new_locale("text_checkbox", "ui_section_checkbox")
|
||||||
|
|
||||||
|
self.druid:new_locale("text_translated", "ui_text_example")
|
||||||
|
self.druid:new_locale("text_button_lang", "ui_text_change_lang")
|
||||||
self.druid:new_text("text_simple", "Simple")
|
self.druid:new_text("text_simple", "Simple")
|
||||||
self.druid:new_text("text_translated", "ui_text_example", true)
|
|
||||||
self.druid:new_text("text_button_lang", "ui_text_change_lang", true, 150 * 0.7)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user