hokusai-zero 0.1.4 → 0.1.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.
@@ -13,7 +13,7 @@ module Hokusai
13
13
  @primary_stack = []
14
14
 
15
15
  node.ast.children.each_with_index do |child, index|
16
- primary_stack << Mounting::MountEntry.new(index, child, root, root, previous_target || root)
16
+ primary_stack << Mounting::MountEntry.new(index, child, root, root, previous_target || root, providers: root.providers)
17
17
  end
18
18
  end
19
19
 
@@ -78,7 +78,7 @@ module Hokusai
78
78
 
79
79
  entry.ast.children.each_with_index do |child, child_index|
80
80
  child.has_if_condition?
81
- items << Mounting::MountEntry.new(child_index, child, child_block, entry.parent, entry.target, context: entry.ctx)
81
+ items << Mounting::MountEntry.new(child_index, child, child_block, entry.parent, entry.target, context: entry.ctx, providers: entry.providers.merge(child_block.providers))
82
82
  end
83
83
 
84
84
  secondary_stack.unshift items
@@ -88,7 +88,7 @@ module Hokusai
88
88
  primary_items = []
89
89
 
90
90
  child_block.node.ast.children.each_with_index do |child, child_index|
91
- primary_items << Mounting::MountEntry.new(child_index, child, child_block, child_block, context: entry.ctx)
91
+ primary_items << Mounting::MountEntry.new(child_index, child, child_block, child_block, context: entry.ctx, providers: entry.providers.merge(child_block.providers))
92
92
  end
93
93
 
94
94
  self.primary_stack = primary_items + primary_stack
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "./event"
4
+ require "colorize"
4
5
 
5
6
  module Hokusai
6
7
  class PainterEntry
@@ -22,6 +23,9 @@ module Hokusai
22
23
  end
23
24
  end
24
25
 
26
+ ZTARGET_ROOT = "root"
27
+ ZTARGET_PARENT = "parent"
28
+
25
29
  class Painter
26
30
  attr_reader :root, :input, :before_render, :after_render,
27
31
  :events
@@ -52,17 +56,36 @@ module Hokusai
52
56
  @after_render = block
53
57
  end
54
58
 
59
+ # def debug(parent, children)
60
+ # @i ||= 0
61
+
62
+ # pp [
63
+ # "#{@i}",
64
+ # "parent: #{parent.block.class}##{parent.block.node.portal&.ast&.id} (z: #{parent.block.node.meta.get_prop(:z)})",
65
+ # "children: #{children.map {|c| "#{c.block.class}##{c.block.node.portal&.ast&.id} (z: #{c.block.node.meta.get_prop(:z)})"} }"
66
+ # ]
67
+ # @i += 1
68
+ # end
69
+
55
70
  # @return [Array(Commands::Base)] the command list
56
71
  def render(canvas, resize = false, capture: true)
57
72
  return if root.children.empty?
58
73
 
74
+ zindexed = {}
75
+ zindex_counter = 0
76
+ zroot_x = canvas.x
77
+ zroot_y = canvas.y
78
+ zroot_w = canvas.width
79
+ zroot_h = canvas.height
80
+
59
81
  @root.on_resize(canvas) if resize
60
82
 
61
83
  before_render&.call([root, nil], canvas, input)
62
84
 
63
85
  root_children = (canvas.reverse? ? root.children?&.reverse.dup : root.children?&.dup) || []
64
86
  groups = []
65
- groups << [root, measure(root_children, canvas)]
87
+ root_entry = PainterEntry.new(root, canvas.x, canvas.y, canvas.width, canvas.height)
88
+ groups << [root_entry, measure(root_children, canvas)]
66
89
 
67
90
  mouse_y = input.mouse.pos[:y]
68
91
  can_capture = mouse_y >= (canvas.y || 0.0) && mouse_y <= (canvas.y || 0.0) + canvas.height
@@ -71,9 +94,25 @@ module Hokusai
71
94
 
72
95
  while payload = groups.pop
73
96
  group_parent, group_children = payload
97
+
98
+ parent_z = group_parent.block.node.meta.get_prop(:z)&.to_i
99
+ zindex_counter -= 1 if (parent_z || 0) > 0 && group_children.empty?
74
100
 
75
101
  while group = group_children.shift
