mirror of
https://github.com/Insality/druid
synced 2025-06-27 02:17:52 +02:00
add text component (#4)
This commit is contained in:
parent
3996ba4b04
commit
5709975ed4
@ -1,13 +1,32 @@
|
||||
local data = require("druid.data")
|
||||
local settings = require("druid.settings")
|
||||
|
||||
local M = {}
|
||||
M.interest = {
|
||||
data.TRANSLATABLE,
|
||||
data.LAYOUT_CHANGED
|
||||
}
|
||||
|
||||
local ui_animate = require "druid.helper.druid_animate"
|
||||
|
||||
--- Bounce text field
|
||||
function M.bounce(instance, callback)
|
||||
gui.set_scale(instance.node, instance.scale_from)
|
||||
ui_animate.bounce(nil, instance.node, instance.scale_to, callback)
|
||||
function M.init(instance, value, is_locale)
|
||||
instance.last_color = gui.get_color(instance.node)
|
||||
if is_locale then
|
||||
instance.text_id = value
|
||||
instance:translate()
|
||||
else
|
||||
instance:set_to(value or 0)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
function M.translate(instance)
|
||||
if instance.text_id then
|
||||
instance:set_to(settings.get_text(instance.text_id))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Set text to text field
|
||||
-- @param set_to - set value to text field
|
||||
function M.set_to(instance, set_to)
|
||||
@ -15,6 +34,7 @@ function M.set_to(instance, set_to)
|
||||
gui.set_text(instance.node, set_to)
|
||||
end
|
||||
|
||||
|
||||
--- Set color
|
||||
-- @param color
|
||||
function M.set_color(instance, color)
|
||||
@ -22,6 +42,15 @@ function M.set_color(instance, color)
|
||||
gui.set_color(instance.node, color)
|
||||
end
|
||||
|
||||
|
||||
--- Set alpha
|
||||
-- @param alpha, number [0-1]
|
||||
function M.set_alpha(instance, alpha)
|
||||
instance.last_color.w = alpha
|
||||
gui.set_color(instance.node, instance.last_color)
|
||||
end
|
||||
|
||||
|
||||
--- Set scale
|
||||
-- @param scale
|
||||
function M.set_scale(instance, scale)
|
||||
@ -29,6 +58,7 @@ function M.set_scale(instance, scale)
|
||||
gui.set_scale(instance.node, scale)
|
||||
end
|
||||
|
||||
|
||||
--- Called when layout updated (rotate for example)
|
||||
function M.on_layout_updated(instance)
|
||||
if instance.last_color then
|
||||
|
@ -9,8 +9,8 @@ local STRING = "string"
|
||||
local components = {
|
||||
-- basic
|
||||
button = require("druid.base.button"),
|
||||
text = require("druid.base.text"),
|
||||
timer = require("druid.base.timer"),
|
||||
-- text = require("druid.base.text"),
|
||||
-- android_back = require("druid.base.android_back"),
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ M.button = {
|
||||
|
||||
function M.get_text(name)
|
||||
-- override to get text for localized text
|
||||
return "locales not inited"
|
||||
end
|
||||
|
||||
|
||||
|
@ -1,10 +1,18 @@
|
||||
local druid = require("druid.druid")
|
||||
local druid_settings = require("druid.settings")
|
||||
|
||||
local lang = {
|
||||
locale_text = "Localized"
|
||||
}
|
||||
|
||||
local function setup_druid(self)
|
||||
druid_settings.play_sound = function(name)
|
||||
sound.play("sounds#" .. name)
|
||||
end
|
||||
|
||||
druid_settings.get_text = function(text_id)
|
||||
return lang[text_id]
|
||||
end
|
||||
end
|
||||
|
||||
function init(self)
|
||||
@ -22,9 +30,14 @@ function init(self)
|
||||
print("On button 3")
|
||||
end)
|
||||
|
||||
self.druid:new_text("text_2", "Simple text")
|
||||
self.druid:new_text("text_3", "locale_text", true)
|
||||
|
||||
self.druid:new_timer("text_1", 0.5, 0, function()
|
||||
print("On timer end")
|
||||
end)
|
||||
|
||||
|
||||
end
|
||||
|
||||
function update(self, dt)
|
||||
|
Loading…
x
Reference in New Issue
Block a user