hokusai-zero 0.1.1
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/Dockerfile +26 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +91 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/ast/genheader +3 -0
- data/ast/include/hashmap.c +1151 -0
- data/ast/include/hashmap.c.license +20 -0
- data/ast/include/hashmap.h +54 -0
- data/ast/src/core/ast.c +448 -0
- data/ast/src/core/ast.h +259 -0
- data/ast/src/core/common.h +24 -0
- data/ast/src/core/component.c +85 -0
- data/ast/src/core/component.h +35 -0
- data/ast/src/core/hml.c +665 -0
- data/ast/src/core/hml.h +11 -0
- data/ast/src/core/input.c +458 -0
- data/ast/src/core/input.h +118 -0
- data/ast/src/core/style.c +101 -0
- data/ast/src/core/style.h +41 -0
- data/ast/src/core/text.c +784 -0
- data/ast/src/core/text.h +93 -0
- data/ast/src/core/util.c +140 -0
- data/ast/src/core/util.h +48 -0
- data/ast/src/hokusai.c +6 -0
- data/ast/src/hokusai.h +6 -0
- data/ast/test/fixtures/test.ui +13 -0
- data/ast/test/greatest.h +1266 -0
- data/ast/test/hokusai.c +14 -0
- data/ast/test/parser.c +234 -0
- data/ast/test/text.c +116 -0
- data/ext/extconf.rb +27 -0
- data/grammar/Cargo.lock +80 -0
- data/grammar/Cargo.toml +26 -0
- data/grammar/binding.gyp +20 -0
- data/grammar/bindings/node/binding.cc +28 -0
- data/grammar/bindings/node/index.js +19 -0
- data/grammar/bindings/rust/build.rs +40 -0
- data/grammar/bindings/rust/lib.rs +52 -0
- data/grammar/corpus/1_document.txt +131 -0
- data/grammar/corpus/2_selectors.txt +58 -0
- data/grammar/corpus/3_spaces.txt +69 -0
- data/grammar/corpus/4_errors.txt +10 -0
- data/grammar/corpus/5_macros.txt +175 -0
- data/grammar/corpus/6_styles.txt +81 -0
- data/grammar/grammar.js +275 -0
- data/grammar/package-lock.json +34 -0
- data/grammar/package.json +33 -0
- data/grammar/src/grammar.json +1269 -0
- data/grammar/src/node-types.json +474 -0
- data/grammar/src/parser.c +5772 -0
- data/grammar/src/scanner.c +258 -0
- data/grammar/src/tree_sitter/parser.h +230 -0
- data/grammar/src/tree_sitter/scanner.h +12 -0
- data/grammar/test.nml +10 -0
- data/hokusai.gemspec +19 -0
- data/ui/examples/assets/DigitalDisplay.ttf +0 -0
- data/ui/examples/assets/OpenSans-Regular.ttf +0 -0
- data/ui/examples/assets/addy.png +0 -0
- data/ui/examples/assets/baby_sean.png +0 -0
- data/ui/examples/assets/football-troll.png +0 -0
- data/ui/examples/assets/gear.png +0 -0
- data/ui/examples/assets/icecold.ttf +0 -0
- data/ui/examples/assets/science-troll.png +0 -0
- data/ui/examples/buddy.rb +31 -0
- data/ui/examples/clock.rb +58 -0
- data/ui/examples/counter.rb +123 -0
- data/ui/examples/dynamic.rb +147 -0
- data/ui/examples/foobar.rb +236 -0
- data/ui/examples/stock.rb +115 -0
- data/ui/examples/stock_decider/option.rb +74 -0
- data/ui/examples/tic_tac_toe.rb +246 -0
- data/ui/lib/lib_hokusai.rb +425 -0
- data/ui/spec/hokusai/ast_spec.rb +88 -0
- data/ui/spec/hokusai/automation/keys_transcoder_spec.rb +50 -0
- data/ui/spec/hokusai/automation/selector_spec.rb +68 -0
- data/ui/spec/hokusai/block_spec.rb +126 -0
- data/ui/spec/hokusai/directives_spec.rb +327 -0
- data/ui/spec/hokusai/e2e/client_spec.rb +58 -0
- data/ui/spec/hokusai/e2e/meta_spec.rb +42 -0
- data/ui/spec/hokusai/publisher_spec.rb +38 -0
- data/ui/spec/hokusai/slots_spec.rb +150 -0
- data/ui/spec/hokusai/util/piece_table_spec.rb +90 -0
- data/ui/spec/hokusai_spec.rb +0 -0
- data/ui/spec/spec_helper.rb +30 -0
- data/ui/src/hokusai/ast.rb +446 -0
- data/ui/src/hokusai/automation/client.rb +167 -0
- data/ui/src/hokusai/automation/constants.rb +98 -0
- data/ui/src/hokusai/automation/converters/selector_converter.rb +61 -0
- data/ui/src/hokusai/automation/driver.rb +54 -0
- data/ui/src/hokusai/automation/driver_command_queue.rb +50 -0
- data/ui/src/hokusai/automation/driver_commands/base.rb +79 -0
- data/ui/src/hokusai/automation/driver_commands/get_attribute.rb +41 -0
- data/ui/src/hokusai/automation/driver_commands/invoke.rb +33 -0
- data/ui/src/hokusai/automation/driver_commands/locate.rb +48 -0
- data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +94 -0
- data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +213 -0
- data/ui/src/hokusai/automation/keys_transcoder.rb +128 -0
- data/ui/src/hokusai/automation/selector.rb +39 -0
- data/ui/src/hokusai/automation/server.rb +114 -0
- data/ui/src/hokusai/automation.rb +3 -0
- data/ui/src/hokusai/backends/raylib/config.rb +47 -0
- data/ui/src/hokusai/backends/raylib/font.rb +113 -0
- data/ui/src/hokusai/backends/raylib/keys.rb +124 -0
- data/ui/src/hokusai/backends/raylib.rb +449 -0
- data/ui/src/hokusai/backends/sdl2/Monaco.ttf +0 -0
- data/ui/src/hokusai/backends/sdl2/color.rb +12 -0
- data/ui/src/hokusai/backends/sdl2/config.rb +31 -0
- data/ui/src/hokusai/backends/sdl2/font.rb +127 -0
- data/ui/src/hokusai/backends/sdl2/keys.rb +119 -0
- data/ui/src/hokusai/backends/sdl2.rb +529 -0
- data/ui/src/hokusai/block.rb +237 -0
- data/ui/src/hokusai/blocks/button.rb +100 -0
- data/ui/src/hokusai/blocks/checkbox.rb +51 -0
- data/ui/src/hokusai/blocks/circle.rb +28 -0
- data/ui/src/hokusai/blocks/clipped.rb +23 -0
- data/ui/src/hokusai/blocks/cursor.rb +49 -0
- data/ui/src/hokusai/blocks/dynamic.rb +37 -0
- data/ui/src/hokusai/blocks/empty.rb +10 -0
- data/ui/src/hokusai/blocks/hblock.rb +35 -0
- data/ui/src/hokusai/blocks/image.rb +18 -0
- data/ui/src/hokusai/blocks/input.rb +200 -0
- data/ui/src/hokusai/blocks/label.rb +39 -0
- data/ui/src/hokusai/blocks/panel.rb +126 -0
- data/ui/src/hokusai/blocks/rect.rb +24 -0
- data/ui/src/hokusai/blocks/scissor_begin.rb +18 -0
- data/ui/src/hokusai/blocks/scissor_end.rb +12 -0
- data/ui/src/hokusai/blocks/scrollbar.rb +103 -0
- data/ui/src/hokusai/blocks/selectable.rb +77 -0
- data/ui/src/hokusai/blocks/svg.rb +20 -0
- data/ui/src/hokusai/blocks/text.rb +214 -0
- data/ui/src/hokusai/blocks/titlebar/osx.rb +145 -0
- data/ui/src/hokusai/blocks/toggle.rb +55 -0
- data/ui/src/hokusai/blocks/vblock.rb +35 -0
- data/ui/src/hokusai/commands/base.rb +22 -0
- data/ui/src/hokusai/commands/circle.rb +47 -0
- data/ui/src/hokusai/commands/image.rb +45 -0
- data/ui/src/hokusai/commands/rect.rb +158 -0
- data/ui/src/hokusai/commands/scissor.rb +22 -0
- data/ui/src/hokusai/commands/text.rb +92 -0
- data/ui/src/hokusai/commands.rb +87 -0
- data/ui/src/hokusai/diff.rb +124 -0
- data/ui/src/hokusai/error.rb +3 -0
- data/ui/src/hokusai/event.rb +54 -0
- data/ui/src/hokusai/events/keyboard.rb +84 -0
- data/ui/src/hokusai/events/mouse.rb +172 -0
- data/ui/src/hokusai/font.rb +280 -0
- data/ui/src/hokusai/meta.rb +152 -0
- data/ui/src/hokusai/mounting/loop_entry.rb +230 -0
- data/ui/src/hokusai/mounting/mount_entry.rb +74 -0
- data/ui/src/hokusai/mounting/update_entry.rb +101 -0
- data/ui/src/hokusai/node.rb +98 -0
- data/ui/src/hokusai/node_mounter.rb +102 -0
- data/ui/src/hokusai/painter.rb +214 -0
- data/ui/src/hokusai/publisher.rb +32 -0
- data/ui/src/hokusai/style.rb +72 -0
- data/ui/src/hokusai/types.rb +266 -0
- data/ui/src/hokusai/util/clamping_iterator.rb +202 -0
- data/ui/src/hokusai/util/piece_table.rb +111 -0
- data/ui/src/hokusai/util/selection.rb +145 -0
- data/ui/src/hokusai.rb +120 -0
- data/ui/vendor/.gitkeep +0 -0
- data/vendor/.gitkeep +0 -0
- data/xmake.lua +192 -0
- metadata +222 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
module Hokusai::Util
|
2
|
+
class SegmentRenderer
|
3
|
+
attr_reader :iterator, :segment
|
4
|
+
attr_accessor :started, :start_select, :stop_select,
|
5
|
+
:select_x, :select_width
|
6
|
+
|
7
|
+
def initialize(segment, iterator)
|
8
|
+
@segment = segment
|
9
|
+
@iterator = iterator
|
10
|
+
@started = false
|
11
|
+
@start_select = 0
|
12
|
+
@stop_select = nil
|
13
|
+
@select_x = nil
|
14
|
+
@select_width = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw(font_size, boundary, selection: nil)
|
18
|
+
selection_extract(font_size, boundary, selection: selection)
|
19
|
+
draw_text(font_size, boundary)
|
20
|
+
selection_update(selection)
|
21
|
+
# self.start_select = 0.0
|
22
|
+
# self.stop_select = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def selection_extract(font_size, boundary, selection: nil)
|
26
|
+
local_x = iterator.x
|
27
|
+
y = iterator.y
|
28
|
+
hit_box = Hokusai::Rect.new(0, 0, 0, 0)
|
29
|
+
|
30
|
+
segment.chars.each do |char|
|
31
|
+
if can_render_inside(font_size, boundary) && segment.char_is_selected(char)
|
32
|
+
self.select_x ||= local_x
|
33
|
+
self.select_width = select_width.nil? ? char.width : (select_width + char.width)
|
34
|
+
|
35
|
+
if selector = selection
|
36
|
+
if segment.select_begin == char.offset && selector.up? && !iterator.cursor_set && !selector.started
|
37
|
+
iterator.cursor_position = [local_x, y, char.width, font_size.to_f]
|
38
|
+
iterator.cursor_set = true
|
39
|
+
selector.started = true
|
40
|
+
elsif segment.select_end == char.offset && selector.down? && started
|
41
|
+
iterator.cursor_position = [local_x + char.width, y, char.width, font_size.to_f]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
elsif !segment.select_end.nil? && segment.select_end < char.offset
|
45
|
+
selection&.started = false
|
46
|
+
end
|
47
|
+
|
48
|
+
# hit_box.x = local_x
|
49
|
+
# hit_box.y = y
|
50
|
+
# hit_box.width = char.width
|
51
|
+
# hit_box.height = font_size.to_f
|
52
|
+
hit_box = Hokusai::Rect.new(local_x, y, char.width, font_size.to_f)
|
53
|
+
iterator.on_char_cb&.call(char, hit_box, char.offset)
|
54
|
+
|
55
|
+
if selector = selection
|
56
|
+
if selector.active? && selector.selected(local_x, y, char.width.to_f, font_size.to_f)
|
57
|
+
self.stop_select = char.offset
|
58
|
+
|
59
|
+
unless started
|
60
|
+
self.start_select = char.offset
|
61
|
+
self.started = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
local_x += char.width
|
67
|
+
end
|
68
|
+
|
69
|
+
return unless select_x && select_width
|
70
|
+
iterator.on_draw_selection_cb&.call(select_x, y, select_width, font_size.to_f)
|
71
|
+
end
|
72
|
+
|
73
|
+
def selection_update(selection)
|
74
|
+
return unless selection&.active?
|
75
|
+
segment.make_selection(start_select, stop_select)
|
76
|
+
|
77
|
+
return if stop_select.nil?
|
78
|
+
|
79
|
+
iterator.start_select ||= start_select + iterator.cursor_offset
|
80
|
+
iterator.stop_select = stop_select + iterator.cursor_offset
|
81
|
+
end
|
82
|
+
|
83
|
+
def draw_text(font_size, boundary)
|
84
|
+
if can_render_inside(font_size, boundary)
|
85
|
+
x = @iterator.x
|
86
|
+
|
87
|
+
if @iterator.clamping.markdown
|
88
|
+
|
89
|
+
segment.groups.each do |group|
|
90
|
+
text = iterator.clamping[group.offset, group.size]
|
91
|
+
|
92
|
+
if text == " "
|
93
|
+
x += group.width * 2
|
94
|
+
|
95
|
+
next
|
96
|
+
end
|
97
|
+
|
98
|
+
@iterator.on_draw_cb&.call(text, x, y, group)
|
99
|
+
x += group.width
|
100
|
+
end
|
101
|
+
else
|
102
|
+
@iterator.on_draw_cb&.call(text, x, y, segment)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
@iterator.y += font_size
|
107
|
+
@iterator.height += font_size
|
108
|
+
end
|
109
|
+
|
110
|
+
def x
|
111
|
+
iterator.x
|
112
|
+
end
|
113
|
+
|
114
|
+
def y
|
115
|
+
iterator.y
|
116
|
+
end
|
117
|
+
|
118
|
+
def text
|
119
|
+
iterator.clamping[segment.offset, segment.size]
|
120
|
+
end
|
121
|
+
|
122
|
+
def can_render_inside(font_size, boundary)
|
123
|
+
iterator.y >= boundary[0] && iterator.y + font_size <= boundary[1]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class ClampingIterator
|
128
|
+
attr_reader :segments, :clamping,
|
129
|
+
:on_draw_cb, :on_draw_selection_cb,
|
130
|
+
:on_selection_change_cb, :on_cursor_change_cb,
|
131
|
+
:on_char_cb
|
132
|
+
|
133
|
+
attr_accessor :produced, :height, :cursor_offset, :x, :y,
|
134
|
+
:start_select, :stop_select, :cursor_position, :cursor_set
|
135
|
+
|
136
|
+
def initialize(clamping, x, y)
|
137
|
+
@clamping = clamping
|
138
|
+
@x = x
|
139
|
+
@y = y
|
140
|
+
@height = 0
|
141
|
+
@cursor_offset = 0
|
142
|
+
@cursor_set = false
|
143
|
+
@i = 0
|
144
|
+
end
|
145
|
+
|
146
|
+
def reset
|
147
|
+
@i = 0
|
148
|
+
end
|
149
|
+
|
150
|
+
def debug
|
151
|
+
clamping.debug
|
152
|
+
end
|
153
|
+
|
154
|
+
def segments
|
155
|
+
clamping.segments
|
156
|
+
end
|
157
|
+
|
158
|
+
def next
|
159
|
+
if @i < segments.size
|
160
|
+
SegmentRenderer.new(segments[@i], self)
|
161
|
+
else
|
162
|
+
if position = cursor_position
|
163
|
+
on_cursor_change_cb&.call(position)
|
164
|
+
end
|
165
|
+
|
166
|
+
if start = start_select
|
167
|
+
on_selection_change_cb&.call(start, stop_select)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
ensure
|
171
|
+
@i += 1
|
172
|
+
end
|
173
|
+
|
174
|
+
def cursor_y
|
175
|
+
y
|
176
|
+
end
|
177
|
+
|
178
|
+
def cursor_x
|
179
|
+
x
|
180
|
+
end
|
181
|
+
|
182
|
+
def on_draw(&block)
|
183
|
+
@on_draw_cb = block
|
184
|
+
end
|
185
|
+
|
186
|
+
def on_draw_selection(&block)
|
187
|
+
@on_draw_selection_cb = block
|
188
|
+
end
|
189
|
+
|
190
|
+
def on_selection_change(&block)
|
191
|
+
@on_selection_change_cb = block
|
192
|
+
end
|
193
|
+
|
194
|
+
def on_cursor_change(&block)
|
195
|
+
@on_cursor_change_cb = block
|
196
|
+
end
|
197
|
+
|
198
|
+
def on_char(&block)
|
199
|
+
@on_char_cb = block
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
module Hokusai::Util
|
4
|
+
class PieceTable
|
5
|
+
attr_accessor :buffer, :buffer_add, :last_piece_index
|
6
|
+
attr_reader :pieces
|
7
|
+
|
8
|
+
def initialize(buffer = "")
|
9
|
+
@pieces = [[:original, 0, buffer.size]]
|
10
|
+
@buffer_add = ""
|
11
|
+
@buffer = buffer
|
12
|
+
@last_piece_index = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
io = StringIO.open do |io|
|
17
|
+
pieces.each do |(which, start, size)|
|
18
|
+
case which
|
19
|
+
when :original
|
20
|
+
io.write buffer[start, size]
|
21
|
+
else
|
22
|
+
if buffer_add[start, size].nil?
|
23
|
+
raise Hokusai::Error.new("#{which} Bad: #{start} #{size}")
|
24
|
+
end
|
25
|
+
|
26
|
+
io.write buffer_add[start, size]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
io.string
|
31
|
+
end
|
32
|
+
|
33
|
+
io
|
34
|
+
end
|
35
|
+
|
36
|
+
def insert(text, offset = buffer.size - 1)
|
37
|
+
return nil if text.size.zero?
|
38
|
+
|
39
|
+
piece_at_buffer_offset(offset) do |(piece, index, remainder)|
|
40
|
+
which, start, size = piece
|
41
|
+
length = remainder - start
|
42
|
+
|
43
|
+
new_pieces = []
|
44
|
+
new_pieces << [which, start, length] if length > 0
|
45
|
+
new_pieces << [:add, buffer_add.size, text.size]
|
46
|
+
new_pieces << [which, length + start, size - length] if size - length > 0
|
47
|
+
|
48
|
+
self.last_piece_index = index + 1
|
49
|
+
self.pieces[index..index] = new_pieces
|
50
|
+
self.buffer_add += text
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete(offset, count)
|
55
|
+
piece_at_buffer_offset(offset) do |(piece_left, index_left, remainder_left)|
|
56
|
+
piece_at_buffer_offset(offset + count) do |(piece_right, index_right, remainder_right)|
|
57
|
+
if index_left == index_right
|
58
|
+
if remainder_left == piece_left[1]
|
59
|
+
pieces[index_left] = [piece_left[0], piece_left[1] + count, piece_left[2] - count]
|
60
|
+
|
61
|
+
return
|
62
|
+
elsif remainder_right == piece_left[1] + piece_left[2]
|
63
|
+
pieces[index_left] = [piece_left[0], piece_left[1], piece_left[2] - count]
|
64
|
+
|
65
|
+
return
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
new_pieces = []
|
70
|
+
left = [piece_left[0], piece_left[1], remainder_left - piece_left[1]]
|
71
|
+
left_condition = (remainder_left - piece_left[1] > 0)
|
72
|
+
right = [piece_right[0], remainder_right, piece_right[2] - (remainder_right - piece_right[1])]
|
73
|
+
right_condition = (piece_right[2] - (remainder_right - piece_right[1]) > 0)
|
74
|
+
|
75
|
+
if !left_condition && !right_condition
|
76
|
+
new_pieces << left
|
77
|
+
end
|
78
|
+
|
79
|
+
if left_condition
|
80
|
+
new_pieces << left
|
81
|
+
end
|
82
|
+
|
83
|
+
if right_condition
|
84
|
+
new_pieces << right
|
85
|
+
end
|
86
|
+
|
87
|
+
self.pieces[index_left..index_right] = new_pieces
|
88
|
+
self.last_piece_index = nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private def piece_at_buffer_offset(offset)
|
94
|
+
raise Hokusai::Error.new("Piece table offset is negative") if offset.negative?
|
95
|
+
|
96
|
+
remainder = offset
|
97
|
+
|
98
|
+
pieces.each_with_index do |piece, index|
|
99
|
+
if remainder <= piece[2]
|
100
|
+
yield([piece, index, remainder + piece[1]])
|
101
|
+
|
102
|
+
return
|
103
|
+
end
|
104
|
+
|
105
|
+
remainder -= piece[2]
|
106
|
+
end
|
107
|
+
|
108
|
+
raise Hokusai::Error.new("Piece table offset is greater than the buffer! #{offset}\n#{pieces}")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module Hokusai::Util
|
2
|
+
class Selection
|
3
|
+
attr_reader :raw
|
4
|
+
attr_accessor :started
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
ptr = FFI::MemoryPointer.new :pointer
|
8
|
+
LibHokusai.hoku_selection_init(ptr)
|
9
|
+
@raw = LibHokusai::HokuSelection.new(ptr.get_pointer(0))
|
10
|
+
ptr.free
|
11
|
+
@started = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def type
|
15
|
+
raw[:type]
|
16
|
+
end
|
17
|
+
|
18
|
+
def none?
|
19
|
+
type == :none
|
20
|
+
end
|
21
|
+
|
22
|
+
def ready?
|
23
|
+
type == :none || type == :frozen
|
24
|
+
end
|
25
|
+
|
26
|
+
def clear
|
27
|
+
raw[:start_x] = 0.0
|
28
|
+
raw[:stop_x] = 0.0
|
29
|
+
raw[:start_y] = 0.0
|
30
|
+
raw[:stop_y] = 0.0
|
31
|
+
raw[:cursor] = nil
|
32
|
+
|
33
|
+
activate!
|
34
|
+
end
|
35
|
+
|
36
|
+
def active?
|
37
|
+
type == :active
|
38
|
+
end
|
39
|
+
|
40
|
+
def frozen?
|
41
|
+
type == :frozen
|
42
|
+
end
|
43
|
+
|
44
|
+
def activate!
|
45
|
+
raw[:type] = :active
|
46
|
+
end
|
47
|
+
|
48
|
+
def freeze!
|
49
|
+
raw[:type] = :frozen
|
50
|
+
end
|
51
|
+
|
52
|
+
def coords
|
53
|
+
[start_x, stop_x, start_y, stop_y]
|
54
|
+
end
|
55
|
+
|
56
|
+
def offset_y=(val)
|
57
|
+
raw[:offset_y] = val
|
58
|
+
end
|
59
|
+
|
60
|
+
def offset_y
|
61
|
+
raw[:offset_y]
|
62
|
+
end
|
63
|
+
|
64
|
+
def start(x, y)
|
65
|
+
raw[:start_x] = x
|
66
|
+
raw[:start_y] = y
|
67
|
+
raw[:stop_x] = x
|
68
|
+
raw[:stop_y] = y
|
69
|
+
|
70
|
+
raw[:cursor] = nil
|
71
|
+
|
72
|
+
activate!
|
73
|
+
end
|
74
|
+
|
75
|
+
def stop(x, y)
|
76
|
+
raw[:stop_x] = x
|
77
|
+
raw[:stop_y] = y
|
78
|
+
end
|
79
|
+
|
80
|
+
def start_x
|
81
|
+
raw[:start_x]
|
82
|
+
end
|
83
|
+
|
84
|
+
def stop_x
|
85
|
+
raw[:stop_x]
|
86
|
+
end
|
87
|
+
|
88
|
+
def stop_y
|
89
|
+
raw[:stop_y]
|
90
|
+
end
|
91
|
+
|
92
|
+
def start_y
|
93
|
+
raw[:start_y]
|
94
|
+
end
|
95
|
+
|
96
|
+
def up?
|
97
|
+
stop_y < start_y
|
98
|
+
end
|
99
|
+
|
100
|
+
def down?
|
101
|
+
start_y <= stop_y
|
102
|
+
end
|
103
|
+
|
104
|
+
def left?
|
105
|
+
stop_x < start_x
|
106
|
+
end
|
107
|
+
|
108
|
+
def right?
|
109
|
+
start_x <= stop_x
|
110
|
+
end
|
111
|
+
|
112
|
+
def cursor=(position)
|
113
|
+
if position.nil?
|
114
|
+
LibHokusai.hoku_selection_cursor_free(raw)
|
115
|
+
return
|
116
|
+
end
|
117
|
+
|
118
|
+
pos = LibHokusai::HokuCursorPosition.create(position)
|
119
|
+
|
120
|
+
ret = LibHokusai.hoku_selection_cursor_set(raw, pos)
|
121
|
+
|
122
|
+
raise Hokusai::Error.new("Could not set cursor") if !ret.zero?
|
123
|
+
end
|
124
|
+
|
125
|
+
def cursor
|
126
|
+
return nil if raw[:cursor].null?
|
127
|
+
|
128
|
+
if frozen?
|
129
|
+
return [raw[:cursor][:x], raw[:cursor][:y] - offset_y, raw[:cursor][:w], raw[:cursor][:h]]
|
130
|
+
end
|
131
|
+
|
132
|
+
[raw[:cursor][:x], raw[:cursor][:y], raw[:cursor][:w], raw[:cursor][:h]]
|
133
|
+
end
|
134
|
+
|
135
|
+
def rect_selected(rect)
|
136
|
+
selected(rect[0], rect[1], rect[2], rect[3])
|
137
|
+
end
|
138
|
+
|
139
|
+
def selected(x, y, width, height)
|
140
|
+
return false if none?
|
141
|
+
|
142
|
+
LibHokusai.hoku_selection_selected(raw, x, y, width, height)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/ui/src/hokusai.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative '../lib/lib_hokusai'
|
2
|
+
require_relative './hokusai/error'
|
3
|
+
require_relative './hokusai/types'
|
4
|
+
require_relative './hokusai/ast'
|
5
|
+
require_relative './hokusai/style'
|
6
|
+
require_relative './hokusai/node'
|
7
|
+
require_relative './hokusai/block'
|
8
|
+
require_relative './hokusai/commands'
|
9
|
+
require_relative './hokusai/font'
|
10
|
+
require_relative './hokusai/event'
|
11
|
+
require_relative './hokusai/painter'
|
12
|
+
require_relative './hokusai/util/selection'
|
13
|
+
require_relative './hokusai/util/piece_table'
|
14
|
+
require_relative './hokusai/blocks/empty'
|
15
|
+
require_relative './hokusai/blocks/vblock'
|
16
|
+
require_relative './hokusai/blocks/hblock'
|
17
|
+
require_relative './hokusai/blocks/label'
|
18
|
+
require_relative './hokusai/blocks/rect'
|
19
|
+
require_relative './hokusai/blocks/button'
|
20
|
+
require_relative './hokusai/blocks/circle'
|
21
|
+
require_relative './hokusai/blocks/checkbox'
|
22
|
+
require_relative './hokusai/blocks/scissor_begin'
|
23
|
+
require_relative './hokusai/blocks/scissor_end'
|
24
|
+
require_relative './hokusai/blocks/clipped'
|
25
|
+
require_relative './hokusai/blocks/cursor'
|
26
|
+
require_relative './hokusai/blocks/image'
|
27
|
+
require_relative './hokusai/blocks/svg'
|
28
|
+
require_relative './hokusai/blocks/toggle'
|
29
|
+
require_relative './hokusai/blocks/scrollbar'
|
30
|
+
require_relative './hokusai/blocks/dynamic'
|
31
|
+
require_relative './hokusai/blocks/panel'
|
32
|
+
require_relative './hokusai/blocks/text'
|
33
|
+
require_relative './hokusai/blocks/selectable'
|
34
|
+
require_relative './hokusai/blocks/input'
|
35
|
+
require_relative './hokusai/blocks/titlebar/osx'
|
36
|
+
|
37
|
+
require "concurrent"
|
38
|
+
|
39
|
+
module Hokusai
|
40
|
+
ThreadPool = Concurrent::ThreadPoolExecutor.new(
|
41
|
+
min_threads: 5,
|
42
|
+
max_threads: 5,
|
43
|
+
max_queue: 20,
|
44
|
+
fallback_policy: :caller_runs
|
45
|
+
)
|
46
|
+
|
47
|
+
def self.fonts
|
48
|
+
@fonts ||= FontRegistry.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.close_window
|
52
|
+
@on_close_window&.call
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.on_close_window(&block)
|
56
|
+
@on_close_window = block
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.on_restore_window(&block)
|
60
|
+
@on_restore_window = block
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.restore_window
|
64
|
+
@on_restore_window&.call
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.minimize_window
|
68
|
+
@on_minimize_window&.call
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.on_minimize_window(&block)
|
72
|
+
@on_minimize_window = block
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.maximize_window
|
76
|
+
@on_maximize_window&.call
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.on_maximize_window(&block)
|
80
|
+
@on_maximize_window = block
|
81
|
+
end
|
82
|
+
|
83
|
+
# Sets the window position on the screen
|
84
|
+
#
|
85
|
+
# NOTE the implementation is backend specific
|
86
|
+
def self.set_window_position(mouse)
|
87
|
+
@on_set_window_position&.call(mouse)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.on_set_window_position(&block)
|
91
|
+
@on_set_window_position = block
|
92
|
+
end
|
93
|
+
|
94
|
+
# Sets the mouse position on the screen
|
95
|
+
#
|
96
|
+
# NOTE the implementation is backend specific
|
97
|
+
def self.on_set_mouse_position(&block)
|
98
|
+
@on_set_mouse_position = block
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.set_mouse_position(mouse)
|
102
|
+
@on_set_mouse_position&.call(mouse)
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.on_renderable(&block)
|
106
|
+
@on_renderable = block
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.can_render(canvas)
|
110
|
+
@on_renderable&.call(canvas)
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.on_set_mouse_cursor(&block)
|
114
|
+
@on_set_mouse_cursor = block
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.set_mouse_cursor(type)
|
118
|
+
@on_set_mouse_cursor&.call(type)
|
119
|
+
end
|
120
|
+
end
|
data/ui/vendor/.gitkeep
ADDED
File without changes
|
data/vendor/.gitkeep
ADDED
File without changes
|