76
- canvas.reset(group.x, group.y, group.w, group.h)
102
+ z = group.block.node.meta.get_prop(:z)&.to_i || 0
103
+ ztarget = group.block.node.meta.get_prop(:ztarget)
104
+ entry = PainterEntry.new(group.block, group.x, group.y, group.w, group.h)
105
+
106
+ if (zindex_counter > 0 || z > 0)
107
+ case ztarget
108
+ when ZTARGET_ROOT
109
+ entry = PainterEntry.new(group.block, zroot_x || 0.0, zroot_y || 0.0, zroot_w, zroot_h).freeze
110
+ when ZTARGET_PARENT
111
+ entry = PainterEntry.new(group.block, group_parent.x || 0.0, group_parent.y || 0.0, group_parent.w, group_parent.h).freeze
112
+ end
113
+ end
114
+
115
+ canvas.reset(entry.x, entry.y, entry.w, entry.h)
77
116
 
78
117
  before_render&.call([group.block, group.parent], canvas, input.raw)
79
118
 
@@ -92,17 +131,36 @@ module Hokusai
92
131
 
93
132
  unless local_children.nil?
94
133
  groups << [group_parent, group_children]
95
- groups << [group.block, measure(local_children, local_canvas)]
134
+ parent = PainterEntry.new(group.block, canvas.x, canvas.y, canvas.width, canvas.height)
135
+ groups << [parent, measure(local_children, local_canvas)]
136
+
96
137
  breaked = true
97
138
  else
98
139
  breaked = false
99
140
  end
100
141
  end
142
+
143
+ if z > 0
144
+ zindex_counter += 1
145
+ # puts ["start (#{z}) <#{parent_z}> {#{zindex_counter}} #{group.block.class}".colorize(:blue), z, group.block.node.portal&.ast&.id]
146
+ zindexed[zindex_counter] ||= []
147
+ zindexed[zindex_counter] << group.block
148
+ elsif zindex_counter > 0
149
+ # puts ["push (#{z}) <#{parent_z}> {#{zindex_counter}} initial #{group.block.class}".colorize(:red), z, group.block.node.portal&.ast&.id]
150
+ zindexed[zindex_counter] << group.block
151
+ else
152
+ # puts ["draw (#{z}) <#{parent_z}> {#{zindex_counter}} #{group.block.class}".colorize(:yellow), z, group.block.node.portal&.ast&.id]
153
+ group.block.execute_draw
154
+ end
101
155
 
102
156
  break if breaked
103
157
  end
104
158
  end
105
159
 
160
+ zindexed.sort.each do |z, blocks|
161
+ blocks.each(&:execute_draw)
162
+ end
163
+
106
164
  if capture
107
165
  events[:hover].bubble
108
166
  events[:wheel].bubble
@@ -132,10 +190,12 @@ module Hokusai
132
190
  hsum = 0.0
133
191
 
134
192
  children.each do |block|
135
- # children.each do |block|
193
+ z = block.node.meta.get_prop?(:z)&.to_i || 0
136
194
  h = block.node.meta.get_prop?(:height)&.to_f
137
195
  w = block.node.meta.get_prop?(:width)&.to_f
138
196
 
197
+ next if z > 0
198
+
139
199
  if w
140
200
  wsum += w
141
201
  wcount = wcount.succ
@@ -195,12 +255,11 @@ module Hokusai
195
255
  events[:hover].capture(block, canvas)
196
256
  events[:click].capture(block, canvas)
197
257
  events[:wheel].capture(block, canvas)
198
- events[:mousedown].capture(block, canvas)
199
258
  events[:mouseup].capture(block, canvas)
259
+ events[:mousedown].capture(block, canvas)
200
260
  else
201
261
  events[:mouseout].capture(block, canvas)
202
262
  end
203
-
204
263
  events[:mousemove].capture(block, canvas)
205
264
 
206
265
  if block_is_hovered || block.node.meta.focused
@@ -15,11 +15,11 @@ module Hokusai::Util
15
15
  end
16
16
 
17
17
  def draw(font_size, boundary, selection: nil)
18
- # selection_extract(font_size, boundary, selection: selection)
18
+ selection_extract(font_size, boundary, selection: selection)
19
19
  draw_text(font_size, boundary)
20
- # selection_update(selection)
21
- # self.start_select = 0.0
22
- # self.stop_select = nil
20
+ selection_update(selection)
21
+ self.start_select = 0.0
22
+ self.stop_select = nil
23
23
  end
24
24
 
