Move examples to new collections

This commit is contained in:
Insality
2021-04-04 13:21:34 +03:00
parent 24237899af
commit 04d6babdff
17 changed files with 6797 additions and 651 deletions

View File

@@ -0,0 +1,37 @@
name: "buttons"
scale_along_z: 0
embedded_instances {
id: "go"
data: "components {\n"
" id: \"buttons\"\n"
" component: \"/example/examples/general/buttons/buttons.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
local druid = require("druid.druid")
local sprite_style = require("druid.styles.sprites.style")
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)
-- Button with another node for animating
self.druid:new_button("button_anim/button", usual_callback, nil, "anim_node_icon")
end
function init(self)
self.druid = druid.new(self)
setup_buttons(self)
end
function final(self)
self.druid:final()
end
function update(self, dt)
self.druid:update(dt)
end
function on_message(self, message_id, message, sender)
self.druid:on_message(message_id, message, sender)
end
function on_input(self, action_id, action)
return self.druid:on_input(action_id, action)
end

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,105 @@
local lang = require("example.lang")
local druid = require("druid.druid")
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()
msg.post("@system:", "toggle_profile")
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_input", "ui_section_input")
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_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_back_handler(self)
self.druid:new_back_handler(empty_callback, "back button")
end
local function setup_input(self)
local input = self.druid:new_input("input_box", "input_text")
input:set_text("hello!")
end
function init(self)
self.druid = druid.new(self)
setup_texts(self)
setup_button(self)
setup_progress(self)
setup_timer(self)
setup_checkbox(self)
setup_slider(self)
setup_back_handler(self)
setup_input(self)
end

View File

@@ -0,0 +1,37 @@
name: "sliders"
scale_along_z: 0
embedded_instances {
id: "go"
data: "components {\n"
" id: \"sliders\"\n"
" component: \"/example/examples/general/sliders/sliders.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
local druid = require("druid.druid")
function init(self)
self.druid = druid.new(self)
local slider = self.druid:new_slider("slider_simple_pin", vmath.vector3(95, 0, 0), function(_, value)
gui.set_text(gui.get_node("slider_simple_text"), math.ceil(value * 100) .. "%")
end)
slider:set(0.2)
local slider_notched = self.druid:new_slider("slider_notched_pin", vmath.vector3(95, 0, 0), function(_, value)
gui.set_text(gui.get_node("slider_notched_text"), math.ceil(value * 100) .. "%")
end)
slider_notched:set_steps({0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1})
slider_notched:set(0.2)
end
function final(self)
self.druid:final()
end
function update(self, dt)
self.druid:update(dt)
end
function on_message(self, message_id, message, sender)
self.druid:on_message(message_id, message, sender)
end
function on_input(self, action_id, action)
return self.druid:on_input(action_id, action)
end

View File

@@ -16,7 +16,7 @@ background_color {
nodes {
position {
x: 300.0
y: 400.0
y: 415.0
z: 0.0
w: 1.0
}
@@ -34,7 +34,7 @@ nodes {
}
size {
x: 600.0
y: 800.0
y: 830.0
z: 0.0
w: 1.0
}
@@ -130,6 +130,12 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
layers {
name: "image"
}
layers {
name: "text"
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512

View File

@@ -0,0 +1,37 @@
name: "texts"
scale_along_z: 0
embedded_instances {
id: "go"
data: "components {\n"
" id: \"texts\"\n"
" component: \"/example/examples/general/texts/texts.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,72 @@
local druid = require("druid.druid")
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")
self.druid:new_text("text_multiline")
local anchoring = self.druid:new_text("text_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 init(self)
self.druid = druid.new(self)
setup_texts(self)
end
function final(self)
self.druid:final()
end
function update(self, dt)
self.druid:update(dt)
end
function on_message(self, message_id, message, sender)
self.druid:on_message(message_id, message, sender)
end
function on_input(self, action_id, action)
return self.druid:on_input(action_id, action)
end