mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Add on layout change initial support
This commit is contained in:
parent
40b2837608
commit
04c39f1ce2
@ -11,10 +11,11 @@
|
|||||||
-- @tfield[opt=node] node click_node Button trigger node
|
-- @tfield[opt=node] node click_node Button trigger node
|
||||||
-- @tfield druid.button button Button component from click_node
|
-- @tfield druid.button button Button component from click_node
|
||||||
|
|
||||||
|
local const = require("druid.const")
|
||||||
local Event = require("druid.event")
|
local Event = require("druid.event")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("checkbox")
|
local M = component.create("checkbox", { const.ON_LAYOUT_CHANGE })
|
||||||
|
|
||||||
|
|
||||||
local function on_click(self)
|
local function on_click(self)
|
||||||
@ -53,15 +54,16 @@ function M.init(self, node, callback, click_node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.on_layout_change(self)
|
||||||
|
self:set_state(self.state, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set checkbox state
|
--- Set checkbox state
|
||||||
-- @function checkbox:set_state
|
-- @function checkbox:set_state
|
||||||
-- @tparam bool state Checkbox state
|
-- @tparam bool state Checkbox state
|
||||||
-- @tparam bool is_silent Don't trigger on_change_state if true
|
-- @tparam bool is_silent Don't trigger on_change_state if true
|
||||||
function M.set_state(self, state, is_silent)
|
function M.set_state(self, state, is_silent)
|
||||||
if self.state == state then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
self.state = state
|
self.state = state
|
||||||
self.style.on_change_state(self, self.node, state)
|
self.style.on_change_state(self, self.node, state)
|
||||||
|
|
||||||
|
@ -19,11 +19,12 @@
|
|||||||
-- @tfield vector4 border The size of item content
|
-- @tfield vector4 border The size of item content
|
||||||
-- @tfield vector3 border_offer The border offset for correct anchor calculations
|
-- @tfield vector3 border_offer The border offset for correct anchor calculations
|
||||||
|
|
||||||
|
local const = require("druid.const")
|
||||||
local Event = require("druid.event")
|
local Event = require("druid.event")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("grid")
|
local M = component.create("grid", { const.ON_LAYOUT_CHANGE })
|
||||||
|
|
||||||
|
|
||||||
--- Component init function
|
--- Component init function
|
||||||
@ -87,7 +88,7 @@ local function get_pos(self, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function update_pos(self)
|
local function update_pos(self, is_instant)
|
||||||
for i = 1, #self.nodes do
|
for i = 1, #self.nodes do
|
||||||
local node = self.nodes[i]
|
local node = self.nodes[i]
|
||||||
gui.set_position(node, get_pos(self, i))
|
gui.set_position(node, get_pos(self, i))
|
||||||
@ -97,6 +98,10 @@ local function update_pos(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.on_layout_change(self)
|
||||||
|
update_pos(self, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set grid items offset, the distance between items
|
--- Set grid items offset, the distance between items
|
||||||
-- @function grid:set_offset
|
-- @function grid:set_offset
|
||||||
|
@ -20,7 +20,7 @@ local const = require("druid.const")
|
|||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("progress", { const.ON_UPDATE })
|
local M = component.create("progress", { const.ON_UPDATE, const.ON_LAYOUT_CHANGE })
|
||||||
|
|
||||||
|
|
||||||
local function check_steps(self, from, to, exactly)
|
local function check_steps(self, from, to, exactly)
|
||||||
@ -106,6 +106,11 @@ function M.init(self, node, key, init_value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.on_layout_change(self)
|
||||||
|
self:set_to(self.last_value)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function M.update(self, dt)
|
function M.update(self, dt)
|
||||||
if self.target then
|
if self.target then
|
||||||
local prev_value = self.last_value
|
local prev_value = self.last_value
|
||||||
|
@ -32,7 +32,7 @@ local const = require("druid.const")
|
|||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("scroll", { const.ON_UPDATE })
|
local M = component.create("scroll", { const.ON_UPDATE, const.ON_LAYOUT_CHANGE })
|
||||||
|
|
||||||
|
|
||||||
local function inverse_lerp(min, max, current)
|
local function inverse_lerp(min, max, current)
|
||||||
@ -376,6 +376,11 @@ function M.init(self, view_node, content_node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.on_layout_change(self)
|
||||||
|
gui.set_position(self.content_node, self.position)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function M.update(self, dt)
|
function M.update(self, dt)
|
||||||
if self.drag.is_drag then
|
if self.drag.is_drag then
|
||||||
update_hand_scroll(self, dt)
|
update_hand_scroll(self, dt)
|
||||||
|
@ -22,7 +22,7 @@ local helper = require("druid.helper")
|
|||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("slider", { const.ON_INPUT_HIGH })
|
local M = component.create("slider", { const.ON_INPUT_HIGH, const.ON_LAYOUT_CHANGE })
|
||||||
|
|
||||||
|
|
||||||
local function on_change_value(self)
|
local function on_change_value(self)
|
||||||
@ -59,6 +59,11 @@ function M.init(self, node, end_pos, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.on_layout_change(self)
|
||||||
|
self:set(self.value, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function M.on_input(self, action_id, action)
|
function M.on_input(self, action_id, action)
|
||||||
if action_id ~= const.ACTION_TOUCH then
|
if action_id ~= const.ACTION_TOUCH then
|
||||||
return false
|
return false
|
||||||
|
@ -24,7 +24,7 @@ local Event = require("druid.event")
|
|||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("text")
|
local M = component.create("text", { const.ON_LAYOUT_CHANGE })
|
||||||
|
|
||||||
|
|
||||||
local function update_text_size(self)
|
local function update_text_size(self)
|
||||||
@ -107,6 +107,11 @@ function M.init(self, node, value, no_adjust)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.on_layout_change(self)
|
||||||
|
self:set_to(self.last_value)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Calculate text width with font with respect to trailing space
|
--- Calculate text width with font with respect to trailing space
|
||||||
-- @function text:get_text_width
|
-- @function text:get_text_width
|
||||||
-- @tparam[opt] string text
|
-- @tparam[opt] string text
|
||||||
|
@ -33,7 +33,7 @@ M.ON_MESSAGE = hash("on_message")
|
|||||||
M.ON_INPUT_HIGH = hash("on_input_high")
|
M.ON_INPUT_HIGH = hash("on_input_high")
|
||||||
M.ON_FOCUS_LOST = hash("on_focus_lost")
|
M.ON_FOCUS_LOST = hash("on_focus_lost")
|
||||||
M.ON_FOCUS_GAINED = hash("on_focus_gained")
|
M.ON_FOCUS_GAINED = hash("on_focus_gained")
|
||||||
M.ON_LAYOUT_CHANGE = hash("on_layout_change")
|
M.ON_LAYOUT_CHANGE = hash("layout_changed")
|
||||||
M.ON_LANGUAGE_CHANGE = hash("on_language_change")
|
M.ON_LANGUAGE_CHANGE = hash("on_language_change")
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +63,7 @@ M.PIVOTS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- Value is method name of component
|
||||||
M.SPECIFIC_UI_MESSAGES = {
|
M.SPECIFIC_UI_MESSAGES = {
|
||||||
[M.ON_FOCUS_LOST] = "on_focus_lost",
|
[M.ON_FOCUS_LOST] = "on_focus_lost",
|
||||||
[M.ON_FOCUS_GAINED] = "on_focus_gained",
|
[M.ON_FOCUS_GAINED] = "on_focus_gained",
|
||||||
|
@ -10961,5 +10961,11 @@ layers {
|
|||||||
name: "text_top"
|
name: "text_top"
|
||||||
}
|
}
|
||||||
material: "/builtins/materials/gui.material"
|
material: "/builtins/materials/gui.material"
|
||||||
|
layouts {
|
||||||
|
name: "Landscape"
|
||||||
|
}
|
||||||
|
layouts {
|
||||||
|
name: "Portrait"
|
||||||
|
}
|
||||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||||
max_nodes: 512
|
max_nodes: 512
|
||||||
|
Loading…
x
Reference in New Issue
Block a user