hokusai-zero 0.2.6.pre.pinephone2 → 0.2.6.pre.pinephone4

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/ast/src/core/input.c +0 -135
  3. data/ast/src/core/input.h +0 -33
  4. data/ast/test/hokusai.c +0 -2
  5. data/hokusai.gemspec +1 -1
  6. data/ui/examples/forum/file.rb +1 -1
  7. data/ui/examples/forum/post.rb +0 -1
  8. data/ui/examples/forum.rb +7 -7
  9. data/ui/examples/keyboard.rb +47 -0
  10. data/ui/examples/shader/test.rb +28 -18
  11. data/ui/examples/spreadsheet.rb +12 -11
  12. data/ui/lib/lib_hokusai.rb +19 -37
  13. data/ui/spec/hokusai/e2e/keyboard_spec.rb +52 -0
  14. data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +19 -0
  15. data/ui/src/hokusai/assets/icons/outline/backspace.svg +20 -0
  16. data/ui/src/hokusai/backends/raylib/config.rb +2 -1
  17. data/ui/src/hokusai/backends/raylib.rb +54 -20
  18. data/ui/src/hokusai/backends/sdl2/config.rb +9 -6
  19. data/ui/src/hokusai/backends/sdl2/font.rb +3 -1
  20. data/ui/src/hokusai/backends/sdl2.rb +164 -65
  21. data/ui/src/hokusai/blocks/input.rb +1 -1
  22. data/ui/src/hokusai/blocks/keyboard.rb +249 -0
  23. data/ui/src/hokusai/blocks/slider.rb +139 -0
  24. data/ui/src/hokusai/commands/rect.rb +2 -2
  25. data/ui/src/hokusai/events/touch.rb +5 -11
  26. data/ui/src/hokusai/mounting/loop_entry.rb +1 -1
  27. data/ui/src/hokusai/painter.rb +6 -2
  28. data/ui/src/hokusai/types.rb +160 -50
  29. data/ui/src/hokusai/util/wrap_stream.rb +197 -0
  30. data/ui/src/hokusai.rb +61 -30
  31. metadata +8 -6
  32. data/ast/test/input.c +0 -44
  33. data/ui/src/hokusai/backends/embedded/config.rb +0 -48
  34. data/ui/src/hokusai/backends/embedded/font.rb +0 -112
  35. data/ui/src/hokusai/backends/embedded/keys.rb +0 -124
  36. data/ui/src/hokusai/backends/embedded.rb +0 -540
