Skip to content

Commit d1d5489

Browse files
committed
Update Docs
1 parent 9e2a14c commit d1d5489

File tree

13 files changed

+530
-5
lines changed

13 files changed

+530
-5
lines changed

druid/base/text.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ local utf8 = utf8 or utf8_lua --[[@as utf8]]
3737
---@field on_update_text_scale event fun(self, scale, metrics) The event triggered when the text scale is updated
3838
---@field on_set_pivot event fun(self, pivot) The event triggered when the text pivot is set
3939
---@field style druid.text.style The style of the text
40-
---@field private start_pivot userdata The start pivot of the text
41-
---@field private start_scale vector3 The start scale of the text
42-
---@field private scale vector3 The current scale of the text
40+
---@field start_pivot userdata The start pivot of the text
41+
---@field start_scale vector3 The start scale of the text
42+
---@field scale vector3 The current scale of the text
4343
local M = component.create("text")
4444

4545

druid/custom/rich_input/rich_input.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,21 @@ local function set_selection_width(self, selection_width)
3434
end
3535

3636

37+
---@param self druid.rich_input
3738
local function update_text(self)
38-
local left_text_part = utf8.sub(self.input:get_text(), 0, self.input.cursor_index)
39+
local full_text = self.input:get_text()
40+
local visible_text = self.input.text:get_text()
41+
42+
local is_truncated = visible_text ~= full_text
43+
local cursor_index = self.input.cursor_index
44+
if is_truncated then
45+
-- If text is truncated, we need to adjust the cursor index
46+
-- to the last visible character
47+
cursor_index = utf8.len(visible_text)
48+
49+
end
50+
51+
local left_text_part = utf8.sub(self.input:get_text(), 0, cursor_index)
3952
local selected_text_part = utf8.sub(self.input:get_text(), self.input.start_index + 1, self.input.end_index)
4053

4154
local left_part_width = self.input.text:get_text_size(left_text_part)
@@ -44,7 +57,7 @@ local function update_text(self)
4457
local pivot_text = gui.get_pivot(self.input.text.node)
4558
local pivot_offset = helper.get_pivot_offset(pivot_text)
4659

47-
self.cursor_position.x = self.text_position.x - self.input.total_width * (0.5 + pivot_offset.x) + left_part_width
60+
self.cursor_position.x = self.text_position.x - self.input.text_width * (0.5 + pivot_offset.x) + left_part_width
4861

