hokusai-zero 0.2.6 → 0.2.8

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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/Gemfile.lock +0 -2
  4. data/README.md +1 -1
  5. data/ast/src/core/ast.c +3 -11
  6. data/ast/src/core/hml.c +214 -40
  7. data/ast/src/core/hml.h +1 -0
  8. data/ast/src/core/input.h +0 -1
  9. data/ast/src/core/log.c +87 -0
  10. data/ast/src/core/log.h +41 -0
  11. data/ast/src/core/util.c +23 -23
  12. data/ast/src/core/util.h +7 -7
  13. data/ast/test/parser.c +1 -0
  14. data/ext/extconf.rb +6 -6
  15. data/hokusai.gemspec +1 -2
  16. data/ui/examples/drag.rb +154 -0
  17. data/ui/examples/embedded.rb +58 -0
  18. data/ui/examples/forum/file.rb +1 -1
  19. data/ui/examples/forum/post.rb +0 -1
  20. data/ui/examples/forum.rb +7 -7
  21. data/ui/examples/game.rb +143 -0
  22. data/ui/examples/keyboard.rb +47 -0
  23. data/ui/examples/overlay.rb +233 -0
  24. data/ui/examples/provider.rb +56 -0
  25. data/ui/examples/shader/test.rb +155 -0
  26. data/ui/examples/shader.rb +100 -0
  27. data/ui/examples/spreadsheet.rb +12 -11
  28. data/ui/examples/wiki.rb +82 -0
  29. data/ui/lib/lib_hokusai.rb +43 -24
  30. data/ui/spec/hokusai/e2e/client_spec.rb +0 -1
  31. data/ui/spec/hokusai/e2e/keyboard_spec.rb +52 -0
  32. data/ui/spec/spec_helper.rb +1 -1
  33. data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
  34. data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
  35. data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +19 -0
  36. data/ui/src/hokusai/assets/icons/outline/backspace.svg +20 -0
  37. data/ui/src/hokusai/automation/driver_commands/base.rb +2 -8
  38. data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +3 -6
  39. data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +12 -5
  40. data/ui/src/hokusai/automation/server.rb +2 -3
  41. data/ui/src/hokusai/backends/raylib/config.rb +2 -1
  42. data/ui/src/hokusai/backends/raylib/font.rb +55 -4
  43. data/ui/src/hokusai/backends/raylib.rb +199 -36
  44. data/ui/src/hokusai/backends/sdl2/config.rb +9 -6
  45. data/ui/src/hokusai/backends/sdl2/font.rb +3 -1
  46. data/ui/src/hokusai/backends/sdl2.rb +188 -93
  47. data/ui/src/hokusai/blocks/color_picker.rb +1080 -0
  48. data/ui/src/hokusai/blocks/dynamic.rb +2 -0
  49. data/ui/src/hokusai/blocks/input.rb +2 -2
  50. data/ui/src/hokusai/blocks/keyboard.rb +249 -0
  51. data/ui/src/hokusai/blocks/panel.rb +2 -0
  52. data/ui/src/hokusai/blocks/scrollbar.rb +7 -0
  53. data/ui/src/hokusai/blocks/selectable.rb +1 -0
  54. data/ui/src/hokusai/blocks/shader_begin.rb +22 -0
  55. data/ui/src/hokusai/blocks/shader_end.rb +12 -0
  56. data/ui/src/hokusai/blocks/slider.rb +139 -0
  57. data/ui/src/hokusai/blocks/text_stream.rb +130 -0
  58. data/ui/src/hokusai/blocks/texture.rb +23 -0
  59. data/ui/src/hokusai/blocks/translation.rb +91 -0
  60. data/ui/src/hokusai/commands/rect.rb +12 -3
  61. data/ui/src/hokusai/commands/rotation.rb +21 -0
  62. data/ui/src/hokusai/commands/scale.rb +20 -0
  63. data/ui/src/hokusai/commands/shader.rb +33 -0
  64. data/ui/src/hokusai/commands/texture.rb +26 -0
  65. data/ui/src/hokusai/commands/translation.rb +20 -0
  66. data/ui/src/hokusai/commands.rb +49 -3
  67. data/ui/src/hokusai/event.rb +2 -1
  68. data/ui/src/hokusai/events/keyboard.rb +11 -18
  69. data/ui/src/hokusai/events/mouse.rb +10 -8
  70. data/ui/src/hokusai/events/touch.rb +62 -0
  71. data/ui/src/hokusai/meta.rb +13 -6
  72. data/ui/src/hokusai/mounting/loop_entry.rb +4 -4
  73. data/ui/src/hokusai/mounting/update_entry.rb +5 -6
  74. data/ui/src/hokusai/painter.rb +31 -8
  75. data/ui/src/hokusai/types/display.rb +155 -0
  76. data/ui/src/hokusai/types/keyboard.rb +168 -0
  77. data/ui/src/hokusai/types/mouse.rb +36 -0
  78. data/ui/src/hokusai/types/primitives.rb +56 -0
  79. data/ui/src/hokusai/types/touch.rb +181 -0
  80. data/ui/src/hokusai/types.rb +20 -244
  81. data/ui/src/hokusai/util/selection.rb +28 -7
  82. data/ui/src/hokusai/util/wrap_stream.rb +268 -0
  83. data/ui/src/hokusai.rb +72 -35
  84. data/xmake.lua +2 -1
  85. metadata +39 -22
  86. data/ui/src/hokusai/assets/chevron-down.svg +0 -1
