hokusai-zero 0.2.6.pre.pinephone6 → 0.2.6
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 +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.md +1 -1
- data/ast/src/core/input.h +1 -0
- data/ast/src/core/util.c +23 -23
- data/ast/src/core/util.h +7 -7
- data/ext/extconf.rb +3 -3
- data/hokusai.gemspec +2 -1
- data/ui/examples/counter.rb +1 -2
- data/ui/examples/forum/file.rb +1 -1
- data/ui/examples/forum/post.rb +1 -0
- data/ui/examples/forum.rb +7 -7
- data/ui/examples/spreadsheet.rb +0 -1
- data/ui/examples/tic_tac_toe.rb +6 -6
- data/ui/lib/lib_hokusai.rb +24 -25
- data/ui/spec/spec_helper.rb +1 -1
- data/ui/src/hokusai/assets/chevron-down.svg +1 -0
- data/ui/src/hokusai/automation/driver_commands/base.rb +8 -2
- data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +6 -3
- data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +5 -12
- data/ui/src/hokusai/automation/server.rb +3 -2
- data/ui/src/hokusai/backends/raylib/config.rb +1 -2
- data/ui/src/hokusai/backends/raylib/font.rb +3 -24
- data/ui/src/hokusai/backends/raylib.rb +36 -167
- data/ui/src/hokusai/backends/sdl2/config.rb +6 -9
- data/ui/src/hokusai/backends/sdl2/font.rb +1 -3
- data/ui/src/hokusai/backends/sdl2.rb +93 -188
- data/ui/src/hokusai/blocks/input.rb +2 -2
- data/ui/src/hokusai/commands/rect.rb +3 -12
- data/ui/src/hokusai/commands.rb +0 -22
- data/ui/src/hokusai/event.rb +1 -2
- data/ui/src/hokusai/events/keyboard.rb +18 -11
- data/ui/src/hokusai/events/mouse.rb +8 -10
- data/ui/src/hokusai/mounting/loop_entry.rb +1 -1
- data/ui/src/hokusai/painter.rb +8 -31
- data/ui/src/hokusai/types.rb +244 -20
- data/ui/src/hokusai.rb +35 -61
- data/xmake.lua +1 -1
- metadata +22 -32
- data/ui/examples/drag.rb +0 -154
- data/ui/examples/embedded.rb +0 -58
- data/ui/examples/game.rb +0 -143
- data/ui/examples/keyboard.rb +0 -47
- data/ui/examples/overlay.rb +0 -233
- data/ui/examples/provider.rb +0 -56
- data/ui/examples/shader/test.rb +0 -155
- data/ui/examples/shader.rb +0 -100
- data/ui/examples/wiki.rb +0 -82
- data/ui/spec/hokusai/e2e/keyboard_spec.rb +0 -52
- data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
- data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
- data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +0 -19
- data/ui/src/hokusai/assets/icons/outline/backspace.svg +0 -20
- data/ui/src/hokusai/blocks/color_picker.rb +0 -1080
- data/ui/src/hokusai/blocks/keyboard.rb +0 -249
- data/ui/src/hokusai/blocks/shader_begin.rb +0 -22
- data/ui/src/hokusai/blocks/shader_end.rb +0 -12
- data/ui/src/hokusai/blocks/slider.rb +0 -139
- data/ui/src/hokusai/blocks/texture.rb +0 -23
- data/ui/src/hokusai/commands/shader.rb +0 -33
- data/ui/src/hokusai/commands/texture.rb +0 -26
- data/ui/src/hokusai/events/touch.rb +0 -62
- data/ui/src/hokusai/types/display.rb +0 -151
- data/ui/src/hokusai/types/keyboard.rb +0 -168
- data/ui/src/hokusai/types/mouse.rb +0 -36
- data/ui/src/hokusai/types/primitives.rb +0 -56
- data/ui/src/hokusai/types/touch.rb +0 -181
- data/ui/src/hokusai/util/wrap_stream.rb +0 -193
data/ui/examples/drag.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
require_relative "../src/hokusai"
|
2
|
-
require_relative "../src/hokusai/backends/raylib"
|
3
|
-
require "ostruct"
|
4
|
-
|
5
|
-
class Item < Hokusai::Block
|
6
|
-
style <<~EOF
|
7
|
-
[style]
|
8
|
-
circleStyle {
|
9
|
-
cursor: "pointer";
|
10
|
-
}
|
11
|
-
EOF
|
12
|
-
template <<~EOF
|
13
|
-
[template]
|
14
|
-
empty {
|
15
|
-
...circleStyle
|
16
|
-
:color="color"
|
17
|
-
@mousedown="start_drag"
|
18
|
-
@mouseup="release_drag"
|
19
|
-
@mousemove="emit_drag"
|
20
|
-
}
|
21
|
-
EOF
|
22
|
-
|
23
|
-
uses(empty: Hokusai::Blocks::Empty)
|
24
|
-
|
25
|
-
computed :index
|
26
|
-
computed! :pos
|
27
|
-
computed! :color
|
28
|
-
|
29
|
-
attr_accessor :dragging
|
30
|
-
|
31
|
-
def initialize(**props)
|
32
|
-
@dragging = false
|
33
|
-
|
34
|
-
super
|
35
|
-
end
|
36
|
-
|
37
|
-
def contains(p)
|
38
|
-
(((p.x - pos[0]) * (p.x - pos[0]) + (p.y - pos[1]) * (p.y - pos[1])) <= 40 * 40)
|
39
|
-
end
|
40
|
-
|
41
|
-
def start_drag(event)
|
42
|
-
if event.left.down && contains(event.pos)
|
43
|
-
|
44
|
-
self.dragging = true
|
45
|
-
node.meta.set_prop(:z, 2)
|
46
|
-
node.meta.set_prop(:position, "absolute")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def release_drag(event)
|
51
|
-
if dragging
|
52
|
-
emit("done", index)
|
53
|
-
self.dragging = false
|
54
|
-
|
55
|
-
node.meta.set_prop(:z, nil)
|
56
|
-
node.meta.set_prop(:position, nil)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def emit_drag(event)
|
61
|
-
if dragging && event.left.down
|
62
|
-
emit("drag", index, [event.pos.x, event.pos.y])
|
63
|
-
elsif dragging
|
64
|
-
emit("done", index)
|
65
|
-
|
66
|
-
self.dragging = false
|
67
|
-
node.meta.set_prop(:z, nil)
|
68
|
-
node.meta.set_prop(:position, nil)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def render(canvas)
|
73
|
-
canvas.x = canvas.x + (canvas.width / 2)
|
74
|
-
canvas.y = canvas.y + canvas.height / 2
|
75
|
-
|
76
|
-
circle(pos[0], pos[1], 40) do |command|
|
77
|
-
command.color = color
|
78
|
-
end
|
79
|
-
|
80
|
-
yield canvas
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
class Drag < Hokusai::Block
|
86
|
-
template <<~EOF
|
87
|
-
[template]
|
88
|
-
vblock { background="233,233,233" }
|
89
|
-
[for="thing in items"]
|
90
|
-
item {
|
91
|
-
:z="z(index)"
|
92
|
-
:key="key(index, thing)"
|
93
|
-
:index="index"
|
94
|
-
@drag="update_position"
|
95
|
-
@done="update_drag_state"
|
96
|
-
:pos="pos(thing)"
|
97
|
-
:color="color(thing)"
|
98
|
-
}
|
99
|
-
EOF
|
100
|
-
|
101
|
-
uses(
|
102
|
-
vblock: Hokusai::Blocks::Vblock,
|
103
|
-
item: Item
|
104
|
-
)
|
105
|
-
|
106
|
-
attr_reader :items
|
107
|
-
|
108
|
-
def z(index)
|
109
|
-
items[index].dragging ? 2 : nil
|
110
|
-
end
|
111
|
-
|
112
|
-
def update_drag_state(index)
|
113
|
-
items[index].dragging = false
|
114
|
-
end
|
115
|
-
|
116
|
-
def key(index, thing)
|
117
|
-
"key-#{index}"
|
118
|
-
end
|
119
|
-
|
120
|
-
def pos(thing)
|
121
|
-
thing.position
|
122
|
-
end
|
123
|
-
|
124
|
-
def color(thing)
|
125
|
-
thing.color
|
126
|
-
end
|
127
|
-
|
128
|
-
def update_position(index, pos)
|
129
|
-
items[index].dragging = true
|
130
|
-
items[index].position = pos
|
131
|
-
end
|
132
|
-
|
133
|
-
def initialize(**args)
|
134
|
-
@items = [[0, 10, [222,222,0]], [100, 100, [0,222,222]], [300, 300, [0, 222, 0]]].map do |list|
|
135
|
-
item = OpenStruct.new
|
136
|
-
item.position = [list[0], list[1]]
|
137
|
-
item.color = Hokusai::Color.convert(list[2])
|
138
|
-
item.dragging = false
|
139
|
-
item
|
140
|
-
end
|
141
|
-
|
142
|
-
pp items
|
143
|
-
|
144
|
-
super
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
Hokusai::Backends::RaylibBackend.run(Drag) do |config|
|
149
|
-
config.after_load do
|
150
|
-
font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
|
151
|
-
Hokusai.fonts.register "inter", font
|
152
|
-
Hokusai.fonts.activate "inter"
|
153
|
-
end
|
154
|
-
end
|
data/ui/examples/embedded.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require_relative "../src/hokusai"
|
2
|
-
require_relative "../src/hokusai/backends/embedded"
|
3
|
-
|
4
|
-
class App < Hokusai::Block
|
5
|
-
template <<~EOF
|
6
|
-
[template]
|
7
|
-
button {
|
8
|
-
@clicked="clear_text"
|
9
|
-
height="30"
|
10
|
-
content="clear"
|
11
|
-
}
|
12
|
-
panel {
|
13
|
-
@swipe="handle_swipe"
|
14
|
-
@taphold="handle_taphold"
|
15
|
-
@pinch="handle_pinch"
|
16
|
-
}
|
17
|
-
text {
|
18
|
-
:content="text"
|
19
|
-
:size="15"
|
20
|
-
}
|
21
|
-
EOF
|
22
|
-
|
23
|
-
uses(
|
24
|
-
button: Hokusai::Blocks::Button,
|
25
|
-
panel: Hokusai::Blocks::Panel,
|
26
|
-
text: Hokusai::Blocks::Text
|
27
|
-
)
|
28
|
-
|
29
|
-
attr_accessor :text
|
30
|
-
|
31
|
-
def initialize(**args)
|
32
|
-
@text = ""
|
33
|
-
|
34
|
-
super
|
35
|
-
end
|
36
|
-
|
37
|
-
def clear_text(event)
|
38
|
-
self.text = ""
|
39
|
-
end
|
40
|
-
|
41
|
-
def handle_pinch(event)
|
42
|
-
self.text += "Pinch: #{event.pinch_direction} - #{event.pinch_pos.x}x#{event.pinch_pos.y} (#{event.pinch_angle})\n\n"
|
43
|
-
end
|
44
|
-
|
45
|
-
def handle_swipe(event)
|
46
|
-
self.text += "Swipe: #{event.drag_direction} - #{event.drag_pos.x}x#{event.drag_pos.y} (#{event.drag_angle})\n\n"
|
47
|
-
end
|
48
|
-
|
49
|
-
def handle_taphold(event)
|
50
|
-
self.text += "Taphold #{event.hold_duration}\n\n"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
Hokusai::Backends::EmbeddedBackend.run(App) do |config|
|
55
|
-
config.after_load do
|
56
|
-
Hokusai.maximize_window
|
57
|
-
end
|
58
|
-
end
|
data/ui/examples/game.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require_relative "../src/hokusai"
|
2
|
-
require_relative "../src/hokusai/backends/raylib"
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
TILES = [
|
6
|
-
["Power Supply", 500],
|
7
|
-
["Power Distribution", 400],
|
8
|
-
["Farm", 100],
|
9
|
-
["Medicine Production", 50],
|
10
|
-
["Science Research", 400],
|
11
|
-
["Lumberyard", 200],
|
12
|
-
["Art Gallery", 20],
|
13
|
-
["School", 100],
|
14
|
-
["Commercial transportation", 300],
|
15
|
-
["Mechanical Automation", 700],
|
16
|
-
["Tailor shop", 50],
|
17
|
-
["Housing Construction", 200],
|
18
|
-
["Commerical Building Construction", 300],
|
19
|
-
["Restaraunt", 50],
|
20
|
-
["Furniture manufacturing", 200],
|
21
|
-
["Cotton mill", 200],
|
22
|
-
["Metals processing", 400],
|
23
|
-
["Forestry center", 400],
|
24
|
-
["Bar", 50],
|
25
|
-
["Healthcare", 100]
|
26
|
-
]
|
27
|
-
|
28
|
-
|
29
|
-
class Game < Hokusai::Block
|
30
|
-
style <<-EOF
|
31
|
-
[style]
|
32
|
-
bg {
|
33
|
-
color: rgb(173, 207, 224);
|
34
|
-
width: 100;
|
35
|
-
height: 100;
|
36
|
-
outline: outline(1.0, 1.0, 1.0, 1.0);
|
37
|
-
outline_color: rgb(0, 0, 0);
|
38
|
-
}
|
39
|
-
board {
|
40
|
-
height: 500;
|
41
|
-
width: 500;
|
42
|
-
}
|
43
|
-
height {
|
44
|
-
height: 100;
|
45
|
-
}
|
46
|
-
textPadding {
|
47
|
-
padding: padding(10.0, 5.0, 10.0, 10.0);
|
48
|
-
}
|
49
|
-
EOF
|
50
|
-
template <<~EOF
|
51
|
-
[template]
|
52
|
-
vblock { ...board }
|
53
|
-
hblock
|
54
|
-
[for="tile in top"]
|
55
|
-
rect { :key="top_key(tile)" ...bg }
|
56
|
-
text { :content="tile" ...textPadding}
|
57
|
-
[for="i in middle"]
|
58
|
-
hblock {...height :key="get(i)"}
|
59
|
-
rect {...bg}
|
60
|
-
text { :key="get(i)" :content="get(i)" ...textPadding }
|
61
|
-
empty
|
62
|
-
empty
|
63
|
-
empty
|
64
|
-
rect {...bg }
|
65
|
-
text { :key="get_next(i)" :content="get_next(i)" ...textPadding}
|
66
|
-
hblock
|
67
|
-
[for="tile in bottom"]
|
68
|
-
rect { ...bg :key="bottom_key(tile)" }
|
69
|
-
text { :key="tile" :content="tile" ...textPadding }
|
70
|
-
EOF
|
71
|
-
|
72
|
-
uses(
|
73
|
-
hblock: Hokusai::Blocks::Hblock,
|
74
|
-
vblock: Hokusai::Blocks::Vblock,
|
75
|
-
text: Hokusai::Blocks::Text,
|
76
|
-
empty: Hokusai::Blocks::Empty,
|
77
|
-
rect: Hokusai::Blocks::Rect
|
78
|
-
)
|
79
|
-
|
80
|
-
attr_reader :tiles
|
81
|
-
|
82
|
-
def get(i)
|
83
|
-
tiles[i[0]].title
|
84
|
-
end
|
85
|
-
|
86
|
-
def get_next(i)
|
87
|
-
tiles[i[1]].title
|
88
|
-
end
|
89
|
-
|
90
|
-
def middle
|
91
|
-
(5..10).each_slice(2).to_a
|
92
|
-
end
|
93
|
-
|
94
|
-
def bottom_key(t)
|
95
|
-
"bottom-#{t}"
|
96
|
-
end
|
97
|
-
|
98
|
-
def top_key(t)
|
99
|
-
"top-#{t}"
|
100
|
-
end
|
101
|
-
|
102
|
-
def top
|
103
|
-
tiles.take(5).map(&:title)
|
104
|
-
end
|
105
|
-
|
106
|
-
def bottom
|
107
|
-
a = tiles[-5, 5].map(&:title)
|
108
|
-
a
|
109
|
-
end
|
110
|
-
|
111
|
-
def after_updated
|
112
|
-
@tiles = TILES.map do |(label, cost)|
|
113
|
-
os = OpenStruct.new
|
114
|
-
os.title = label
|
115
|
-
os.cost = cost
|
116
|
-
os
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def initialize(**args)
|
121
|
-
@tiles = TILES.map do |(label, cost)|
|
122
|
-
os = OpenStruct.new
|
123
|
-
os.title = label
|
124
|
-
os.cost = cost
|
125
|
-
os
|
126
|
-
end
|
127
|
-
|
128
|
-
super
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
Hokusai::Backends::RaylibBackend.run(Game) do |config|
|
134
|
-
config.width = 500
|
135
|
-
config.height = 500
|
136
|
-
|
137
|
-
config.after_load do
|
138
|
-
font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/OpenSans-Regular.ttf", 160)
|
139
|
-
Hokusai.fonts.register "opensans", font
|
140
|
-
Hokusai.fonts.activate "opensans"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
data/ui/examples/keyboard.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require_relative "../src/hokusai"
|
2
|
-
require_relative "../src/hokusai/backends/sdl2"
|
3
|
-
require_relative "../src/hokusai/backends/raylib"
|
4
|
-
|
5
|
-
class KeyboardExample < Hokusai::Block
|
6
|
-
style <<~EOF
|
7
|
-
[style]
|
8
|
-
example {
|
9
|
-
background: rgb(225,255,255);
|
10
|
-
reverse: true
|
11
|
-
}
|
12
|
-
input {
|
13
|
-
size: 20;
|
14
|
-
color: rgb(0, 0, 0);
|
15
|
-
}
|
16
|
-
EOF
|
17
|
-
|
18
|
-
template <<~EOF
|
19
|
-
[template]
|
20
|
-
vblock { ...example }
|
21
|
-
keyboard
|
22
|
-
vblock
|
23
|
-
input {
|
24
|
-
...input
|
25
|
-
}
|
26
|
-
EOF
|
27
|
-
|
28
|
-
uses(
|
29
|
-
input: Hokusai::Blocks::Input,
|
30
|
-
vblock: Hokusai::Blocks::Vblock,
|
31
|
-
text: Hokusai::Blocks::Text,
|
32
|
-
keyboard: Hokusai::Blocks::Keyboard
|
33
|
-
)
|
34
|
-
|
35
|
-
attr_accessor :content
|
36
|
-
|
37
|
-
def initialize(**args)
|
38
|
-
super
|
39
|
-
@content = ""
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
Hokusai::Backends::RaylibBackend.run(KeyboardExample) do |config|
|
44
|
-
config.width = 370
|
45
|
-
config.height = 680
|
46
|
-
config.title = "keyboard example"
|
47
|
-
end
|
data/ui/examples/overlay.rb
DELETED
@@ -1,233 +0,0 @@
|
|
1
|
-
require_relative "../src/hokusai"
|
2
|
-
require_relative "../src/hokusai/backends/raylib"
|
3
|
-
|
4
|
-
class DropdownItem < Hokusai::Block
|
5
|
-
style <<~EOF
|
6
|
-
[style]
|
7
|
-
textStyle {
|
8
|
-
padding: padding(5.0, 5.0, 5.0, 5.0);
|
9
|
-
size: 23;
|
10
|
-
color: rgb(255,255,255);
|
11
|
-
cursor: "pointer";
|
12
|
-
}
|
13
|
-
EOF
|
14
|
-
|
15
|
-
template <<~EOF
|
16
|
-
[template]
|
17
|
-
text#second {
|
18
|
-
:content="content"
|
19
|
-
...textStyle
|
20
|
-
@click="emit_option"
|
21
|
-
@height_updated="udpate_height"
|
22
|
-
}
|
23
|
-
EOF
|
24
|
-
|
25
|
-
uses(text: Hokusai::Blocks::Text)
|
26
|
-
|
27
|
-
computed! :content
|
28
|
-
computed! :index
|
29
|
-
|
30
|
-
def udpate_height(height)
|
31
|
-
node.portal.meta.set_prop(:height, height)
|
32
|
-
emit("height", height, index)
|
33
|
-
end
|
34
|
-
|
35
|
-
def emit_option(e)
|
36
|
-
emit("option", content)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Dropdown < Hokusai::Block
|
41
|
-
style <<-EOF
|
42
|
-
[style]
|
43
|
-
panelStyle {
|
44
|
-
z: 1;
|
45
|
-
width: 200;
|
46
|
-
height: 300;
|
47
|
-
background: rgb(67, 64, 92);
|
48
|
-
}
|
49
|
-
|
50
|
-
labelStyle {
|
51
|
-
size: 22;
|
52
|
-
content: "Please choose your fruit?";
|
53
|
-
}
|
54
|
-
EOF
|
55
|
-
|
56
|
-
template <<~EOF
|
57
|
-
[template]
|
58
|
-
vblock { @click="toggle_dropdown" height="70"}
|
59
|
-
label { ...labelStyle }
|
60
|
-
label { :content="selected" size="25" }
|
61
|
-
[if="toggled"]
|
62
|
-
panel#first { ...panelStyle @click="stop"}
|
63
|
-
[for="option in options"]
|
64
|
-
item {
|
65
|
-
:height="get_height(index)"
|
66
|
-
:content="option"
|
67
|
-
:key="index"
|
68
|
-
:index="index"
|
69
|
-
@option="select"
|
70
|
-
@height="update_height"
|
71
|
-
}
|
72
|
-
EOF
|
73
|
-
|
74
|
-
uses(label: Hokusai::Blocks::Label, vblock: Hokusai::Blocks::Vblock, item: DropdownItem, panel: Hokusai::Blocks::Panel)
|
75
|
-
|
76
|
-
attr_reader :toggled
|
77
|
-
|
78
|
-
computed! :options
|
79
|
-
|
80
|
-
def list_height
|
81
|
-
@heights ||= {}
|
82
|
-
@heights.values.reduce(&:+) || 0.0
|
83
|
-
end
|
84
|
-
|
85
|
-
def get_height(index)
|
86
|
-
@heights ||= {}
|
87
|
-
@heights[index] || 0.0
|
88
|
-
end
|
89
|
-
|
90
|
-
def update_height(height, index)
|
91
|
-
@heights ||= {}
|
92
|
-
@heights[index] = height
|
93
|
-
end
|
94
|
-
|
95
|
-
def stop(e)
|
96
|
-
end
|
97
|
-
|
98
|
-
def toggle_dropdown(_)
|
99
|
-
@toggled = !@toggled
|
100
|
-
end
|
101
|
-
|
102
|
-
def select(option)
|
103
|
-
@selected = option
|
104
|
-
@toggled = false
|
105
|
-
end
|
106
|
-
|
107
|
-
# def options
|
108
|
-
# %w[apple pear mango pineapple orange pear bananana kiwi grapes melon lemon lime]
|
109
|
-
# end
|
110
|
-
|
111
|
-
def selected
|
112
|
-
@selected || options.first
|
113
|
-
end
|
114
|
-
|
115
|
-
def initialize(**args)
|
116
|
-
@toggled = true
|
117
|
-
|
118
|
-
super
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
class Modal < Hokusai::Block
|
123
|
-
template <<~EOF
|
124
|
-
[template]
|
125
|
-
hblock#top
|
126
|
-
empty
|
127
|
-
empty#topempty
|
128
|
-
text { @click="emit_close" content="X" size="40" color="255,255,255}
|
129
|
-
hblock#middle { height="300"}
|
130
|
-
slot
|
131
|
-
hblock#last
|
132
|
-
empty#lastempty
|
133
|
-
EOF
|
134
|
-
|
135
|
-
uses(vblock: Hokusai::Blocks::Vblock, empty: Hokusai::Blocks::Empty, hblock: Hokusai::Blocks::Hblock, text: Hokusai::Blocks::Label)
|
136
|
-
|
137
|
-
computed :color, default: [0, 0, 0, 200], convert: Hokusai::Color
|
138
|
-
|
139
|
-
def emit_close(event)
|
140
|
-
emit("close")
|
141
|
-
|
142
|
-
event.stop
|
143
|
-
end
|
144
|
-
|
145
|
-
def render(canvas)
|
146
|
-
draw do
|
147
|
-
rect(canvas.x, canvas.y, canvas.width, canvas.height) do |command|
|
148
|
-
command.color = color
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
yield canvas
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
class Thing < Hokusai::Block
|
157
|
-
style <<~EOF
|
158
|
-
[style]
|
159
|
-
textStyle {
|
160
|
-
size: 30;
|
161
|
-
color: rgb(0, 0, 0);
|
162
|
-
content: "Hello modal!";
|
163
|
-
}
|
164
|
-
|
165
|
-
otherText {
|
166
|
-
size: 25;
|
167
|
-
content: "Hello World";
|
168
|
-
}
|
169
|
-
contentStyle {
|
170
|
-
height: 300.0;
|
171
|
-
width: 300.0;
|
172
|
-
background: rgb(255, 255, 255, 255);
|
173
|
-
}
|
174
|
-
backgroundStyle {
|
175
|
-
background: rgb(43, 151, 117);
|
176
|
-
}
|
177
|
-
modalStyle {
|
178
|
-
z: 1;
|
179
|
-
position: "absolute";
|
180
|
-
}
|
181
|
-
EOF
|
182
|
-
|
183
|
-
template <<~EOF
|
184
|
-
[template]
|
185
|
-
vblock#topnot
|
186
|
-
hblock#not{ ...backgroundStyle }
|
187
|
-
text#not { ...otherText @click="open_modal" }
|
188
|
-
dropdown { :options="outer_options" }
|
189
|
-
hblock { background="233,0,0" }
|
190
|
-
text#second { content="Second" }
|
191
|
-
modal {
|
192
|
-
@close="close"
|
193
|
-
:active="modal_open"
|
194
|
-
}
|
195
|
-
vblock { ...contentStyle }
|
196
|
-
dropdown { :options="inner_options" }
|
197
|
-
color_picker
|
198
|
-
text#last { size="30" content="last"}
|
199
|
-
EOF
|
200
|
-
|
201
|
-
attr_reader :modal_open
|
202
|
-
|
203
|
-
def log(event)
|
204
|
-
pp ["clicked!"]
|
205
|
-
end
|
206
|
-
|
207
|
-
def outer_options
|
208
|
-
%w[sam betty fred candace justin lucy annabelle nick janessa sean]
|
209
|
-
end
|
210
|
-
|
211
|
-
def inner_options
|
212
|
-
%w[apple pear mango pineapple orange pear bananana kiwi grapes melon lemon lime]
|
213
|
-
end
|
214
|
-
|
215
|
-
def open_modal(event)
|
216
|
-
@modal_open = true
|
217
|
-
end
|
218
|
-
|
219
|
-
def close
|
220
|
-
@modal_open = false
|
221
|
-
end
|
222
|
-
|
223
|
-
uses(
|
224
|
-
color_picker: Hokusai::Blocks::ColorPicker, modal: Hokusai::Blocks::Modal, dropdown: Hokusai::Blocks::Dropdown, vblock: Hokusai::Blocks::Vblock, text: Hokusai::Blocks::Text,empty: Hokusai::Blocks::Empty, hblock: Hokusai::Blocks::Hblock)
|
225
|
-
end
|
226
|
-
|
227
|
-
Hokusai::Backends::RaylibBackend.run(Thing) do |config|
|
228
|
-
config.after_load do
|
229
|
-
font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
|
230
|
-
Hokusai.fonts.register "inter", font
|
231
|
-
Hokusai.fonts.activate "inter"
|
232
|
-
end
|
233
|
-
end
|
data/ui/examples/provider.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require_relative "../src/hokusai"
|
2
|
-
require_relative "../src/hokusai/backends/raylib"
|
3
|
-
|
4
|
-
class Child < Hokusai::Block
|
5
|
-
template <<~EOF
|
6
|
-
[template]
|
7
|
-
text { :content="get_content" @selected="handle_selected" @height_updated="update_height"}
|
8
|
-
EOF
|
9
|
-
|
10
|
-
uses(
|
11
|
-
vblock: Hokusai::Blocks::Vblock,
|
12
|
-
text: Hokusai::Blocks::Text,
|
13
|
-
input: Hokusai::Blocks::Input
|
14
|
-
)
|
15
|
-
|
16
|
-
def update_height(height)
|
17
|
-
node.meta.set_prop(:height, height)
|
18
|
-
end
|
19
|
-
|
20
|
-
def handle_selected(start, stop)
|
21
|
-
pp [start, stop]
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_content
|
25
|
-
@file ||= File.read(__FILE__)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class ProviderExample < Hokusai::Block
|
30
|
-
template <<~EOF
|
31
|
-
[template]
|
32
|
-
selectable
|
33
|
-
panel
|
34
|
-
text { :content="get_content" }
|
35
|
-
EOF
|
36
|
-
|
37
|
-
uses(
|
38
|
-
vblock: Hokusai::Blocks::Vblock,
|
39
|
-
selectable: Hokusai::Blocks::Selectable,
|
40
|
-
panel: Hokusai::Blocks::Panel,
|
41
|
-
child: Child,
|
42
|
-
text: Hokusai::Blocks::Text
|
43
|
-
)
|
44
|
-
|
45
|
-
def get_content
|
46
|
-
@file ||= File.read(__FILE__)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
Hokusai::Backends::RaylibBackend.run(ProviderExample) do |config|
|
52
|
-
config.width = 500
|
53
|
-
config.height = 500
|
54
|
-
config.title = "Provider application"
|
55
|
-
end
|
56
|
-
|