data/ast/test/input.c DELETED
@@ -1,44 +0,0 @@
1
- #include "../src/core/input.c"
2
- #include<unistd.h>
3
-
4
- TEST test_hoku_input_touch_basic()
5
- {
6
- hoku_input* input;
7
- int ret = hoku_input_init(&input);
8
- ASSERT_EQ_FMT(ret, 0, "%d");
9
-
10
- ret = hoku_input_attach_touch(input, 2);
11
- ASSERT_EQ_FMT(ret, 0, "%d");
12
-
13
- hoku_input_record_touch(input, 0, 1.0, 2.0);
14
- hoku_input_clear_touch(input, 0);
15
-
16
- bool tapped = hoku_input_touch_tapped(input);
17
- bool swiped = hoku_input_touch_swiped(input, 4);
18
-
19
- ASSERT_EQ_FMT(1, tapped, "%d");
20
- ASSERT_EQ_FMT(0, swiped, "%d");
21
-
22
- hoku_input_record_touch(input, 0, 1.0, 2.0);
23
- usleep(1000);
24
- hoku_input_record_touch(input, 0, 3.0, 1.0);
25
-
26
- bool longtapped = hoku_input_touch_longtapped(input, 4);
27
-
28
- hoku_input_clear_touch(input, 0);
29
- swiped = hoku_input_touch_swiped(input, 1.0);
30
-
31
- ASSERT_EQ_FMT(1, longtapped, "%d");
32
- ASSERT_EQ_FMT(1, swiped, "%d");
33
- // ASSERT_EQ_FMT(pinched, 0, "%d");
34
-
35
- hoku_input_free(input);
36
-
37
- PASS();
38
- }
39
-
40
-
41
- SUITE(hoku_input_suite)
42
- {
43
- RUN_TEST(test_hoku_input_touch_basic);
44
- }
@@ -1,48 +0,0 @@
1
- module Hokusai::Backends
2
- class EmbeddedBackend::ConfigError < StandardError; end
3
-
4
- class EmbeddedBackend::Config
5
- attr_accessor :width, :height, :fps,
6
- :title, :config_flags, :window_state_flags,
7
- :automation_driver, :background, :after_load_cb,
8
- :host, :port, :automated, :on_reload, :event_waiting, :max_touch_count
9
-
10
- def initialize
11
- @width = 500
12
- @height = 500
13
- @fps = 60
14
- @title = "(Unknown Title)"
15
- @config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT
16
- @window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE
17
- @automation_driver = nil
18
- @background = Raylib::WHITE
19
- @after_load_cb = nil
20
- @host = "127.0.0.1"
21
- @port = 4333
22
- @automated = false
23
- @on_reload = ->(_){}
24
- @event_waiting = false
25
- @max_touch_count = 2
26
- end
27
-
28
- def start_automation_driver
29
- raise ConfigError.new("Need a Hokusai::Driver in order to automate") if automation_driver.nil?
30
-
31
- automation_driver.serve(host, port)
32
- end
33
-
34
- def automate(host, port)
35
- self.host = host
36
- self.port = port
37
- self.automated = true
38
- end
39
-
40
- def after_load(&block)
41
- self.after_load_cb = block
42
- end
43
-
44
- def on_reload(&block)
45
- @on_reload = block
46
- end
47
- end
48
- end
@@ -1,112 +0,0 @@
1
- module Hokusai
2
- module Backends
3
- class EmbeddedBackend
4
- class DataForCb < FFI::Struct
5
- layout :size, :int,
6
- :spacing, :int,
7
- :raw, :pointer
8
-
9
- def self.create(size, spacing, raw)
10
- obj = new.tap do |instance|
11
- instance[:size] = size
12
- instance[:spacing] = spacing
13
- instance[:raw] = raw
14
- end
15
-
16
- yield obj.to_ptr
17
- end
18
- end
19
-
20
- OnWidthCb = Proc.new do |char, ffi_pointer|
21
- data = DataForCb.new ffi_pointer
22
-
23
- Raylib.MeasureTextEx(data[:raw], "#{char.chr}", data[:size], data[:spacing]).x + 1.565#@ data[:spacing]
24
- end
25
-
26
- class Font < Hokusai::Font
27
- attr_reader :raw
28
-
29
- DEFAULT = "–—‘’“”…\r\n\t0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%%^&*(),.?/\"\\[]-_=+|~`{}<>;:'\0"
30
-
31
- def self.default
32
- font = Raylib.GetFontDefault
33
- Raylib.SetTextureFilter(font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
34
- # Raylib.GenTextureMipmaps(font.texture)
35
-
36
- new(font)
37
- end
38
-
39
- def self.from(file)
40
- font = Raylib.LoadFont(file)
41
- Raylib.SetTextureFilter(font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
42
- # Raylib.GenTextureMipmaps(font.texture)
43
-
44
- new(font)
45
- end
46
-
47
- def self.from_ext(file, font_size, codepoint_string = DEFAULT)
48
- ptr = FFI::MemoryPointer.new :int
49
- codepoints = Raylib.LoadCodepoints(codepoint_string, ptr)
50
- count = ptr.read_int
51
-
52
- raylib_font = Raylib.LoadFontEx(file, font_size, codepoints, count)
53
- # Raylib.GenTextureMipmaps(raylib_font.texture)
54
- Raylib.SetTextureFilter(raylib_font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
55
-
56
- font = new(raylib_font)
57
- Raylib.UnloadCodepoints(codepoints)
58
-
59
- font
60
- end
61
-
62
- def initialize(raw, spacing = 1.0)
63
- @raw = raw
64
- @spacing = spacing
65
- end
66
-
67
- # returns the spacing for this font
68
- # based on the text size
69
- def spacing
70
- ssize = raw.baseSize || 1
71
- ssize = 10 if ssize < 10
72
-
73
- (ssize / (raw.baseSize.zero? ? 1 : raw.baseSize)).to_f
74
- end
75
-
76
- def measure(string, size)
77
- vec = Raylib.MeasureTextEx(raw, string, size, spacing)
78
-
79
- [vec.x, vec.y]
80
- end
81
-
82
- def height
83
- raw.baseSize
84
- end
85
-
86
- def clamp_markdown(text, size, width, initial_offset = 0.0)
87
- clamping_pointer = FFI::MemoryPointer.new :pointer
88
- RaylibBackend::DataForCb.create(size, spacing, raw) do |ptr|
89
- ret = LibHokusai.hoku_text_md_clamp(clamping_pointer, text, width, initial_offset, ptr, RaylibBackend::OnWidthCb)
90
- raise Hokusai::Error.new("Clamping failed") unless ret.zero?
91
- end
92
-
93
- clamping = LibHokusai::HokuClamping.new(FFI::AutoPointer.new(clamping_pointer.get_pointer(0), LibHokusai.method(:hoku_text_clamping_free)))
94
-
95
- Hokusai::Clamping.new(clamping, markdown: true)
96
- end
97
-
98
- def clamp(text, size, width, initial_offset = 0.0)
99
- clamping_pointer = FFI::MemoryPointer.new :pointer
100
- EmbeddedBackend::DataForCb.create(size, spacing, raw) do |ptr|
101
- ret = LibHokusai.hoku_text_clamp(clamping_pointer, text, width, initial_offset, ptr, EmbeddedBackend::OnWidthCb)
102
- raise Hokusai::Error.new("Clamping failed") unless ret.zero?
103
- end
104
-
105
- clamping = LibHokusai::HokuClamping.new(FFI::AutoPointer.new(clamping_pointer.get_pointer(0), LibHokusai.method(:hoku_text_clamping_free)))
106
-
107
- Hokusai::Clamping.new(clamping)
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,124 +0,0 @@
1
- module Hokusai::Backends
2
- class EmbeddedBackend
3
- Keys = [
4
- [:null, Raylib::KEY_NULL],
5
- [:left_shift, Raylib::KEY_LEFT_SHIFT],
6
- [:left_control, Raylib::KEY_LEFT_CONTROL],
7
- [:left_alt, Raylib::KEY_LEFT_ALT],
8
- [:left_super, Raylib::KEY_LEFT_SUPER],
9
- [:right_shift, Raylib::KEY_RIGHT_SHIFT],
10
- [:right_control, Raylib::KEY_RIGHT_CONTROL],
11
- [:right_alt, Raylib::KEY_RIGHT_ALT],
12
- [:right_super, Raylib::KEY_RIGHT_SUPER],
13
- [:apostrophe, Raylib::KEY_APOSTROPHE],
14
- [:comma, Raylib::KEY_COMMA],
15
- [:minus, Raylib::KEY_MINUS],
16
- [:period, Raylib::KEY_PERIOD],
17
- [:slash, Raylib::KEY_SLASH],
18
- [:zero, Raylib::KEY_ZERO],
19
- [:one, Raylib::KEY_ONE],
20
- [:two, Raylib::KEY_TWO],
21
- [:three, Raylib::KEY_THREE],
22
- [:four, Raylib::KEY_FOUR],
23
- [:five, Raylib::KEY_FIVE],
24
- [:six, Raylib::KEY_SIX],
25
- [:seven, Raylib::KEY_SEVEN],
26
- [:eight, Raylib::KEY_EIGHT],
27
- [:nine, Raylib::KEY_NINE],
28
- [:semicolon, Raylib::KEY_SEMICOLON],
29
- [:equal, Raylib::KEY_EQUAL],
30
- [:a, Raylib::KEY_A],
31
- [:b, Raylib::KEY_B],
32
- [:c, Raylib::KEY_C],
33
- [:d, Raylib::KEY_D],
34
- [:e, Raylib::KEY_E],
35
- [:f, Raylib::KEY_F],
36
- [:g, Raylib::KEY_G],
37
- [:h, Raylib::KEY_H],
38
- [:i, Raylib::KEY_I],
39
- [:j, Raylib::KEY_J],
40
- [:k, Raylib::KEY_K],
41
- [:l, Raylib::KEY_L],
42
- [:m, Raylib::KEY_M],
43
- [:n, Raylib::KEY_N],
44
- [:o, Raylib::KEY_O],
45
- [:p, Raylib::KEY_P],
46
- [:q, Raylib::KEY_Q],
47
- [:r, Raylib::KEY_R],
48
- [:s, Raylib::KEY_S],
49
- [:t, Raylib::KEY_T],
50
- [:u, Raylib::KEY_U],
51
- [:v, Raylib::KEY_V],
52
- [:w, Raylib::KEY_W],
53
- [:x, Raylib::KEY_X],
54
- [:y, Raylib::KEY_Y],
55
- [:z, Raylib::KEY_Z],
56
- [:left_bracket, Raylib::KEY_LEFT_BRACKET],
57
- [:backslash, Raylib::KEY_BACKSLASH],
58
- [:right_bracket, Raylib::KEY_RIGHT_BRACKET],
59
- [:grave, Raylib::KEY_GRAVE],
60
- [:space, Raylib::KEY_SPACE],
61
- [:escape, Raylib::KEY_ESCAPE],
62
- [:enter, Raylib::KEY_ENTER],
63
- [:tab, Raylib::KEY_TAB],
64
- [:backspace, Raylib::KEY_BACKSPACE],
65
- [:insert, Raylib::KEY_INSERT],
66
- [:delete, Raylib::KEY_DELETE],
67
- [:right, Raylib::KEY_RIGHT],
68
- [:left, Raylib::KEY_LEFT],
69
- [:down, Raylib::KEY_DOWN],
70
- [:up, Raylib::KEY_UP],
71
- [:page_up, Raylib::KEY_PAGE_UP],
72
- [:page_down, Raylib::KEY_PAGE_DOWN],
73
- [:home, Raylib::KEY_HOME],
74
- [:end, Raylib::KEY_END],
75
- [:caps_lock, Raylib::KEY_CAPS_LOCK],
76
- [:scroll_lock, Raylib::KEY_SCROLL_LOCK],
77
- [:num_lock, Raylib::KEY_NUM_LOCK],
78
- [:print_screen, Raylib::KEY_PRINT_SCREEN],
79
- [:pause, Raylib::KEY_PAUSE],
80
- [:f1, Raylib::KEY_F1],
81
- [:f2, Raylib::KEY_F2],
82
- [:f3, Raylib::KEY_F3],
83
- [:f4, Raylib::KEY_F4],
84
- [:f5, Raylib::KEY_F5],
85
- [:f6, Raylib::KEY_F6],
86
- [:f7, Raylib::KEY_F7],
87
- [:f8, Raylib::KEY_F8],
88
- [:f9, Raylib::KEY_F9],
89
- [:f10, Raylib::KEY_F10],
90
- [:f11, Raylib::KEY_F11],
91
- [:f12, Raylib::KEY_F12],
92
- [:left_shift, Raylib::KEY_LEFT_SHIFT],
93
- [:left_control, Raylib::KEY_LEFT_CONTROL],
94
- [:left_alt, Raylib::KEY_LEFT_ALT],
95
- [:left_super, Raylib::KEY_LEFT_SUPER],
96
- [:right_shift, Raylib::KEY_RIGHT_SHIFT],
97
- [:right_control, Raylib::KEY_RIGHT_CONTROL],
98
- [:right_alt, Raylib::KEY_RIGHT_ALT],
99
- [:right_super, Raylib::KEY_RIGHT_SUPER],
100
- [:kb_menu, Raylib::KEY_KB_MENU],
101
- [:kp_0, Raylib::KEY_KP_0],
102
- [:kp_1, Raylib::KEY_KP_1],
103
- [:kp_2, Raylib::KEY_KP_2],
104
- [:kp_3, Raylib::KEY_KP_3],
105
- [:kp_4, Raylib::KEY_KP_4],
106
- [:kp_5, Raylib::KEY_KP_5],
107
- [:kp_6, Raylib::KEY_KP_6],
108
- [:kp_7, Raylib::KEY_KP_7],
109
- [:kp_8, Raylib::KEY_KP_8],
110
- [:kp_9, Raylib::KEY_KP_9],
111
- [:kp_decimal, Raylib::KEY_KP_DECIMAL],
112
- [:kp_divide, Raylib::KEY_KP_DIVIDE],
113
- [:kp_multiply, Raylib::KEY_KP_MULTIPLY],
114
- [:kp_subtract, Raylib::KEY_KP_SUBTRACT],
115
- [:kp_add, Raylib::KEY_KP_ADD],
116
- [:kp_enter, Raylib::KEY_KP_ENTER],
117
- [:kp_equal, Raylib::KEY_KP_EQUAL],
118
- [:back, Raylib::KEY_BACK],
119
- [:menu, Raylib::KEY_MENU],
120
- [:volume_up, Raylib::KEY_VOLUME_UP],
121
- [:volume_down, Raylib::KEY_VOLUME_DOWN]]
122
- end
123
- end
124
-