@@ -0,0 +1,41 @@
1
+ #ifndef FLASHLIGHT_LOG_H
2
+ #define FLASHLIGHT_LOG_H
3
+ #include <time.h>
4
+ #include <stdio.h>
5
+ #include <stdarg.h>
6
+
7
+ #define ANSI_COLOR_YELLOW "\x1b[33m"
8
+ #define ANSI_COLOR_BLUE "\x1b[34m"
9
+ #define ANSI_COLOR_MAGENTA "\x1b[35m"
10
+ #define ANSI_COLOR_CYAN "\x1b[36m"
11
+ #define ANSI_COLOR_RESET "\x1b[0m"
12
+
13
+ enum F_LOG_LEVEL
14
+ {
15
+ F_LOG_ERROR = 1 << 0,
16
+ F_LOG_WARN = 1 << 1,
17
+ F_LOG_INFO = 1 << 2,
18
+ F_LOG_DEBUG = 1 << 3,
19
+ F_LOG_FINE = 1 << 4
20
+ };
21
+
22
+ typedef struct FLogMessage
23
+ {
24
+ char* datetime;
25
+ enum F_LOG_LEVEL level;
26
+ char* message;
27
+ } f_log_message;
28
+
29
+ typedef void (*f_logger_cb)(f_log_message message, volatile void* payload);
30
+ static volatile f_logger_cb f_log_cb = NULL;
31
+ static volatile enum F_LOG_LEVEL f_log_level = F_LOG_ERROR;
32
+ static volatile void* f_log_payload = NULL;
33
+
34
+ void f_logger_set_level(enum F_LOG_LEVEL level);
35
+ void f_logger_set_cb(f_logger_cb cb, volatile void* payload);
36
+ f_logger_cb f_logger_get_cb();
37
+ enum F_LOG_LEVEL f_logger_get_level();
38
+ volatile void* f_logger_get_payload();
39
+ void f_log(enum F_LOG_LEVEL level, char* fmt, ...);
40
+
41
+ #endif
data/ast/src/core/util.c CHANGED
@@ -3,33 +3,33 @@
3
3
 
4
4
  #include "util.h"
5
5
 
6
- bool hoku_rect_includes_y(hoku_rect rect, float y)
6
+ bool hoku_rect_includes_y(hoku_rect* rect, float y)
7
7
  {
8
- return y > rect.y && y <= (rect.y + rect.h);
8
+ return y > rect->y && y <= (rect->y + rect->h);
9
9
  }
10
10
 
11
- bool hoku_rect_includes_x(hoku_rect rect, float x)
11
+ bool hoku_rect_includes_x(hoku_rect* rect, float x)
12
12
  {
13
- return x > rect.x && x <= (rect.x + rect.w);
13
+ return x > rect->x && x <= (rect->x + rect->w);
14
14
  }
15
15
 
16
- float hoku_rect_x_left(hoku_rect rect, int times)
16
+ float hoku_rect_x_left(hoku_rect* rect, int times)
17
17
  {
18
- return (rect.x - ((rect.w / 2) * times));
18
+ return (rect->x - ((rect->w / 2) * times));
19
19
  }
20
- float hoku_rect_x_right(hoku_rect rect, int times)
20
+ float hoku_rect_x_right(hoku_rect* rect, int times)
21
21
  {
22
- return (rect.x + ((rect.w / 2) * times));
22
+ return (rect->x + ((rect->w / 2) * times));
23
23
  }
24
24
 