4962
gui.set_position(self.cursor, self.cursor_position)
5063
gui.set_scale(self.cursor, self.input.text.scale)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
font: "/druid/fonts/Roboto-Bold.ttf"
2+
material: "/example/assets/fonts/gui_world/gui-world-font-df.material"
3+
size: 40
4+
outline_alpha: 1.0
5+
outline_width: 2.0
6+
shadow_alpha: 1.0
7+
shadow_blur: 2
8+
output_format: TYPE_DISTANCE_FIELD
9+
render_mode: MODE_MULTI_LAYER
10+
characters: "\302\241\302\253\302\273\302\277\303\200\303\202\303\206\303\207\303\210\303\211\303\212\303\213\303\216\303\217\303\224\303\231\303\233\303\234\303\237\303\240\303\241\303\242\303\243\303\244\303\246\303\247\303\250\303\251\303\252\303\253\303\255\303\256\303\257\303\261\303\262\303\263\303\264\303\265\303\266\303\271\303\273\303\274\303\277\305\222\305\223\305\270\320\201\320\220\320\221\320\222\320\223\320\224\320\225\320\226\320\227\320\230\320\231\320\232\320\233\320\234\320\235\320\236\320\237\320\240\320\241\320\242\320\243\320\244\320\245\320\246\320\247\320\250\320\251\320\252\320\253\320\254\320\255\320\256\320\257\320\260\320\261\320\262\320\263\320\264\320\265\320\266\320\267\320\270\320\271\320\272\320\273\320\274\320\275\320\276\320\277\321\200\321\201\321\202\321\203\321\204\321\205\321\206\321\207\321\210\321\211\321\212\321\213\321\214\321\215\321\216\321\217\321\221\342\200\224\343\200\201\343\200\202\343\200\214\343\200\215\357\274\201\357\274\214\357\274\237 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
font: "/druid/fonts/Roboto-Regular.ttf"
2+
material: "/example/assets/fonts/gui_world/gui-world-font-df.material"
3+
size: 40
4+
outline_alpha: 1.0
5+
outline_width: 2.0
6+
output_format: TYPE_DISTANCE_FIELD
7+
render_mode: MODE_MULTI_LAYER
8+
characters: "\302\241\302\253\302\273\302\277\303\200\303\202\303\206\303\207\303\210\303\211\303\212\303\213\303\216\303\217\303\224\303\231\303\233\303\234\303\237\303\240\303\241\303\242\303\243\303\244\303\246\303\247\303\250\303\251\303\252\303\253\303\255\303\256\303\257\303\261\303\262\303\263\303\264\303\265\303\266\303\271\303\273\303\274\303\277\305\222\305\223\305\270\320\201\320\220\320\221\320\222\320\223\320\224\320\225\320\226\320\227\320\230\320\231\320\232\320\233\320\234\320\235\320\236\320\237\320\240\320\241\320\242\320\243\320\244\320\245\320\246\320\247\320\250\320\251\320\252\320\253\320\254\320\255\320\256\320\257\320\260\320\261\320\262\320\263\320\264\320\265\320\266\320\267\320\270\320\271\320\272\320\273\320\274\320\275\320\276\320\277\321\200\321\201\321\202\321\203\321\204\321\205\321\206\321\207\321\210\321\211\321\212\321\213\321\214\321\215\321\216\321\217\321\221\342\200\224\343\200\201\343\200\202\343\200\214\343\200\215\357\274\201\357\274\214\357\274\237 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: "font"
2+
tags: "tile"
3+
vertex_program: "/example/assets/fonts/gui_world/gui-world-font-df.vp"
4+
fragment_program: "/builtins/fonts/font-df.fp"
5+
vertex_constants {
6+
name: "view_proj"
7+
type: CONSTANT_TYPE_VIEWPROJ
8+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#version 140
2+
3+
// positions are in world space
4+
in highp vec4 position;
5+
in mediump vec2 texcoord0;
6+
in mediump vec4 sdf_params;
7+
in mediump vec4 face_color;
8+
in mediump vec4 outline_color;
9+
in mediump vec4 shadow_color;
10+
in mediump vec3 layer_mask;
11+
12+
out mediump vec2 var_texcoord0;
13+
out mediump vec4 var_face_color;
14+
out mediump vec4 var_outline_color;
15+
out mediump vec4 var_shadow_color;
16+
out mediump vec4 var_sdf_params;
17+
out mediump vec4 var_layer_mask;
18+
19+
uniform vs_uniforms
20+
{
21+
highp mat4 view_proj;
22+
};
23+
24+
void main()
25+
{
26+
var_texcoord0 = texcoord0;
27+
var_face_color = vec4(face_color.xyz * face_color.w, face_color.w);
28+
var_outline_color = vec4(outline_color.xyz * outline_color.w, outline_color.w);
29+
var_shadow_color = vec4(shadow_color.xyz * shadow_color.w, shadow_color.w);
30+
var_sdf_params = sdf_params;
31+
var_layer_mask.rgb = layer_mask;
32+
var_layer_mask.a = layer_mask.r * layer_mask.g * layer_mask.b;
33+
gl_Position = view_proj * vec4(position.x, position.y, position.z, 1.0);
34+
}

example/examples/basic/input/rich_input.gui

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,27 @@ nodes {
7878
template_node_child: true
7979
}
8080
nodes {
81+
position {
82+
x: -240.0
83+
}
8184
type: TYPE_TEXT
8285
id: "rich_input_2/placeholder_text"
86+
pivot: PIVOT_W
8387
parent: "rich_input_2/button"
88+
overridden_fields: 1
89+
overridden_fields: 14
8490
template_node_child: true
8591
}
8692
nodes {
93+
position {
94+
x: -240.0
95+
}
8796
type: TYPE_TEXT
8897
id: "rich_input_2/input_text"
98+
pivot: PIVOT_W
8999
parent: "rich_input_2/button"
100+
overridden_fields: 1
101+
overridden_fields: 14
90102
template_node_child: true
91103
}
92104
nodes {
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
return {
2+
data = {
3+
animations = {
4+
{
5+
animation_id = "default",
6+
animation_keys = {
7+
{
8+
duration = 1.305,
9+
easing = "outsine",
10+
end_value = 706,
11+
key_type = "tween",
12+
node_id = "go",
13+
property_id = "position_x",
14+
start_value = 960,
15+
},
16+
{
17+
duration = 3.03,
18+
easing = "outsine",
19+
end_value = 1.2,
20+
key_type = "tween",
21+
node_id = "go",
22+
property_id = "scale_x",
23+
start_value = 1,
24+
},
25+
{
26+
duration = 3.03,
27+
easing = "outsine",
28+
end_value = 1.2,
29+
key_type = "tween",
30+
node_id = "go",
31+
property_id = "scale_y",
32+
start_value = 1,
33+
},
34+
{
35+
duration = 1.689,
36+
easing = "outsine",
37+
end_value = 271,
38+
key_type = "tween",
39+
node_id = "go",
40+
property_id = "position_y",
41+
start_time = 1.305,
42+
start_value = 540,
43+
},
44+
{
45+
duration = 1.665,
46+
easing = "outsine",
47+
end_value = 960,
48+
key_type = "tween",
49+
node_id = "go",
50+
property_id = "position_x",
51+
start_time = 2.995,
52+
start_value = 706,
53+
},
54+
{
55+
duration = 2.97,
56+
easing = "outsine",
57+
end_value = 1,
58+
key_type = "tween",
59+
node_id = "go",
60+
property_id = "scale_x",
61+
start_time = 3.03,
62+
start_value = 1.2,
63+
},
64+
{
65+
duration = 2.97,
66+
easing = "outsine",
67+
end_value = 1,
68+
key_type = "tween",
69+
node_id = "go",
70+
property_id = "scale_y",
71+
start_time = 3.03,
72+
start_value = 1.2,
73+
},
74+
{
75+
duration = 1.353,
76+
easing = "outsine",
77+
end_value = 540,
78+
key_type = "tween",
79+
node_id = "go",
80+
property_id = "position_y",
81+
start_time = 4.647,
82+
start_value = 271,
83+
},
84+
},
85+
duration = 6,
86+
},
87+
},
88+
metadata = {
89+
fps = 60,
90+
gizmo_steps = {
91+
},
92+
gui_path = "/example/examples/widgets/go_widgets/go_widget.collection",
93+
layers = {
94+
},
95+
settings = {
96+
font_size = 30,
97+
},
98+
template_animation_paths = {
99+
},
100+
},
101+
nodes = {
102+
},
103+
},
104+
format = "json",
105+
type = "animation_editor",
106+
version = 1,
107+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: "go_bindings"
2+
scale_along_z: 0
3+
embedded_instances {
4+
id: "go"
5+
data: "components {\n"
6+
" id: \"go_widget\"\n"
7+
" component: \"/example/examples/widgets/go_widgets/go_widget.gui\"\n"
8+
"}\n"
9+
"components {\n"
10+
" id: \"go_bindings\"\n"
11+
" component: \"/example/examples/widgets/go_widgets/go_widget.script\"\n"
12+
"}\n"
13+
"components {\n"
14+
" id: \"druid\"\n"
15+
" component: \"/druid/druid.script\"\n"
16+
"}\n"
17+
"embedded_components {\n"
18+
" id: \"sprite\"\n"
19+
" type: \"sprite\"\n"
20+
" data: \"default_animation: \\\"ui_circle_64\\\"\\n"
21+
"material: \\\"/panthera/materials/sprite.material\\\"\\n"
22+
"attributes {\\n"
23+
" name: \\\"color\\\"\\n"
24+
" double_values {\\n"
25+
" v: 0.839\\n"
26+
" v: 0.808\\n"
27+
" v: 0.533\\n"
28+
" v: 1.0\\n"
29+
" }\\n"
30+
"}\\n"
31+
"textures {\\n"
32+
" sampler: \\\"texture_sampler\\\"\\n"
33+
" texture: \\\"/druid/druid.atlas\\\"\\n"
34+
"}\\n"
35+
"\"\n"
36+
" rotation {\n"
37+
" z: 0.70710677\n"
38+
" w: 0.70710677\n"
39+
" }\n"
40+
" scale {\n"
41+
" x: 3.0\n"
42+
" y: 3.0\n"
43+
" }\n"
44+
"}\n"
45+
"embedded_components {\n"
46+
" id: \"sprite_outline\"\n"
47+
" type: \"sprite\"\n"
48+
" data: \"default_animation: \\\"ui_circle_64\\\"\\n"
49+
"material: \\\"/panthera/materials/sprite.material\\\"\\n"
50+
"blend_mode: BLEND_MODE_MULT\\n"
51+
"size {\\n"
52+
" x: 64.0\\n"
53+
" y: 64.0\\n"
54+
"}\\n"
55+
"attributes {\\n"
56+
" name: \\\"color\\\"\\n"
57+
" double_values {\\n"
58+
" v: 0.839\\n"
59+
" v: 0.808\\n"
60+
" v: 0.533\\n"
61+
" v: 1.0\\n"
62+
" }\\n"
63+
"}\\n"
64+
"textures {\\n"
65+
" sampler: \\\"texture_sampler\\\"\\n"
66+
" texture: \\\"/druid/druid.atlas\\\"\\n"
67+
"}\\n"
68+
"\"\n"
69+
" rotation {\n"
70+
" z: 0.70710677\n"
71+
" w: 0.70710677\n"
72+
" }\n"
73+
" scale {\n"
74+
" x: 3.1\n"
75+
" y: 3.1\n"
76+
" }\n"
77+
"}\n"
78+
""
79+
}
80+
embedded_instances {
81+
id: "camera"
82+
data: "embedded_components {\n"
83+
" id: \"camera\"\n"
84+
" type: \"camera\"\n"
85+
" data: \"aspect_ratio: 1.0\\n"
86+
"fov: 0.7854\\n"
87+
"near_z: 0.1\\n"
88+
"far_z: 1000.0\\n"
89+
"orthographic_projection: 1\\n"
90+
"orthographic_zoom: 0.4\\n"
91+
"\"\n"
92+
"}\n"
93+
""
94+
position {
95+
z: 10.0
96+
}
97+
}

0 commit comments

Comments
 (0)