mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Remove old examples
This commit is contained in:
53
example/page/button.lua
Normal file
53
example/page/button.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local sprite_style = require("druid.styles.sprites.style")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
local function usual_callback()
|
||||
print("Usual callback")
|
||||
end
|
||||
|
||||
local function long_tap_callback(self, params, button, hold_time)
|
||||
print("Long tap callback", hold_time)
|
||||
end
|
||||
|
||||
local function hold_callback(self, params, button, hold_time)
|
||||
print("On hold callback", hold_time)
|
||||
end
|
||||
|
||||
local function repeated_callback(self, params, button, click_in_row)
|
||||
print("Repeated callback", click_in_row)
|
||||
end
|
||||
|
||||
local function double_tap_callback(self, params, button, click_in_row)
|
||||
print("Double tap callback", click_in_row)
|
||||
end
|
||||
|
||||
|
||||
local function setup_buttons(self)
|
||||
self.druid:new_button("button_usual/button", usual_callback)
|
||||
|
||||
local custom_style = self.druid:new_button("button_custom_style/button", usual_callback)
|
||||
custom_style:set_style(sprite_style)
|
||||
|
||||
local long_button = self.druid:new_button("button_long_tap/button", usual_callback)
|
||||
long_button.on_hold_callback:subscribe(hold_callback)
|
||||
long_button.on_long_click:subscribe(long_tap_callback)
|
||||
self.druid:new_button("button_repeated_tap/button", usual_callback)
|
||||
.on_repeated_click:subscribe(repeated_callback)
|
||||
self.druid:new_button("button_double_tap/button", usual_callback)
|
||||
.on_double_click:subscribe(double_tap_callback)
|
||||
|
||||
local button_space = self.druid:new_button("button_key_trigger/button", usual_callback)
|
||||
button_space:set_key_trigger("key_space")
|
||||
button_space.on_long_click:subscribe(long_tap_callback)
|
||||
button_space.on_double_click:subscribe(double_tap_callback)
|
||||
end
|
||||
|
||||
|
||||
function M.setup_page(self)
|
||||
setup_buttons(self)
|
||||
end
|
||||
|
||||
|
||||
return M
|
123
example/page/main.lua
Normal file
123
example/page/main.lua
Normal file
@@ -0,0 +1,123 @@
|
||||
local lang = require("example.lang")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
local function empty_callback(self, param)
|
||||
print("Empty callback. Param", param)
|
||||
end
|
||||
|
||||
|
||||
local function random_progress(progress, text)
|
||||
local rnd = math.random()
|
||||
|
||||
gui.set_text(text, math.ceil(rnd * 100) .. "%")
|
||||
progress:to(rnd)
|
||||
end
|
||||
|
||||
|
||||
local function setup_button(self)
|
||||
local b = self.druid:new_button("button_simple", lang.toggle_locale, "button_param")
|
||||
self.druid:new_button("button_template/button", function()
|
||||
print(b:is_enabled())
|
||||
b:set_enabled(not b:is_enabled())
|
||||
end, "button_param")
|
||||
end
|
||||
|
||||
|
||||
local function setup_texts(self)
|
||||
self.druid:new_lang_text("text_button", "ui_section_button")
|
||||
self.druid:new_lang_text("text_text", "ui_section_text")
|
||||
self.druid:new_lang_text("text_timer", "ui_section_timer")
|
||||
self.druid:new_lang_text("text_progress", "ui_section_progress")
|
||||
self.druid:new_lang_text("text_slider", "ui_section_slider")
|
||||
self.druid:new_lang_text("text_radio", "ui_section_radio")
|
||||
self.druid:new_lang_text("text_checkbox", "ui_section_checkbox")
|
||||
|
||||
self.druid:new_lang_text("text_translated", "ui_text_example")
|
||||
self.druid:new_lang_text("text_button_lang", "ui_text_change_lang")
|
||||
self.druid:new_text("text_simple", "Simple")
|
||||
end
|
||||
|
||||
|
||||
local function setup_progress(self)
|
||||
self.progress = self.druid:new_progress("progress_fill", "x", 0.4)
|
||||
random_progress(self.progress, gui.get_node("text_progress_amount"))
|
||||
timer.delay(2, true, function()
|
||||
random_progress(self.progress, gui.get_node("text_progress_amount"))
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
local function setup_grid(self)
|
||||
local grid = self.druid:new_grid("grid", "button_template/button", 3)
|
||||
|
||||
for i = 1, 12 do
|
||||
local nodes = gui.clone_tree(gui.get_node("button_template/button"))
|
||||
|
||||
local root = nodes["button_template/button"]
|
||||
self.druid:new_button(root, function(context, param)
|
||||
grid:set_offset(vmath.vector3(param))
|
||||
end, i)
|
||||
self.druid:new_text(nodes["button_template/text"], "Grid"..i)
|
||||
grid:add(root)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function setup_slider(self)
|
||||
local slider = self.druid:new_slider("slider_pin", vmath.vector3(95, 0, 0), function(_, value)
|
||||
gui.set_text(gui.get_node("text_progress_slider"), math.ceil(value * 100) .. "%")
|
||||
end)
|
||||
|
||||
slider:set(0.2)
|
||||
end
|
||||
|
||||
|
||||
local function setup_checkbox(self)
|
||||
local radio_group = self.druid:new_radio_group(
|
||||
{"radio1/check", "radio2/check", "radio3/check"},
|
||||
nil,
|
||||
{"radio1/back", "radio2/back", "radio3/back"})
|
||||
|
||||
local checkbox_group = self.druid:new_checkbox_group(
|
||||
{"checkbox1/check", "checkbox2/check", "checkbox3/check"},
|
||||
nil,
|
||||
{"checkbox1/back", "checkbox2/back", "checkbox3/back"})
|
||||
|
||||
radio_group:set_state(2)
|
||||
checkbox_group:set_state({true, false, true})
|
||||
end
|
||||
|
||||
|
||||
local function setup_timer(self)
|
||||
self.timer = self.druid:new_timer("timer", 300, 0, empty_callback)
|
||||
end
|
||||
|
||||
|
||||
local function setup_scroll(self)
|
||||
self.scroll = self.druid:new_scroll("scroll_content", "main_page")
|
||||
end
|
||||
|
||||
|
||||
local function setup_back_handler(self)
|
||||
self.druid:new_back_handler(empty_callback, "back button")
|
||||
end
|
||||
|
||||
|
||||
|
||||
function M.setup_page(self)
|
||||
setup_texts(self)
|
||||
|
||||
setup_button(self)
|
||||
setup_progress(self)
|
||||
setup_grid(self)
|
||||
setup_timer(self)
|
||||
setup_checkbox(self)
|
||||
setup_scroll(self)
|
||||
setup_slider(self)
|
||||
setup_back_handler(self)
|
||||
end
|
||||
|
||||
|
||||
return M
|
46
example/page/scroll.lua
Normal file
46
example/page/scroll.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local M = {}
|
||||
|
||||
|
||||
local function init_grid(self)
|
||||
local prefab = gui.get_node("grid_prefab")
|
||||
|
||||
local grid_scroll = self.druid:new_scroll("grid_content", "scroll_with_grid_size")
|
||||
local grid = self.druid:new_grid("grid_content", "grid_prefab", 20)
|
||||
grid:set_anchor(vmath.vector3(0, 0.5, 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)
|
||||
|
||||
local button = self.druid:new_button(clone_prefab["grid_button"], function()
|
||||
local position = gui.get_position(clone_prefab["grid_prefab"])
|
||||
position.x = -position.x
|
||||
grid_scroll:scroll_to(position)
|
||||
end)
|
||||
button:set_click_zone(gui.get_node("scroll_with_grid_size"))
|
||||
end
|
||||
|
||||
gui.set_enabled(prefab, false)
|
||||
|
||||
grid_scroll:set_border(grid:get_size())
|
||||
|
||||
local scroll_slider = self.druid:new_slider("grid_scroll_pin", vmath.vector3(300, 0, 0), function(_, value)
|
||||
grid_scroll:scroll_to_percent(vmath.vector3(value, 0, 0), true)
|
||||
end)
|
||||
|
||||
grid_scroll.on_scroll:subscribe(function(_, point)
|
||||
scroll_slider:set(grid_scroll:get_scroll_percent().x, true)
|
||||
end)
|
||||
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
|
||||
|
||||
|
||||
return M
|
53
example/page/texts.lua
Normal file
53
example/page/texts.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local M = {}
|
||||
|
||||
local pivots = {
|
||||
gui.PIVOT_CENTER,
|
||||
gui.PIVOT_N,
|
||||
gui.PIVOT_NE,
|
||||
gui.PIVOT_E,
|
||||
gui.PIVOT_SE,
|
||||
gui.PIVOT_S,
|
||||
gui.PIVOT_SW,
|
||||
gui.PIVOT_W,
|
||||
gui.PIVOT_NW
|
||||
}
|
||||
|
||||
local function setup_texts(self)
|
||||
self.druid:new_text("text_inline", "Simple inline text")
|
||||
self.druid:new_text("text_multiline", "Simple multiline text with smth")
|
||||
local anchoring = self.druid:new_text("text_anchoring", "Anchoring")
|
||||
self.druid:new_text("text_no_adjust", "Without adjust size", true)
|
||||
self.druid:new_lang_text("text_locale", "ui_text_example")
|
||||
|
||||
local big_text = "Check max size"
|
||||
local width = self.druid:new_text("text_max_width", big_text)
|
||||
local height = self.druid:new_text("text_max_height", big_text)
|
||||
|
||||
local pivot_index = 1
|
||||
timer.delay(0.3, true, function()
|
||||
anchoring:set_pivot(pivots[pivot_index])
|
||||
|
||||
pivot_index = pivot_index + 1
|
||||
if pivot_index > #pivots then
|
||||
pivot_index = 1
|
||||
end
|
||||
end)
|
||||
|
||||
timer.delay(0.2, true, function()
|
||||
big_text = big_text .. " max"
|
||||
width:set_to(big_text)
|
||||
height:set_to(big_text)
|
||||
|
||||
if #big_text > 50 then
|
||||
big_text = "Check max size"
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function M.setup_page(self)
|
||||
setup_texts(self)
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user