25
- float hoku_rect_y_up(hoku_rect rect, int times)
25
+ float hoku_rect_y_up(hoku_rect* rect, int times)
26
26
  {
27
- return (rect.y - ((rect.h / 2) * times));
27
+ return (rect->y - ((rect->h / 2) * times));
28
28
  }
29
29
 
30
- float hoku_rect_y_down(hoku_rect rect, int times)
30
+ float hoku_rect_y_down(hoku_rect* rect, int times)
31
31
  {
32
- return (rect.y + ((rect.h / 2) * times));
32
+ return (rect->y + ((rect->h / 2) * times));
33
33
  }
34
34
 
35
35
  int hoku_selection_init(hoku_selection** selection)
@@ -68,28 +68,28 @@ bool hoku_selection_selected(hoku_selection* selection, float x, float y, float
68
68
  bool right = selection->start_x <= selection->stop_x;
69
69
 
70
70
  hoku_rect hit_box = (hoku_rect){.x=x, .y=y, .w=width, .h=height};
71
- float x_shifted_right = hoku_rect_x_right(hit_box, 1);
72
- float y_shifted_up = hoku_rect_y_up(hit_box, 2);
73
- float y_shifted_down = hoku_rect_y_down(hit_box, 2);
71
+ float x_shifted_right = hoku_rect_x_right(&hit_box, 1);
72
+ float y_shifted_up = hoku_rect_y_up(&hit_box, 2);
73
+ float y_shifted_down = hoku_rect_y_down(&hit_box, 2);
74
74
  float end_y = y + height;
75
75
 
76
76
  return (
77
77
  (down &&
78
78
  // first line of multiline selection
79
- ((x_shifted_right > sx && end_y < ey && hoku_rect_includes_y(hit_box, sy)) ||
79
+ ((x_shifted_right > sx && end_y < ey && hoku_rect_includes_y(&hit_box, sy)) ||
80
80
  // last line of multiline selection
81
81
  (x_shifted_right <= ex && y_shifted_up + hit_box.h < ey && hit_box.y > sy) ||
82
82
  // middle line (all selected)
83
83
  (hit_box.y > sy && end_y < ey))) ||
84
84
  (up &&
85
85
  // first line of multiline selection
86
- ((x_shifted_right <= sx && hit_box.y > ey && hoku_rect_includes_y(hit_box, sy)) ||
86
+ ((x_shifted_right <= sx && hit_box.y > ey && hoku_rect_includes_y(&hit_box, sy)) ||
87
87
  // last line of multiline selection
88
88
  (x_shifted_right >= ex && y_shifted_down > ey && end_y < sy) ||
89
89
  // middle line (all selected)
90
90
  (hit_box.y > ey && hit_box.y + hit_box.h < sy))) ||
91
91
  // single line selection
92
- ((hoku_rect_includes_y(hit_box, sy) && hoku_rect_includes_y(hit_box, ey)) &&
92
+ ((hoku_rect_includes_y(&hit_box, sy) && hoku_rect_includes_y(&hit_box, ey)) &&
93
93
  ((left && x_shifted_right < sx && x_shifted_right > ex) || (right && x_shifted_right > sx && x_shifted_right < ex)))
94
94
  );
95
95
  }
@@ -108,7 +108,7 @@ hoku_cursor_position hoku_selection_cursor_get(hoku_selection* selection)
108
108
  return pos;
109
109
  }
110
110
 
111
- int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position cursor)
111
+ int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position* cursor)
112
112
  {
113
113
  if (selection->cursor == NULL)
114
114
  {
@@ -117,10 +117,10 @@ int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position cu
117
117
  if (selection->cursor == NULL) return -1;
118
118
  }
119
119
 
120
- selection->cursor->x = cursor.x;
121
- selection->cursor->y = cursor.y;
122
- selection->cursor->w = cursor.w;
123
- selection->cursor->h = cursor.h;
120
+ selection->cursor->x = cursor->x;
121
+ selection->cursor->y = cursor->y;
122
+ selection->cursor->w = cursor->w;
123
+ selection->cursor->h = cursor->h;
124
124
 
125
125
  return 0;
126
126
  }
data/ast/src/core/util.h CHANGED
@@ -30,16 +30,16 @@ typedef struct HokuSelection
30
30
  hoku_cursor_position* cursor;
31
31
  } hoku_selection;
32
32
 
