bevy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Cargo.lock +4279 -0
- data/Cargo.toml +36 -0
- data/README.md +226 -0
- data/crates/bevy/Cargo.toml +52 -0
- data/crates/bevy/src/app.rs +43 -0
- data/crates/bevy/src/component.rs +111 -0
- data/crates/bevy/src/entity.rs +30 -0
- data/crates/bevy/src/error.rs +32 -0
- data/crates/bevy/src/event.rs +190 -0
- data/crates/bevy/src/input_bridge.rs +300 -0
- data/crates/bevy/src/lib.rs +42 -0
- data/crates/bevy/src/mesh_renderer.rs +328 -0
- data/crates/bevy/src/query.rs +53 -0
- data/crates/bevy/src/render_app.rs +689 -0
- data/crates/bevy/src/resource.rs +28 -0
- data/crates/bevy/src/schedule.rs +186 -0
- data/crates/bevy/src/sprite_renderer.rs +355 -0
- data/crates/bevy/src/system.rs +44 -0
- data/crates/bevy/src/text_renderer.rs +258 -0
- data/crates/bevy/src/types/color.rs +114 -0
- data/crates/bevy/src/types/dynamic.rs +131 -0
- data/crates/bevy/src/types/math.rs +260 -0
- data/crates/bevy/src/types/mod.rs +9 -0
- data/crates/bevy/src/types/transform.rs +166 -0
- data/crates/bevy/src/world.rs +163 -0
- data/crates/bevy_ruby_render/Cargo.toml +22 -0
- data/crates/bevy_ruby_render/src/asset.rs +360 -0
- data/crates/bevy_ruby_render/src/audio.rs +511 -0
- data/crates/bevy_ruby_render/src/camera.rs +365 -0
- data/crates/bevy_ruby_render/src/gamepad.rs +398 -0
- data/crates/bevy_ruby_render/src/lib.rs +26 -0
- data/crates/bevy_ruby_render/src/material.rs +310 -0
- data/crates/bevy_ruby_render/src/mesh.rs +491 -0
- data/crates/bevy_ruby_render/src/sprite.rs +289 -0
- data/ext/bevy/Cargo.toml +20 -0
- data/ext/bevy/extconf.rb +6 -0
- data/ext/bevy/src/conversions.rs +137 -0
- data/ext/bevy/src/lib.rs +29 -0
- data/ext/bevy/src/ruby_app.rs +65 -0
- data/ext/bevy/src/ruby_color.rs +149 -0
- data/ext/bevy/src/ruby_component.rs +189 -0
- data/ext/bevy/src/ruby_entity.rs +33 -0
- data/ext/bevy/src/ruby_math.rs +384 -0
- data/ext/bevy/src/ruby_query.rs +64 -0
- data/ext/bevy/src/ruby_render_app.rs +779 -0
- data/ext/bevy/src/ruby_system.rs +122 -0
- data/ext/bevy/src/ruby_world.rs +107 -0
- data/lib/bevy/animation.rb +597 -0
- data/lib/bevy/app.rb +675 -0
- data/lib/bevy/asset.rb +613 -0
- data/lib/bevy/audio.rb +545 -0
- data/lib/bevy/audio_effects.rb +224 -0
- data/lib/bevy/camera.rb +412 -0
- data/lib/bevy/component.rb +91 -0
- data/lib/bevy/diagnostics.rb +227 -0
- data/lib/bevy/ecs_advanced.rb +296 -0
- data/lib/bevy/event.rb +199 -0
- data/lib/bevy/gizmos.rb +158 -0
- data/lib/bevy/gltf.rb +227 -0
- data/lib/bevy/hierarchy.rb +444 -0
- data/lib/bevy/input.rb +514 -0
- data/lib/bevy/lighting.rb +369 -0
- data/lib/bevy/material.rb +248 -0
- data/lib/bevy/mesh.rb +257 -0
- data/lib/bevy/navigation.rb +344 -0
- data/lib/bevy/networking.rb +335 -0
- data/lib/bevy/particle.rb +337 -0
- data/lib/bevy/physics.rb +396 -0
- data/lib/bevy/plugins/default_plugins.rb +34 -0
- data/lib/bevy/plugins/input_plugin.rb +49 -0
- data/lib/bevy/reflect.rb +361 -0
- data/lib/bevy/render_graph.rb +210 -0
- data/lib/bevy/resource.rb +185 -0
- data/lib/bevy/scene.rb +254 -0
- data/lib/bevy/shader.rb +319 -0
- data/lib/bevy/shape.rb +195 -0
- data/lib/bevy/skeletal.rb +248 -0
- data/lib/bevy/sprite.rb +152 -0
- data/lib/bevy/sprite_sheet.rb +444 -0
- data/lib/bevy/state.rb +277 -0
- data/lib/bevy/system.rb +206 -0
- data/lib/bevy/text.rb +99 -0
- data/lib/bevy/text_advanced.rb +455 -0
- data/lib/bevy/timer.rb +147 -0
- data/lib/bevy/transform.rb +158 -0
- data/lib/bevy/ui.rb +454 -0
- data/lib/bevy/ui_advanced.rb +568 -0
- data/lib/bevy/version.rb +5 -0
- data/lib/bevy/visibility.rb +250 -0
- data/lib/bevy/window.rb +302 -0
- data/lib/bevy.rb +390 -0
- metadata +150 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bevy
|
|
4
|
+
class Transform
|
|
5
|
+
attr_reader :translation, :rotation, :scale
|
|
6
|
+
|
|
7
|
+
def initialize(translation: nil, rotation: nil, scale: nil)
|
|
8
|
+
@translation = translation || Vec3.zero
|
|
9
|
+
@rotation = rotation || Quat.identity
|
|
10
|
+
@scale = scale || Vec3.one
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.from_translation(translation)
|
|
14
|
+
new(translation: translation)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.from_rotation(rotation)
|
|
18
|
+
new(rotation: rotation)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.from_scale(scale)
|
|
22
|
+
new(scale: scale)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.from_xyz(x, y, z)
|
|
26
|
+
new(translation: Vec3.new(x, y, z))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.identity
|
|
30
|
+
new
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def type_name
|
|
34
|
+
'Transform'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def translate(&block)
|
|
38
|
+
result = block.call(@translation)
|
|
39
|
+
@translation = result if result.is_a?(Vec3)
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def rotate(&block)
|
|
44
|
+
result = block.call(@rotation)
|
|
45
|
+
@rotation = result if result.is_a?(Quat)
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def with_translation(translation)
|
|
50
|
+
self.class.new(
|
|
51
|
+
translation: translation,
|
|
52
|
+
rotation: @rotation,
|
|
53
|
+
scale: @scale
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def with_rotation(rotation)
|
|
58
|
+
self.class.new(
|
|
59
|
+
translation: @translation,
|
|
60
|
+
rotation: rotation,
|
|
61
|
+
scale: @scale
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def with_scale(scale)
|
|
66
|
+
self.class.new(
|
|
67
|
+
translation: @translation,
|
|
68
|
+
rotation: @rotation,
|
|
69
|
+
scale: scale
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def rotate_x(angle)
|
|
74
|
+
new_rotation = @rotation * Quat.from_rotation_x(angle)
|
|
75
|
+
with_rotation(new_rotation)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def rotate_y(angle)
|
|
79
|
+
new_rotation = @rotation * Quat.from_rotation_y(angle)
|
|
80
|
+
with_rotation(new_rotation)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def rotate_z(angle)
|
|
84
|
+
new_rotation = @rotation * Quat.from_rotation_z(angle)
|
|
85
|
+
with_rotation(new_rotation)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def forward
|
|
89
|
+
@rotation.mul_vec3(Vec3.new(0.0, 0.0, -1.0))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def right
|
|
93
|
+
@rotation.mul_vec3(Vec3.new(1.0, 0.0, 0.0))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def up
|
|
97
|
+
@rotation.mul_vec3(Vec3.new(0.0, 1.0, 0.0))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def to_native
|
|
101
|
+
native = Component.new('Transform')
|
|
102
|
+
native['translation_x'] = @translation.x
|
|
103
|
+
native['translation_y'] = @translation.y
|
|
104
|
+
native['translation_z'] = @translation.z
|
|
105
|
+
native['rotation_x'] = @rotation.x
|
|
106
|
+
native['rotation_y'] = @rotation.y
|
|
107
|
+
native['rotation_z'] = @rotation.z
|
|
108
|
+
native['rotation_w'] = @rotation.w
|
|
109
|
+
native['scale_x'] = @scale.x
|
|
110
|
+
native['scale_y'] = @scale.y
|
|
111
|
+
native['scale_z'] = @scale.z
|
|
112
|
+
native
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def self.from_native(native)
|
|
116
|
+
translation = Vec3.new(
|
|
117
|
+
native['translation_x'],
|
|
118
|
+
native['translation_y'],
|
|
119
|
+
native['translation_z']
|
|
120
|
+
)
|
|
121
|
+
rotation = Quat.identity
|
|
122
|
+
scale = Vec3.new(
|
|
123
|
+
native['scale_x'] || 1.0,
|
|
124
|
+
native['scale_y'] || 1.0,
|
|
125
|
+
native['scale_z'] || 1.0
|
|
126
|
+
)
|
|
127
|
+
new(translation: translation, rotation: rotation, scale: scale)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def to_h
|
|
131
|
+
{
|
|
132
|
+
translation: @translation.to_a,
|
|
133
|
+
rotation: @rotation.to_a,
|
|
134
|
+
scale: @scale.to_a
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def to_sync_hash
|
|
139
|
+
{
|
|
140
|
+
x: @translation.x,
|
|
141
|
+
y: @translation.y,
|
|
142
|
+
z: @translation.z,
|
|
143
|
+
rotation: rotation_z_angle,
|
|
144
|
+
scale_x: @scale.x,
|
|
145
|
+
scale_y: @scale.y,
|
|
146
|
+
scale_z: @scale.z
|
|
147
|
+
}
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
private
|
|
151
|
+
|
|
152
|
+
def rotation_z_angle
|
|
153
|
+
# Extract Z rotation angle from quaternion (2D rotation)
|
|
154
|
+
# For 2D, we only care about rotation around the Z axis
|
|
155
|
+
2.0 * Math.atan2(@rotation.z, @rotation.w)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
data/lib/bevy/ui.rb
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bevy
|
|
4
|
+
module Val
|
|
5
|
+
def self.px(value)
|
|
6
|
+
{ type: :px, value: value.to_f }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.percent(value)
|
|
10
|
+
{ type: :percent, value: value.to_f }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.auto
|
|
14
|
+
{ type: :auto, value: 0.0 }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.vw(value)
|
|
18
|
+
{ type: :vw, value: value.to_f }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.vh(value)
|
|
22
|
+
{ type: :vh, value: value.to_f }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.vmin(value)
|
|
26
|
+
{ type: :vmin, value: value.to_f }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.vmax(value)
|
|
30
|
+
{ type: :vmax, value: value.to_f }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module FlexDirection
|
|
35
|
+
ROW = :row
|
|
36
|
+
ROW_REVERSE = :row_reverse
|
|
37
|
+
COLUMN = :column
|
|
38
|
+
COLUMN_REVERSE = :column_reverse
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module JustifyContent
|
|
42
|
+
START = :start
|
|
43
|
+
END_POS = :end
|
|
44
|
+
FLEX_START = :flex_start
|
|
45
|
+
FLEX_END = :flex_end
|
|
46
|
+
CENTER = :center
|
|
47
|
+
SPACE_BETWEEN = :space_between
|
|
48
|
+
SPACE_AROUND = :space_around
|
|
49
|
+
SPACE_EVENLY = :space_evenly
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
module AlignItems
|
|
53
|
+
DEFAULT = :default
|
|
54
|
+
START = :start
|
|
55
|
+
END_POS = :end
|
|
56
|
+
FLEX_START = :flex_start
|
|
57
|
+
FLEX_END = :flex_end
|
|
58
|
+
CENTER = :center
|
|
59
|
+
BASELINE = :baseline
|
|
60
|
+
STRETCH = :stretch
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module AlignSelf
|
|
64
|
+
AUTO = :auto
|
|
65
|
+
START = :start
|
|
66
|
+
END_POS = :end
|
|
67
|
+
FLEX_START = :flex_start
|
|
68
|
+
FLEX_END = :flex_end
|
|
69
|
+
CENTER = :center
|
|
70
|
+
BASELINE = :baseline
|
|
71
|
+
STRETCH = :stretch
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
module AlignContent
|
|
75
|
+
DEFAULT = :default
|
|
76
|
+
START = :start
|
|
77
|
+
END_POS = :end
|
|
78
|
+
FLEX_START = :flex_start
|
|
79
|
+
FLEX_END = :flex_end
|
|
80
|
+
CENTER = :center
|
|
81
|
+
STRETCH = :stretch
|
|
82
|
+
SPACE_BETWEEN = :space_between
|
|
83
|
+
SPACE_AROUND = :space_around
|
|
84
|
+
SPACE_EVENLY = :space_evenly
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
module Display
|
|
88
|
+
FLEX = :flex
|
|
89
|
+
GRID = :grid
|
|
90
|
+
NONE = :none
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
module PositionType
|
|
94
|
+
RELATIVE = :relative
|
|
95
|
+
ABSOLUTE = :absolute
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
module Overflow
|
|
99
|
+
VISIBLE = :visible
|
|
100
|
+
CLIP = :clip
|
|
101
|
+
SCROLL = :scroll
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
class UiRect
|
|
105
|
+
attr_accessor :left, :right, :top, :bottom
|
|
106
|
+
|
|
107
|
+
def initialize(left: nil, right: nil, top: nil, bottom: nil, all: nil, horizontal: nil, vertical: nil)
|
|
108
|
+
if all
|
|
109
|
+
@left = @right = @top = @bottom = all
|
|
110
|
+
else
|
|
111
|
+
@left = horizontal || left || Val.px(0)
|
|
112
|
+
@right = horizontal || right || Val.px(0)
|
|
113
|
+
@top = vertical || top || Val.px(0)
|
|
114
|
+
@bottom = vertical || bottom || Val.px(0)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.all(val)
|
|
119
|
+
new(all: val)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.horizontal(val)
|
|
123
|
+
new(horizontal: val)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def self.vertical(val)
|
|
127
|
+
new(vertical: val)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.axes(horizontal, vertical)
|
|
131
|
+
new(horizontal: horizontal, vertical: vertical)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def self.left(val)
|
|
135
|
+
new(left: val)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.right(val)
|
|
139
|
+
new(right: val)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.top(val)
|
|
143
|
+
new(top: val)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def self.bottom(val)
|
|
147
|
+
new(bottom: val)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def to_h
|
|
151
|
+
{ left: @left, right: @right, top: @top, bottom: @bottom }
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
class Style
|
|
156
|
+
attr_accessor :display, :position_type, :overflow_x, :overflow_y
|
|
157
|
+
attr_accessor :left, :right, :top, :bottom
|
|
158
|
+
attr_accessor :width, :height, :min_width, :min_height, :max_width, :max_height
|
|
159
|
+
attr_accessor :aspect_ratio
|
|
160
|
+
attr_accessor :margin, :padding, :border
|
|
161
|
+
attr_accessor :flex_direction, :flex_wrap, :flex_grow, :flex_shrink, :flex_basis
|
|
162
|
+
attr_accessor :justify_content, :align_items, :align_self, :align_content
|
|
163
|
+
attr_accessor :row_gap, :column_gap
|
|
164
|
+
|
|
165
|
+
def initialize(
|
|
166
|
+
display: Display::FLEX,
|
|
167
|
+
position_type: PositionType::RELATIVE,
|
|
168
|
+
overflow_x: Overflow::VISIBLE,
|
|
169
|
+
overflow_y: Overflow::VISIBLE,
|
|
170
|
+
left: Val.auto,
|
|
171
|
+
right: Val.auto,
|
|
172
|
+
top: Val.auto,
|
|
173
|
+
bottom: Val.auto,
|
|
174
|
+
width: Val.auto,
|
|
175
|
+
height: Val.auto,
|
|
176
|
+
min_width: Val.auto,
|
|
177
|
+
min_height: Val.auto,
|
|
178
|
+
max_width: Val.auto,
|
|
179
|
+
max_height: Val.auto,
|
|
180
|
+
aspect_ratio: nil,
|
|
181
|
+
margin: nil,
|
|
182
|
+
padding: nil,
|
|
183
|
+
border: nil,
|
|
184
|
+
flex_direction: FlexDirection::ROW,
|
|
185
|
+
flex_wrap: :no_wrap,
|
|
186
|
+
flex_grow: 0.0,
|
|
187
|
+
flex_shrink: 1.0,
|
|
188
|
+
flex_basis: Val.auto,
|
|
189
|
+
justify_content: JustifyContent::START,
|
|
190
|
+
align_items: AlignItems::STRETCH,
|
|
191
|
+
align_self: AlignSelf::AUTO,
|
|
192
|
+
align_content: AlignContent::DEFAULT,
|
|
193
|
+
row_gap: Val.px(0),
|
|
194
|
+
column_gap: Val.px(0)
|
|
195
|
+
)
|
|
196
|
+
@display = display
|
|
197
|
+
@position_type = position_type
|
|
198
|
+
@overflow_x = overflow_x
|
|
199
|
+
@overflow_y = overflow_y
|
|
200
|
+
@left = left
|
|
201
|
+
@right = right
|
|
202
|
+
@top = top
|
|
203
|
+
@bottom = bottom
|
|
204
|
+
@width = width
|
|
205
|
+
@height = height
|
|
206
|
+
@min_width = min_width
|
|
207
|
+
@min_height = min_height
|
|
208
|
+
@max_width = max_width
|
|
209
|
+
@max_height = max_height
|
|
210
|
+
@aspect_ratio = aspect_ratio
|
|
211
|
+
@margin = margin || UiRect.all(Val.px(0))
|
|
212
|
+
@padding = padding || UiRect.all(Val.px(0))
|
|
213
|
+
@border = border || UiRect.all(Val.px(0))
|
|
214
|
+
@flex_direction = flex_direction
|
|
215
|
+
@flex_wrap = flex_wrap
|
|
216
|
+
@flex_grow = flex_grow
|
|
217
|
+
@flex_shrink = flex_shrink
|
|
218
|
+
@flex_basis = flex_basis
|
|
219
|
+
@justify_content = justify_content
|
|
220
|
+
@align_items = align_items
|
|
221
|
+
@align_self = align_self
|
|
222
|
+
@align_content = align_content
|
|
223
|
+
@row_gap = row_gap
|
|
224
|
+
@column_gap = column_gap
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def to_h
|
|
228
|
+
{
|
|
229
|
+
display: @display,
|
|
230
|
+
position_type: @position_type,
|
|
231
|
+
overflow_x: @overflow_x,
|
|
232
|
+
overflow_y: @overflow_y,
|
|
233
|
+
left: @left,
|
|
234
|
+
right: @right,
|
|
235
|
+
top: @top,
|
|
236
|
+
bottom: @bottom,
|
|
237
|
+
width: @width,
|
|
238
|
+
height: @height,
|
|
239
|
+
min_width: @min_width,
|
|
240
|
+
min_height: @min_height,
|
|
241
|
+
max_width: @max_width,
|
|
242
|
+
max_height: @max_height,
|
|
243
|
+
aspect_ratio: @aspect_ratio,
|
|
244
|
+
margin: @margin.to_h,
|
|
245
|
+
padding: @padding.to_h,
|
|
246
|
+
border: @border.to_h,
|
|
247
|
+
flex_direction: @flex_direction,
|
|
248
|
+
flex_wrap: @flex_wrap,
|
|
249
|
+
flex_grow: @flex_grow,
|
|
250
|
+
flex_shrink: @flex_shrink,
|
|
251
|
+
flex_basis: @flex_basis,
|
|
252
|
+
justify_content: @justify_content,
|
|
253
|
+
align_items: @align_items,
|
|
254
|
+
align_self: @align_self,
|
|
255
|
+
align_content: @align_content,
|
|
256
|
+
row_gap: @row_gap,
|
|
257
|
+
column_gap: @column_gap
|
|
258
|
+
}
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
class Node
|
|
263
|
+
attr_accessor :style
|
|
264
|
+
|
|
265
|
+
def initialize(style: nil)
|
|
266
|
+
@style = style || Style.new
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def type_name
|
|
270
|
+
'Node'
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def to_h
|
|
274
|
+
{ style: @style.to_h }
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
class BackgroundColor
|
|
279
|
+
attr_accessor :color
|
|
280
|
+
|
|
281
|
+
def initialize(color = nil)
|
|
282
|
+
@color = color || Color.white
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def type_name
|
|
286
|
+
'BackgroundColor'
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def to_h
|
|
290
|
+
{ color: @color.to_a }
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
class BorderColor
|
|
295
|
+
attr_accessor :color
|
|
296
|
+
|
|
297
|
+
def initialize(color = nil)
|
|
298
|
+
@color = color || Color.transparent
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def type_name
|
|
302
|
+
'BorderColor'
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def to_h
|
|
306
|
+
{ color: @color.to_a }
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
class BorderRadius
|
|
311
|
+
attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
|
|
312
|
+
|
|
313
|
+
def initialize(top_left: Val.px(0), top_right: Val.px(0), bottom_left: Val.px(0), bottom_right: Val.px(0), all: nil)
|
|
314
|
+
if all
|
|
315
|
+
@top_left = @top_right = @bottom_left = @bottom_right = all
|
|
316
|
+
else
|
|
317
|
+
@top_left = top_left
|
|
318
|
+
@top_right = top_right
|
|
319
|
+
@bottom_left = bottom_left
|
|
320
|
+
@bottom_right = bottom_right
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def self.all(val)
|
|
325
|
+
new(all: val)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def to_h
|
|
329
|
+
{ top_left: @top_left, top_right: @top_right, bottom_left: @bottom_left, bottom_right: @bottom_right }
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
module Interaction
|
|
334
|
+
NONE = :none
|
|
335
|
+
PRESSED = :pressed
|
|
336
|
+
HOVERED = :hovered
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
class Button
|
|
340
|
+
attr_accessor :interaction
|
|
341
|
+
|
|
342
|
+
def initialize
|
|
343
|
+
@interaction = Interaction::NONE
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def type_name
|
|
347
|
+
'Button'
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def pressed?
|
|
351
|
+
@interaction == Interaction::PRESSED
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def hovered?
|
|
355
|
+
@interaction == Interaction::HOVERED
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def none?
|
|
359
|
+
@interaction == Interaction::NONE
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
class UiImage
|
|
364
|
+
attr_accessor :texture, :flip_x, :flip_y, :color
|
|
365
|
+
|
|
366
|
+
def initialize(texture: nil, flip_x: false, flip_y: false, color: nil)
|
|
367
|
+
@texture = texture
|
|
368
|
+
@flip_x = flip_x
|
|
369
|
+
@flip_y = flip_y
|
|
370
|
+
@color = color || Color.white
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def type_name
|
|
374
|
+
'UiImage'
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def to_h
|
|
378
|
+
{ texture: @texture, flip_x: @flip_x, flip_y: @flip_y, color: @color.to_a }
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
class TextBundle
|
|
383
|
+
attr_accessor :text, :style
|
|
384
|
+
|
|
385
|
+
def initialize(text:, style: nil)
|
|
386
|
+
@text = text
|
|
387
|
+
@style = style || Style.new
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
def type_name
|
|
391
|
+
'TextBundle'
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
class ButtonBundle
|
|
396
|
+
attr_accessor :node, :button, :style, :background_color, :border_color, :border_radius
|
|
397
|
+
|
|
398
|
+
def initialize(
|
|
399
|
+
style: nil,
|
|
400
|
+
background_color: nil,
|
|
401
|
+
border_color: nil,
|
|
402
|
+
border_radius: nil
|
|
403
|
+
)
|
|
404
|
+
@node = Node.new(style: style || Style.new)
|
|
405
|
+
@button = Button.new
|
|
406
|
+
@style = style || Style.new
|
|
407
|
+
@background_color = background_color || BackgroundColor.new
|
|
408
|
+
@border_color = border_color || BorderColor.new
|
|
409
|
+
@border_radius = border_radius || BorderRadius.new
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
def type_name
|
|
413
|
+
'ButtonBundle'
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
class NodeBundle
|
|
418
|
+
attr_accessor :node, :style, :background_color, :border_color, :border_radius, :z_index
|
|
419
|
+
|
|
420
|
+
def initialize(
|
|
421
|
+
style: nil,
|
|
422
|
+
background_color: nil,
|
|
423
|
+
border_color: nil,
|
|
424
|
+
border_radius: nil,
|
|
425
|
+
z_index: 0
|
|
426
|
+
)
|
|
427
|
+
@style = style || Style.new
|
|
428
|
+
@node = Node.new(style: @style)
|
|
429
|
+
@background_color = background_color || BackgroundColor.new(Color.transparent)
|
|
430
|
+
@border_color = border_color || BorderColor.new
|
|
431
|
+
@border_radius = border_radius || BorderRadius.new
|
|
432
|
+
@z_index = z_index
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def type_name
|
|
436
|
+
'NodeBundle'
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
class ImageBundle
|
|
441
|
+
attr_accessor :node, :style, :image, :background_color
|
|
442
|
+
|
|
443
|
+
def initialize(style: nil, image: nil, background_color: nil)
|
|
444
|
+
@style = style || Style.new
|
|
445
|
+
@node = Node.new(style: @style)
|
|
446
|
+
@image = image || UiImage.new
|
|
447
|
+
@background_color = background_color || BackgroundColor.new(Color.white)
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def type_name
|
|
451
|
+
'ImageBundle'
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
end
|