mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Add more scroll examples
This commit is contained in:
parent
5ef9e6fa65
commit
85e2235bae
@ -11,7 +11,7 @@ Simple to-do for Druid Alpha 0.2.0
|
||||
+ refactor on_swipe. To on_scroll? Add input priority
|
||||
+ separate custom data and predefined fields in components? Every component have their fields and events
|
||||
+ How to set custom sprites for button states?
|
||||
- add druid settings (add auto_focus input and other stuff)
|
||||
+ add druid settings (add auto_focus input and other stuff) (to game.project)
|
||||
|
||||
+ button add key trigger
|
||||
+ button and hover click restriction zone?
|
||||
|
@ -98,7 +98,7 @@ end
|
||||
function M.get_size(self)
|
||||
return vmath.vector3(
|
||||
self.border.z - self.border.x,
|
||||
self.border.w - self.border.y,
|
||||
self.border.y - self.border.w,
|
||||
0)
|
||||
end
|
||||
|
||||
|
@ -27,6 +27,25 @@ local function get_border(node)
|
||||
end
|
||||
|
||||
|
||||
local function update_border(self)
|
||||
local input_border = get_border(self.input_zone)
|
||||
local content_border = get_border(self.node)
|
||||
|
||||
-- border.x - min content.x node pos
|
||||
-- border.y - min content.y node pos
|
||||
-- border.z - max content.x node pos
|
||||
-- border.w - max content.y node pos
|
||||
self.border = vmath.vector4(
|
||||
input_border.x - content_border.x,
|
||||
-input_border.w + content_border.w,
|
||||
input_border.z - content_border.z,
|
||||
-input_border.y + content_border.y
|
||||
)
|
||||
self.can_x = (self.border.x ~= self.border.z)
|
||||
self.can_y = (self.border.y ~= self.border.w)
|
||||
end
|
||||
|
||||
|
||||
function M.init(self, scroll_parent, input_zone, border)
|
||||
self.style = self:get_style()
|
||||
self.node = self:get_node(scroll_parent)
|
||||
@ -53,14 +72,7 @@ function M.init(self, scroll_parent, input_zone, border)
|
||||
side = false,
|
||||
}
|
||||
|
||||
local input_border = get_border(self.input_zone)
|
||||
local content_border = get_border(self.node)
|
||||
self:set_border(vmath.vector4(
|
||||
input_border.x - content_border.x,
|
||||
-input_border.w + content_border.w,
|
||||
input_border.z - content_border.z,
|
||||
-input_border.y + content_border.y
|
||||
))
|
||||
update_border(self)
|
||||
|
||||
self.on_scroll = Event()
|
||||
self.on_scroll_to = Event()
|
||||
@ -432,14 +444,9 @@ end
|
||||
-- @function scroll:set_border
|
||||
-- @tparam table self Component instance
|
||||
-- @tparam vmath.vector3 border Size of scrolling area
|
||||
function M.set_border(self, border)
|
||||
-- border.x - min content.x node pos
|
||||
-- border.y - min content.y node pos
|
||||
-- border.z - max content.x node pos
|
||||
-- border.w - max content.y node pos
|
||||
self.border = border
|
||||
self.can_x = (border.x ~= border.z)
|
||||
self.can_y = (border.y ~= border.w)
|
||||
function M.set_border(self, content_size)
|
||||
gui.set_size(self.node, content_size)
|
||||
update_border(self)
|
||||
end
|
||||
|
||||
|
||||
|
@ -48,6 +48,9 @@ end
|
||||
|
||||
--- Setup scale x, but can only be smaller, than start text scale
|
||||
local function update_text_area_size(self)
|
||||
gui.set_scale(self.node, self.start_scale)
|
||||
gui.set_size(self.node, self.start_size)
|
||||
|
||||
local max_width = self.text_area.x
|
||||
local max_height = self.text_area.y
|
||||
|
||||
|
@ -20,8 +20,6 @@ local settings = require("druid.system.settings")
|
||||
|
||||
local M = {}
|
||||
|
||||
local log = settings.log
|
||||
|
||||
|
||||
--- Register external druid component.
|
||||
-- After register you can create the component with
|
||||
@ -37,7 +35,7 @@ function M.register(name, module)
|
||||
return druid_instance.create(self, module, ...)
|
||||
end
|
||||
|
||||
log("Register component", name)
|
||||
-- print("Register component", name)
|
||||
end
|
||||
|
||||
|
||||
|
@ -43,8 +43,7 @@ local Druid = class("druid.druid_instance")
|
||||
|
||||
|
||||
local function input_init(self)
|
||||
-- TODO: To custom settings
|
||||
if not settings.auto_focus_gain then
|
||||
if not sys.get_config("druid.auto_focus") == "1" then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -4,10 +4,7 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
M.is_debug = false
|
||||
M.default_style = nil
|
||||
M.auto_focus_gain = true
|
||||
|
||||
|
||||
function M.get_text(name)
|
||||
return "[Druid]: locales not inited"
|
||||
@ -18,11 +15,4 @@ function M.play_sound(name)
|
||||
end
|
||||
|
||||
|
||||
function M.log(...)
|
||||
if M.is_debug then
|
||||
print("[Druid]: ", ...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@ -3918,6 +3918,61 @@ nodes {
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 150.0
|
||||
y: -260.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 0.7
|
||||
y: 0.7
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.7019608
|
||||
y: 0.7019608
|
||||
z: 0.7019608
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: ""
|
||||
id: "text_max_height_visual"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "text_page"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 0.7
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 150.0
|
||||
@ -5053,7 +5108,62 @@ nodes {
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 150.0
|
||||
y: 450.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 600.0
|
||||
y: 1900.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "kenney/empty"
|
||||
id: "scroll_page_content"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_N
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "scroll_page"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: -300.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
@ -5089,7 +5199,7 @@ nodes {
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "scroll_page"
|
||||
parent: "scroll_page_content"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
@ -5107,7 +5217,7 @@ nodes {
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
x: 300.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
@ -5412,6 +5522,234 @@ nodes {
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: -630.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 600.0
|
||||
y: 300.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "kenney/empty"
|
||||
id: "scroll_with_grid_size"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "scroll_page_content"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_STENCIL
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: -300.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 600.0
|
||||
y: 300.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 0.6
|
||||
z: 0.4
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: ""
|
||||
id: "grid_content"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_W
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "scroll_with_grid_size"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: -180.0
|
||||
y: -550.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "kenney/button_blue"
|
||||
id: "grid_prefab"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "scroll_page_content"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 10.0
|
||||
y: 10.0
|
||||
z: 10.0
|
||||
w: 10.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 5.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 180.0
|
||||
y: 50.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Just text"
|
||||
font: "game"
|
||||
id: "grid_prefab_text"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.2
|
||||
y: 0.3019608
|
||||
z: 0.7019608
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "grid_prefab"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 0.0
|
||||
template_node_child: false
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
|
@ -1,8 +1,31 @@
|
||||
local M = {}
|
||||
|
||||
|
||||
local function init_grid(self)
|
||||
local prefab = gui.get_node("grid_prefab")
|
||||
|
||||
|
||||
local grid = self.druid:new_grid("grid_content", "grid_prefab", 20)
|
||||
grid:set_anchor(vmath.vector3(0, 0.5, 0))
|
||||
grid:set_offset(vmath.vector3(15, 100, 0))
|
||||
|
||||
for i = 1, 40 do
|
||||
local clone_prefab = gui.clone_tree(prefab)
|
||||
|
||||
grid:add(clone_prefab["grid_prefab"])
|
||||
gui.set_text(clone_prefab["grid_prefab_text"], "Node " .. i)
|
||||
end
|
||||
|
||||
gui.set_enabled(prefab, false)
|
||||
local grid_scroll = self.druid:new_scroll("grid_content", "scroll_with_grid_size")
|
||||
grid_scroll:set_border(grid:get_size())
|
||||
end
|
||||
|
||||
|
||||
function M.setup_page(self)
|
||||
self.druid:new_scroll("scroll_page_content", "scroll_page")
|
||||
self.druid:new_scroll("simple_scroll_content", "simple_scroll_input")
|
||||
init_grid(self)
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user