33
- bool hoku_rect_includes_y(hoku_rect rect, float y);
34
- bool hoku_rect_includes_x(hoku_rect rect, float x);
35
- float hoku_rect_x_left(hoku_rect rect, int times);
36
- float hoku_rect_x_right(hoku_rect rect, int times);
37
- float hoku_rect_y_up(hoku_rect rect, int times);
38
- float hoku_rect_y_down(hoku_rect rect, int times);
33
+ bool hoku_rect_includes_y(hoku_rect* rect, float y);
34
+ bool hoku_rect_includes_x(hoku_rect* rect, float x);
35
+ float hoku_rect_x_left(hoku_rect* rect, int times);
36
+ float hoku_rect_x_right(hoku_rect* rect, int times);
37
+ float hoku_rect_y_up(hoku_rect* rect, int times);
38
+ float hoku_rect_y_down(hoku_rect* rect, int times);
39
39
 
40
40
  int hoku_selection_init(hoku_selection** selection);
41
41
  bool hoku_selection_selected(hoku_selection* selection, float x, float y, float width, float height);
42
- int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position cursor);
42
+ int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position* cursor);
43
43
  void hoku_selection_cursor_free(hoku_selection* selection);
44
44
  void hoku_selection_free(hoku_selection* selection);
45
45
 
data/ast/test/parser.c CHANGED
@@ -1,3 +1,4 @@
1
+ #include "../src/core/log.c"
1
2
  #include "../src/core/ast.c"
2
3
  #include "../src/core/style.c"
3
4
  #include "../src/core/hml.c"
data/ext/extconf.rb CHANGED
@@ -9,7 +9,7 @@ if MiniPortile.darwin?
9
9
  elsif MiniPortile.linux?
10
10
  suffix = "so"
11
11
  ext = "tar.gz"
12
- md4cext = "so"
12
+ md4cext = "a"
13
13
  MDFLAGS = "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
14
14
  elsif MiniPortile.windows?
15
15
  suffix = "dll"
@@ -45,7 +45,7 @@ md4c = MiniPortileCMake.new("md4c", "0.5.2")
45
45
  md4c.files = ["https://github.com/mity/md4c/archive/refs/tags/release-0.5.2.#{ext}"]
46
46
 
47
47
  def md4c.cmake_compile_flags
48
- [*super, "-DBUILD_SHARED_LIBS=OFF #{MDFLAGS}"]
48
+ [*super, "-DBUILD_SHARED_LIBS=OFF", "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"]
49
49
  end
50
50
 
51
51
  md4c.cook
@@ -54,10 +54,10 @@ md4c.activate
54
54
  pre = "#{__dir__}/.."
55
55
  cwd = "#{__dir__}"
56
56
 
57
- files = %w[ast/src/core/hml.c ast/src/core/ast.c ast/rc/core/style.c ast/src/core/input.c ast/src/core/component.c ast/src/core/util.c ast/src/core/text.c grammar/src/parser.c grammar/src/scanner.c ast/include/hashmap.c]
58
- objects = %w[hml.o ast.o style.o input.o component.o util.o text.o parser.o scanner.o hashmap.o]
57
+ files = %w[ast/src/core/log.c ast/src/core/hml.c ast/src/core/ast.c ast/rc/core/style.c ast/src/core/input.c ast/src/core/component.c ast/src/core/util.c ast/src/core/text.c grammar/src/parser.c grammar/src/scanner.c ast/include/hashmap.c]
58
+ objects = %w[log.o hml.o ast.o style.o input.o component.o util.o text.o parser.o scanner.o hashmap.o]
59
59
  libraries = [File.expand_path("#{tree_sitter.path}/lib/libtree-sitter.a"), File.expand_path("#{md4c.path}/lib/libmd4c.#{md4cext}")]
60
- src_files = ["#{tree_sitter.path}/lib/libtree-sitter.a", "#{md4c.path}/lib/libmd4c.#{md4cext}", "#{pre}/ast/src/core/hml.c", "#{pre}/ast/src/core/ast.c", "#{pre}/ast/src/core/style.c", "#{pre}/ast/src/core/input.c", "#{pre}/ast/src/core/component.c", "#{pre}/ast/src/core/util.c", "#{pre}/ast/src/core/text.c", "#{pre}/grammar/src/parser.c", "#{pre}/grammar/src/scanner.c", "#{pre}/ast/include/hashmap.c"]
60
+ src_files = ["#{tree_sitter.path}/lib/libtree-sitter.a", "#{md4c.path}/lib/libmd4c.#{md4cext}", "#{pre}/ast/src/core/log.c", "#{pre}/ast/src/core/hml.c", "#{pre}/ast/src/core/ast.c", "#{pre}/ast/src/core/style.c", "#{pre}/ast/src/core/input.c", "#{pre}/ast/src/core/component.c", "#{pre}/ast/src/core/util.c", "#{pre}/ast/src/core/text.c", "#{pre}/grammar/src/parser.c", "#{pre}/grammar/src/scanner.c", "#{pre}/ast/include/hashmap.c"]
61
61
  if MiniPortile.windows?