25
25
  def selection_extract(font_size, boundary, selection: nil)
@@ -165,6 +165,8 @@ module Hokusai::Util
165
165
  if start = start_select
166
166
  on_selection_change_cb&.call(start, stop_select)
167
167
  end
168
+
169
+ nil
168
170
  end
169
171
  ensure
170
172
  @i += 1
data/ui/src/hokusai.rb CHANGED
@@ -1,3 +1,5 @@
1
+ ASSETS_FOLDER = "#{__dir__}/hokusai/assets"
2
+
1
3
  require_relative '../lib/lib_hokusai'
2
4
  require_relative './hokusai/error'
3
5
  require_relative './hokusai/types'
@@ -34,6 +36,8 @@ require_relative './hokusai/blocks/selectable'
34
36
  require_relative './hokusai/blocks/input'
35
37
  require_relative './hokusai/blocks/variable'
36
38
  require_relative './hokusai/blocks/titlebar/osx'
39
+ require_relative './hokusai/blocks/modal'
40
+ require_relative './hokusai/blocks/dropdown'
37
41
 
38
42
  require "concurrent"
39
43
 
@@ -48,6 +52,19 @@ module Hokusai
48
52
  fallback_policy: :caller_runs
49
53
  )
50
54
 
55
+ SHADER_UNIFORM_FLOAT = 0 # Shader uniform type: float
56
+ SHADER_UNIFORM_VEC2 = 1 # Shader uniform type: vec2 (2 float)
57
+ SHADER_UNIFORM_VEC3 = 2 # Shader uniform type: vec3 (3 float)
58
+ SHADER_UNIFORM_VEC4 = 3 # Shader uniform type: vec4 (4 float)
59
+ SHADER_UNIFORM_INT = 4 # Shader uniform type: int
60
+ SHADER_UNIFORM_IVEC2 = 5 # Shader uniform type: ivec2 (2 int)
61
+ SHADER_UNIFORM_IVEC3 = 6 # Shader uniform type: ivec3 (3 int)
62
+ SHADER_UNIFORM_IVEC4 = 7 # Shader uniform type: ivec4 (4 int)
63
+ SHADER_UNIFORM_UINT = 8 # Shader uniform type: unsigned int
64
+ SHADER_UNIFORM_UIVEC2 = 9 # Shader uniform type: uivec2 (2 unsigned int)
65
+ SHADER_UNIFORM_UIVEC3 = 10 # Shader uniform type: uivec3 (3 unsigned int)
66
+ SHADER_UNIFORM_UIVEC4 = 11 # Shader uniform type: uivec4 (4 unsigned int)
67
+
51
68
  # Access the font registry
52
69
  #
53
70
  # @return [Hokusai::FontRegistry]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hokusai-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - skinnyjames
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-11 00:00:00.000000000 Z
11
+ date: 2025-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: concurrent-ruby
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +206,9 @@ files:
192
206
  - ui/spec/hokusai_spec.rb
193
207
  - ui/spec/spec_helper.rb
194
208
  - ui/src/hokusai.rb
209
+ - ui/src/hokusai/assets/arrow-drop-down-line.png
210
+ - ui/src/hokusai/assets/chevron-down.svg
211
+ - ui/src/hokusai/assets/close-large-line.png
195
212
  - ui/src/hokusai/ast.rb
196
213
  - ui/src/hokusai/automation.rb
197
214
  - ui/src/hokusai/automation/client.rb
@@ -224,12 +241,14 @@ files:
224
241
  - ui/src/hokusai/blocks/circle.rb
225
242
  - ui/src/hokusai/blocks/clipped.rb
226
243
  - ui/src/hokusai/blocks/cursor.rb
244
+ - ui/src/hokusai/blocks/dropdown.rb
227
245
  - ui/src/hokusai/blocks/dynamic.rb
228
246
  - ui/src/hokusai/blocks/empty.rb
229
247
  - ui/src/hokusai/blocks/hblock.rb
230
248
  - ui/src/hokusai/blocks/image.rb
231
249
  - ui/src/hokusai/blocks/input.rb
232
250
  - ui/src/hokusai/blocks/label.rb
251
+ - ui/src/hokusai/blocks/modal.rb
233
252
  - ui/src/hokusai/blocks/panel.rb
234
253
  - ui/src/hokusai/blocks/rect.rb
235
254
  - ui/src/hokusai/blocks/scissor_begin.rb