62
62
  cflags = "-shared -Wall -Wl,--export-all-symbols -Wl,--enable-auto-import"
63
63
  mkdir = "mkdir #{pre}\\vendor\\lib"
@@ -89,4 +89,4 @@ File.open("Makefile", "w") do |io|
89
89
  #{"\t"}rm -f #{File.expand_path("vendor/lib/libhokusai.*")}
90
90
  #{"\t"}rm -f #{File.expand_path("vendor/lib/libmd4c.*")}
91
91
  EOF
92
- end
92
+ end
data/hokusai.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'hokusai-zero'
3
- s.version = '0.2.6'
3
+ s.version = '0.2.8'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = "A Ruby library for writing GUI applications"
6
6
  s.authors = ["skinnyjames"]
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.metadata = { "source_code_uri" => "https://codeberg.org/skinnyjames/hokusai" }
17
17
 
18
18
  s.add_dependency "ffi", "~> 1.16"
19
- s.add_dependency "concurrent-ruby", "~> 1.3.4"
20
19
  s.add_dependency "raylib-bindings", "~> 0.7.9"
21
20
  s.add_dependency "sdl2-bindings", "~> 0.2.3"
22
21
  s.add_dependency "memory_profiler"
@@ -0,0 +1,154 @@
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
@@ -0,0 +1,58 @@
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
@@ -36,7 +36,7 @@ module Demos
36
36
  )
37
37
 
38
38
  def compute_background
39
- index.odd? ? nil : Hokusai::Color.new(255, 255, 255,20)
39
+ index.odd? ? nil : Hokusai::Color.new(44, 44, 44, 20)
40
40
  end
41
41
 
42
42
  def item_image
@@ -107,7 +107,6 @@ module Demos
107
107
 
108
108
  uses(
109
109
  vblock: Hokusai::Blocks::Vblock,
110
- hblock: Hokusai::Blocks::Hblock,
111
110
  text: Hokusai::Blocks::Text,
112
111
  image: Hokusai::Blocks::Image,
113
112
  label: Hokusai::Blocks::Label,
data/ui/examples/forum.rb CHANGED
@@ -175,13 +175,13 @@ module Demos
175
175
  end
176
176
  end
177
177
 
178
- Hokusai::Backends::RaylibBackend.run(Demos::Forum::App) do |config|
178
+ Hokusai::Backends::SDLBackend.run(Demos::Forum::App) do |config|
179
179
  config.after_load do
180
- font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
180
+ font = Hokusai::Backends::SDLBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
181
181
  Hokusai.fonts.register "inter", font
182
182
  Hokusai.fonts.activate "inter"
183
183
 
184
- font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/Delius-Regular.ttf", 160)
184
+ font = Hokusai::Backends::SDLBackend::Font.from("#{__dir__}/assets/Delius-Regular.ttf")
185
185
  Hokusai.fonts.register "dohyeon", font
186
186
  end
187
187
 
@@ -190,10 +190,10 @@ Hokusai::Backends::RaylibBackend.run(Demos::Forum::App) do |config|
190
190
  config.height = 500
191
191
  config.title = "Counter application"
192
192
 
193
- # config.window_config_flags = SDL::WINDOW_RESIZABLE | SDL::WINDOW_BORDERLESS
193
+ config.window_config_flags = SDL::WINDOW_RESIZABLE #| SDL::WINDOW_BORDERLESS
194
194
 
195
- config.config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT | Raylib::FLAG_WINDOW_TRANSPARENT
196
- config.window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_WINDOW_UNDECORATED | Raylib::FLAG_WINDOW_TRANSPARENT
197
- config.background = Raylib::BLANK
195
+ # config.config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT | Raylib::FLAG_WINDOW_TRANSPARENT
196
+ # config.window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_WINDOW_UNDECORATED | Raylib::FLAG_WINDOW_TRANSPARENT
197
+ # config.background = Raylib::BLANK
198
198
  end
199
199
 
@@ -0,0 +1,143 @@
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
+
@@ -0,0 +1,47 @@
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