konpeito 0.1.0
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/.ruby-version +1 -0
- data/CHANGELOG.md +75 -0
- data/CONTRIBUTING.md +123 -0
- data/LICENSE +21 -0
- data/README.md +257 -0
- data/Rakefile +11 -0
- data/bin/konpeito +6 -0
- data/konpeito.gemspec +43 -0
- data/lib/konpeito/ast/typed_ast.rb +620 -0
- data/lib/konpeito/ast/visitor.rb +78 -0
- data/lib/konpeito/cache/cache_manager.rb +230 -0
- data/lib/konpeito/cache/dependency_graph.rb +192 -0
- data/lib/konpeito/cache.rb +8 -0
- data/lib/konpeito/cli/base_command.rb +187 -0
- data/lib/konpeito/cli/build_command.rb +220 -0
- data/lib/konpeito/cli/check_command.rb +104 -0
- data/lib/konpeito/cli/config.rb +231 -0
- data/lib/konpeito/cli/deps_command.rb +128 -0
- data/lib/konpeito/cli/doctor_command.rb +340 -0
- data/lib/konpeito/cli/fmt_command.rb +199 -0
- data/lib/konpeito/cli/init_command.rb +312 -0
- data/lib/konpeito/cli/lsp_command.rb +40 -0
- data/lib/konpeito/cli/run_command.rb +150 -0
- data/lib/konpeito/cli/test_command.rb +248 -0
- data/lib/konpeito/cli/watch_command.rb +212 -0
- data/lib/konpeito/cli.rb +301 -0
- data/lib/konpeito/codegen/builtin_methods.rb +229 -0
- data/lib/konpeito/codegen/cruby_backend.rb +1090 -0
- data/lib/konpeito/codegen/debug_info.rb +352 -0
- data/lib/konpeito/codegen/inliner.rb +486 -0
- data/lib/konpeito/codegen/jvm_backend.rb +197 -0
- data/lib/konpeito/codegen/jvm_generator.rb +13412 -0
- data/lib/konpeito/codegen/llvm_generator.rb +13191 -0
- data/lib/konpeito/codegen/loop_optimizer.rb +363 -0
- data/lib/konpeito/codegen/monomorphizer.rb +359 -0
- data/lib/konpeito/codegen/profile_runtime.c +341 -0
- data/lib/konpeito/codegen/profiler.rb +99 -0
- data/lib/konpeito/compiler.rb +592 -0
- data/lib/konpeito/dependency_resolver.rb +296 -0
- data/lib/konpeito/diagnostics/collector.rb +127 -0
- data/lib/konpeito/diagnostics/diagnostic.rb +237 -0
- data/lib/konpeito/diagnostics/renderer.rb +144 -0
- data/lib/konpeito/formatter/formatter.rb +1214 -0
- data/lib/konpeito/hir/builder.rb +7167 -0
- data/lib/konpeito/hir/nodes.rb +2465 -0
- data/lib/konpeito/lsp/document_manager.rb +820 -0
- data/lib/konpeito/lsp/server.rb +183 -0
- data/lib/konpeito/lsp/transport.rb +38 -0
- data/lib/konpeito/parser/prism_adapter.rb +65 -0
- data/lib/konpeito/platform.rb +103 -0
- data/lib/konpeito/profile/report.rb +136 -0
- data/lib/konpeito/rbs_inline/preprocessor.rb +199 -0
- data/lib/konpeito/stdlib/compression/compression.rb +72 -0
- data/lib/konpeito/stdlib/compression/compression.rbs +60 -0
- data/lib/konpeito/stdlib/compression/compression_native.c +415 -0
- data/lib/konpeito/stdlib/compression/extconf.rb +19 -0
- data/lib/konpeito/stdlib/crypto/crypto.rb +85 -0
- data/lib/konpeito/stdlib/crypto/crypto.rbs +74 -0
- data/lib/konpeito/stdlib/crypto/crypto_native.c +312 -0
- data/lib/konpeito/stdlib/crypto/extconf.rb +40 -0
- data/lib/konpeito/stdlib/http/extconf.rb +19 -0
- data/lib/konpeito/stdlib/http/http.rb +125 -0
- data/lib/konpeito/stdlib/http/http.rbs +57 -0
- data/lib/konpeito/stdlib/http/http_native.c +440 -0
- data/lib/konpeito/stdlib/json/extconf.rb +17 -0
- data/lib/konpeito/stdlib/json/json.rb +44 -0
- data/lib/konpeito/stdlib/json/json.rbs +33 -0
- data/lib/konpeito/stdlib/json/json_native.c +286 -0
- data/lib/konpeito/stdlib/ui/extconf.rb +216 -0
- data/lib/konpeito/stdlib/ui/konpeito_ui_native.cpp +1625 -0
- data/lib/konpeito/stdlib/ui/konpeito_ui_native.h +162 -0
- data/lib/konpeito/stdlib/ui/ui.rb +318 -0
- data/lib/konpeito/stdlib/ui/ui.rbs +247 -0
- data/lib/konpeito/type_checker/annotation_parser.rb +67 -0
- data/lib/konpeito/type_checker/hm_inferrer.rb +2565 -0
- data/lib/konpeito/type_checker/inferrer.rb +565 -0
- data/lib/konpeito/type_checker/rbs_loader.rb +1621 -0
- data/lib/konpeito/type_checker/type_resolver.rb +276 -0
- data/lib/konpeito/type_checker/types.rb +1434 -0
- data/lib/konpeito/type_checker/unification.rb +323 -0
- data/lib/konpeito/ui/animation/animated_state.rb +80 -0
- data/lib/konpeito/ui/animation/easing.rb +59 -0
- data/lib/konpeito/ui/animation/value_tween.rb +66 -0
- data/lib/konpeito/ui/app.rb +379 -0
- data/lib/konpeito/ui/box.rb +38 -0
- data/lib/konpeito/ui/castella.rb +70 -0
- data/lib/konpeito/ui/castella_native.rb +76 -0
- data/lib/konpeito/ui/chart/area_chart.rb +305 -0
- data/lib/konpeito/ui/chart/bar_chart.rb +288 -0
- data/lib/konpeito/ui/chart/base_chart.rb +210 -0
- data/lib/konpeito/ui/chart/chart_helpers.rb +79 -0
- data/lib/konpeito/ui/chart/gauge_chart.rb +171 -0
- data/lib/konpeito/ui/chart/heatmap_chart.rb +222 -0
- data/lib/konpeito/ui/chart/line_chart.rb +289 -0
- data/lib/konpeito/ui/chart/pie_chart.rb +219 -0
- data/lib/konpeito/ui/chart/scales.rb +77 -0
- data/lib/konpeito/ui/chart/scatter_chart.rb +303 -0
- data/lib/konpeito/ui/chart/stacked_bar_chart.rb +276 -0
- data/lib/konpeito/ui/column.rb +271 -0
- data/lib/konpeito/ui/core.rb +2199 -0
- data/lib/konpeito/ui/dsl.rb +443 -0
- data/lib/konpeito/ui/frame.rb +171 -0
- data/lib/konpeito/ui/frame_native.rb +494 -0
- data/lib/konpeito/ui/markdown/ast.rb +124 -0
- data/lib/konpeito/ui/markdown/mermaid/layout.rb +387 -0
- data/lib/konpeito/ui/markdown/mermaid/models.rb +232 -0
- data/lib/konpeito/ui/markdown/mermaid/parser.rb +519 -0
- data/lib/konpeito/ui/markdown/mermaid/renderer.rb +336 -0
- data/lib/konpeito/ui/markdown/parser.rb +805 -0
- data/lib/konpeito/ui/markdown/renderer.rb +639 -0
- data/lib/konpeito/ui/markdown/theme.rb +165 -0
- data/lib/konpeito/ui/render_node.rb +260 -0
- data/lib/konpeito/ui/row.rb +207 -0
- data/lib/konpeito/ui/spacer.rb +18 -0
- data/lib/konpeito/ui/style.rb +799 -0
- data/lib/konpeito/ui/theme.rb +563 -0
- data/lib/konpeito/ui/themes/material.rb +35 -0
- data/lib/konpeito/ui/themes/tokyo_night.rb +6 -0
- data/lib/konpeito/ui/widgets/button.rb +103 -0
- data/lib/konpeito/ui/widgets/calendar.rb +1034 -0
- data/lib/konpeito/ui/widgets/checkbox.rb +119 -0
- data/lib/konpeito/ui/widgets/container.rb +91 -0
- data/lib/konpeito/ui/widgets/data_table.rb +667 -0
- data/lib/konpeito/ui/widgets/divider.rb +29 -0
- data/lib/konpeito/ui/widgets/image.rb +105 -0
- data/lib/konpeito/ui/widgets/input.rb +485 -0
- data/lib/konpeito/ui/widgets/markdown.rb +57 -0
- data/lib/konpeito/ui/widgets/modal.rb +163 -0
- data/lib/konpeito/ui/widgets/multiline_input.rb +968 -0
- data/lib/konpeito/ui/widgets/multiline_text.rb +180 -0
- data/lib/konpeito/ui/widgets/net_image.rb +100 -0
- data/lib/konpeito/ui/widgets/progress_bar.rb +70 -0
- data/lib/konpeito/ui/widgets/radio_buttons.rb +93 -0
- data/lib/konpeito/ui/widgets/slider.rb +133 -0
- data/lib/konpeito/ui/widgets/switch.rb +84 -0
- data/lib/konpeito/ui/widgets/tabs.rb +157 -0
- data/lib/konpeito/ui/widgets/text.rb +110 -0
- data/lib/konpeito/ui/widgets/tree.rb +426 -0
- data/lib/konpeito/version.rb +5 -0
- data/lib/konpeito.rb +109 -0
- data/test_native_array.rb +172 -0
- data/test_native_array_class.rb +197 -0
- data/test_native_class.rb +151 -0
- data/tools/konpeito-asm/build.sh +65 -0
- data/tools/konpeito-asm/lib/asm-9.7.1.jar +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KArray.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KCompression.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KConditionVariable.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KCrypto.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KFile.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KHTTP.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KHash.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KJSON$Parser.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KJSON.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KMath.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRactor.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRactorPort.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KSizedQueue.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KThread.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KTime.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/RubyDispatch.class +0 -0
- data/tools/konpeito-asm/src/ClassIntrospector.java +312 -0
- data/tools/konpeito-asm/src/KonpeitoAssembler.java +659 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KArray.java +390 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KCompression.java +168 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KConditionVariable.java +48 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KCrypto.java +151 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KFile.java +100 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KHTTP.java +113 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KHash.java +228 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KJSON.java +405 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KMath.java +54 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KRactor.java +244 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KRactorPort.java +53 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KSizedQueue.java +49 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KThread.java +49 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KTime.java +53 -0
- data/tools/konpeito-asm/src/konpeito/runtime/RubyDispatch.java +416 -0
- metadata +267 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
# rbs_inline: enabled
|
|
2
|
+
|
|
3
|
+
# DSL - Block-based UI tree builder (CSS-inspired)
|
|
4
|
+
#
|
|
5
|
+
# Uses a widget stack to manage implicit parent-child relationships.
|
|
6
|
+
# Lowercase DSL functions (column, row, text, etc.) create widgets
|
|
7
|
+
# and auto-add them to the current parent in the stack.
|
|
8
|
+
#
|
|
9
|
+
# Usage (keyword arguments — recommended):
|
|
10
|
+
# column(padding: 16.0) {
|
|
11
|
+
# text "Count: #{@count}", font_size: 32.0, color: 0xFFC0CAF5, align: :center
|
|
12
|
+
# row(spacing: 8.0) {
|
|
13
|
+
# button(" - ", width: 80.0) { @count -= 1 }
|
|
14
|
+
# spacer
|
|
15
|
+
# button(" + ", width: 80.0) { @count += 1 }
|
|
16
|
+
# }
|
|
17
|
+
# }
|
|
18
|
+
#
|
|
19
|
+
# Usage (Style object — also supported):
|
|
20
|
+
# column(s.spacing(8)) {
|
|
21
|
+
# text("Title", s.font_size(24).color(0xFFC0CAF5).bold)
|
|
22
|
+
# row(s.fixed_height(60)) {
|
|
23
|
+
# button("-", s.width(80)) { @count -= 1 }
|
|
24
|
+
# spacer
|
|
25
|
+
# button("+", s.width(80)) { @count += 1 }
|
|
26
|
+
# }
|
|
27
|
+
# }
|
|
28
|
+
|
|
29
|
+
# Widget stack for tracking current parent container
|
|
30
|
+
DSL_STACK = []
|
|
31
|
+
|
|
32
|
+
#: (untyped w) -> void
|
|
33
|
+
def __dsl_push(w)
|
|
34
|
+
DSL_STACK.push(w)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#: () -> untyped
|
|
38
|
+
def __dsl_pop
|
|
39
|
+
DSL_STACK.pop
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# NOTE: __dsl_auto_add accesses DSL_STACK.last directly instead of
|
|
43
|
+
# going through a helper function. On JVM, returning a value from a
|
|
44
|
+
# helper function that has an if/else with nil loses the object reference
|
|
45
|
+
# (phi-node merging issue with nil branch).
|
|
46
|
+
#: (untyped w) -> void
|
|
47
|
+
def __dsl_auto_add(w)
|
|
48
|
+
len = DSL_STACK.length
|
|
49
|
+
if len > 0
|
|
50
|
+
parent = DSL_STACK.last
|
|
51
|
+
if parent != nil
|
|
52
|
+
parent.add(w)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# --- Keyword argument helper ---
|
|
58
|
+
# Applies keyword arguments directly to a widget.
|
|
59
|
+
# typography: true enables text-related kwargs (font_size, color, bold, etc.)
|
|
60
|
+
|
|
61
|
+
#: (untyped widget, Hash kwargs, bool typography) -> void
|
|
62
|
+
def __apply_kwargs(widget, kwargs, typography)
|
|
63
|
+
# Layout
|
|
64
|
+
widget.fixed_width(kwargs[:width]) if kwargs.key?(:width)
|
|
65
|
+
widget.fixed_height(kwargs[:height]) if kwargs.key?(:height)
|
|
66
|
+
if kwargs.key?(:padding)
|
|
67
|
+
p = kwargs[:padding]
|
|
68
|
+
widget.padding(p, p, p, p)
|
|
69
|
+
end
|
|
70
|
+
widget.flex(kwargs[:flex]) if kwargs.key?(:flex)
|
|
71
|
+
widget.fit_content if kwargs[:fit_content]
|
|
72
|
+
# Container
|
|
73
|
+
widget.spacing(kwargs[:spacing]) if kwargs.key?(:spacing)
|
|
74
|
+
widget.scrollable if kwargs[:scrollable]
|
|
75
|
+
widget.pin_to_bottom if kwargs[:pin_to_bottom]
|
|
76
|
+
widget.pin_to_end if kwargs[:pin_to_end]
|
|
77
|
+
# Visual
|
|
78
|
+
widget.bg_color(kwargs[:bg_color]) if kwargs.key?(:bg_color)
|
|
79
|
+
widget.border_color(kwargs[:border_color]) if kwargs.key?(:border_color)
|
|
80
|
+
widget.border_radius(kwargs[:border_radius]) if kwargs.key?(:border_radius)
|
|
81
|
+
# Expanding
|
|
82
|
+
if kwargs[:expanding]
|
|
83
|
+
widget.set_width_policy(EXPANDING)
|
|
84
|
+
widget.set_height_policy(EXPANDING)
|
|
85
|
+
end
|
|
86
|
+
widget.set_width_policy(EXPANDING) if kwargs[:expanding_width]
|
|
87
|
+
widget.set_height_policy(EXPANDING) if kwargs[:expanding_height]
|
|
88
|
+
# Typography (text/button/checkbox etc.)
|
|
89
|
+
if typography
|
|
90
|
+
widget.font_size(kwargs[:font_size]) if kwargs.key?(:font_size)
|
|
91
|
+
widget.color(kwargs[:color]) if kwargs.key?(:color)
|
|
92
|
+
widget.text_color(kwargs[:text_color]) if kwargs.key?(:text_color)
|
|
93
|
+
widget.bold if kwargs[:bold]
|
|
94
|
+
widget.italic if kwargs[:italic]
|
|
95
|
+
widget.font_family(kwargs[:font_family]) if kwargs.key?(:font_family)
|
|
96
|
+
widget.kind(kwargs[:kind]) if kwargs.key?(:kind)
|
|
97
|
+
if kwargs.key?(:align)
|
|
98
|
+
a = kwargs[:align]
|
|
99
|
+
if a == :center
|
|
100
|
+
widget.align(1)
|
|
101
|
+
elsif a == :right
|
|
102
|
+
widget.align(2)
|
|
103
|
+
elsif a == :left
|
|
104
|
+
widget.align(0)
|
|
105
|
+
else
|
|
106
|
+
widget.align(a)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# --- Style helper ---
|
|
113
|
+
|
|
114
|
+
#: () -> Style
|
|
115
|
+
def s
|
|
116
|
+
Style.new
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# --- Container DSL functions ---
|
|
120
|
+
|
|
121
|
+
#: (Style? base_style, **untyped kwargs) -> Column
|
|
122
|
+
def column(base_style = nil, **kwargs)
|
|
123
|
+
col = Column.new
|
|
124
|
+
if base_style != nil
|
|
125
|
+
base_style.apply(col)
|
|
126
|
+
end
|
|
127
|
+
__apply_kwargs(col, kwargs, false) if kwargs.length > 0
|
|
128
|
+
__dsl_push(col)
|
|
129
|
+
yield
|
|
130
|
+
__dsl_pop
|
|
131
|
+
__dsl_auto_add(col)
|
|
132
|
+
col
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
#: (Style? base_style, **untyped kwargs) -> Row
|
|
136
|
+
def row(base_style = nil, **kwargs)
|
|
137
|
+
r = Row.new
|
|
138
|
+
if base_style != nil
|
|
139
|
+
base_style.apply(r)
|
|
140
|
+
end
|
|
141
|
+
__apply_kwargs(r, kwargs, false) if kwargs.length > 0
|
|
142
|
+
__dsl_push(r)
|
|
143
|
+
yield
|
|
144
|
+
__dsl_pop
|
|
145
|
+
__dsl_auto_add(r)
|
|
146
|
+
r
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
#: (Style? base_style, **untyped kwargs) -> Box
|
|
150
|
+
def box(base_style = nil, **kwargs)
|
|
151
|
+
b = Box.new
|
|
152
|
+
if base_style != nil
|
|
153
|
+
base_style.apply(b)
|
|
154
|
+
end
|
|
155
|
+
__apply_kwargs(b, kwargs, false) if kwargs.length > 0
|
|
156
|
+
__dsl_push(b)
|
|
157
|
+
yield
|
|
158
|
+
__dsl_pop
|
|
159
|
+
__dsl_auto_add(b)
|
|
160
|
+
b
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
#: (Style? base_style, **untyped kwargs) -> Container
|
|
164
|
+
def container(base_style = nil, **kwargs)
|
|
165
|
+
c = Container.new(nil)
|
|
166
|
+
if base_style != nil
|
|
167
|
+
base_style.apply_layout(c)
|
|
168
|
+
base_style.apply_visual(c)
|
|
169
|
+
end
|
|
170
|
+
__apply_kwargs(c, kwargs, false) if kwargs.length > 0
|
|
171
|
+
__dsl_push(c)
|
|
172
|
+
yield
|
|
173
|
+
__dsl_pop
|
|
174
|
+
__dsl_auto_add(c)
|
|
175
|
+
c
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# --- Leaf DSL functions ---
|
|
179
|
+
|
|
180
|
+
#: (String content, Style? base_style, **untyped kwargs) -> Text
|
|
181
|
+
def text(content, base_style = nil, **kwargs)
|
|
182
|
+
w = Text.new(content)
|
|
183
|
+
if base_style != nil
|
|
184
|
+
base_style.apply(w)
|
|
185
|
+
base_style.apply_typography(w)
|
|
186
|
+
end
|
|
187
|
+
__apply_kwargs(w, kwargs, true) if kwargs.length > 0
|
|
188
|
+
__dsl_auto_add(w)
|
|
189
|
+
w
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
#: (String label, Style? base_style, **untyped kwargs) -> Button
|
|
193
|
+
def button(label, base_style = nil, **kwargs)
|
|
194
|
+
w = Button.new(label)
|
|
195
|
+
if base_style != nil
|
|
196
|
+
base_style.apply(w)
|
|
197
|
+
base_style.apply_typography(w)
|
|
198
|
+
end
|
|
199
|
+
__apply_kwargs(w, kwargs, true) if kwargs.length > 0
|
|
200
|
+
if block_given?
|
|
201
|
+
w.on_click { yield }
|
|
202
|
+
end
|
|
203
|
+
__dsl_auto_add(w)
|
|
204
|
+
w
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
#: () -> Spacer
|
|
208
|
+
def spacer
|
|
209
|
+
w = Spacer.new
|
|
210
|
+
__dsl_auto_add(w)
|
|
211
|
+
w
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
#: () -> Divider
|
|
215
|
+
def divider
|
|
216
|
+
w = Divider.new
|
|
217
|
+
__dsl_auto_add(w)
|
|
218
|
+
w
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
#: (String label, Style? base_style, **untyped kwargs) -> Checkbox
|
|
222
|
+
def checkbox(label, base_style = nil, **kwargs)
|
|
223
|
+
w = Checkbox.new(label)
|
|
224
|
+
if base_style != nil
|
|
225
|
+
base_style.apply(w)
|
|
226
|
+
base_style.apply_typography(w)
|
|
227
|
+
end
|
|
228
|
+
__apply_kwargs(w, kwargs, true) if kwargs.length > 0
|
|
229
|
+
__dsl_auto_add(w)
|
|
230
|
+
w
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
#: (Array options, Style? base_style, **untyped kwargs) -> RadioButtons
|
|
234
|
+
def radio_buttons(options, base_style = nil, **kwargs)
|
|
235
|
+
w = RadioButtons.new(options)
|
|
236
|
+
if base_style != nil
|
|
237
|
+
base_style.apply(w)
|
|
238
|
+
end
|
|
239
|
+
__apply_kwargs(w, kwargs, false) if kwargs.length > 0
|
|
240
|
+
__dsl_auto_add(w)
|
|
241
|
+
w
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
#: (Float min_val, Float max_val, Style? base_style, **untyped kwargs) -> Slider
|
|
245
|
+
def slider(min_val, max_val, base_style = nil, **kwargs)
|
|
246
|
+
w = Slider.new(min_val, max_val)
|
|
247
|
+
if base_style != nil
|
|
248
|
+
base_style.apply(w)
|
|
249
|
+
end
|
|
250
|
+
__apply_kwargs(w, kwargs, false) if kwargs.length > 0
|
|
251
|
+
__dsl_auto_add(w)
|
|
252
|
+
w
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
#: (String path, Style? base_style, **untyped kwargs) -> ImageWidget
|
|
256
|
+
def image(path, base_style = nil, **kwargs)
|
|
257
|
+
w = ImageWidget.new(path)
|
|
258
|
+
if base_style != nil
|
|
259
|
+
base_style.apply(w)
|
|
260
|
+
end
|
|
261
|
+
__apply_kwargs(w, kwargs, false) if kwargs.length > 0
|
|
262
|
+
__dsl_auto_add(w)
|
|
263
|
+
w
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
#: (String url, Style? base_style, **untyped kwargs) -> NetImageWidget
|
|
267
|
+
def net_image(url, base_style = nil, **kwargs)
|
|
268
|
+
w = NetImageWidget.new(url)
|
|
269
|
+
if base_style != nil
|
|
270
|
+
base_style.apply(w)
|
|
271
|
+
end
|
|
272
|
+
__apply_kwargs(w, kwargs, false) if kwargs.length > 0
|
|
273
|
+
__dsl_auto_add(w)
|
|
274
|
+
w
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
#: (String content, Style? base_style, **untyped kwargs) -> MultilineText
|
|
278
|
+
def multiline_text(content, base_style = nil, **kwargs)
|
|
279
|
+
w = MultilineText.new(content)
|
|
280
|
+
if base_style != nil
|
|
281
|
+
base_style.apply(w)
|
|
282
|
+
base_style.apply_typography(w)
|
|
283
|
+
end
|
|
284
|
+
__apply_kwargs(w, kwargs, true) if kwargs.length > 0
|
|
285
|
+
__dsl_auto_add(w)
|
|
286
|
+
w
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
#: (String content, Style? base_style, **untyped kwargs) -> Markdown
|
|
290
|
+
def markdown_text(content, base_style = nil, **kwargs)
|
|
291
|
+
w = Markdown.new(content)
|
|
292
|
+
if base_style != nil
|
|
293
|
+
base_style.apply(w)
|
|
294
|
+
end
|
|
295
|
+
__apply_kwargs(w, kwargs, false) if kwargs.length > 0
|
|
296
|
+
__dsl_auto_add(w)
|
|
297
|
+
w
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
#: (InputState state, Style? base_style, **untyped kwargs) -> Input
|
|
301
|
+
def text_input(state, base_style = nil, **kwargs)
|
|
302
|
+
w = Input.new(state)
|
|
303
|
+
if base_style != nil
|
|
304
|
+
base_style.apply(w)
|
|
305
|
+
base_style.apply_typography(w)
|
|
306
|
+
end
|
|
307
|
+
__apply_kwargs(w, kwargs, true) if kwargs.length > 0
|
|
308
|
+
__dsl_auto_add(w)
|
|
309
|
+
w
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
#: (MultilineInputState state, Style? base_style, **untyped kwargs) -> MultilineInput
|
|
313
|
+
def multiline_input(state, base_style = nil, **kwargs)
|
|
314
|
+
w = MultilineInput.new(state)
|
|
315
|
+
if base_style != nil
|
|
316
|
+
base_style.apply(w)
|
|
317
|
+
end
|
|
318
|
+
__apply_kwargs(w, kwargs, false) if kwargs.length > 0
|
|
319
|
+
__dsl_auto_add(w)
|
|
320
|
+
w
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
#: (Array cols, Array widths, Array rows, Style? base_style, **untyped kwargs) -> DataTable
|
|
324
|
+
def data_table(cols, widths, rows, base_style = nil, **kwargs)
|
|
325
|
+
w = DataTable.new(cols, widths, rows)
|
|
326
|
+
if base_style != nil
|
|
327
|
+
base_style.apply(w)
|
|
328
|
+
base_style.apply_typography(w)
|
|
329
|
+
end
|
|
330
|
+
__apply_kwargs(w, kwargs, true) if kwargs.length > 0
|
|
331
|
+
__dsl_auto_add(w)
|
|
332
|
+
w
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
#: () -> Switch
|
|
336
|
+
def switch_toggle
|
|
337
|
+
w = Switch.new
|
|
338
|
+
__dsl_auto_add(w)
|
|
339
|
+
w
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
#: () -> ProgressBar
|
|
343
|
+
def progress_bar
|
|
344
|
+
w = ProgressBar.new
|
|
345
|
+
__dsl_auto_add(w)
|
|
346
|
+
w
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# --- Complex widget DSL functions ---
|
|
350
|
+
|
|
351
|
+
#: (Array labels, Array contents) -> Tabs
|
|
352
|
+
def tabs(labels, contents)
|
|
353
|
+
w = Tabs.new(labels, contents)
|
|
354
|
+
__dsl_auto_add(w)
|
|
355
|
+
w
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
#: (untyped state) -> Tree
|
|
359
|
+
def tree(state)
|
|
360
|
+
w = Tree.new(state)
|
|
361
|
+
__dsl_auto_add(w)
|
|
362
|
+
w
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
#: (untyped state) -> Calendar
|
|
366
|
+
def calendar(state)
|
|
367
|
+
w = Calendar.new(state)
|
|
368
|
+
__dsl_auto_add(w)
|
|
369
|
+
w
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
#: (untyped body) -> Modal
|
|
373
|
+
def modal(body)
|
|
374
|
+
w = Modal.new(body)
|
|
375
|
+
__dsl_auto_add(w)
|
|
376
|
+
w
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
# --- Chart DSL functions ---
|
|
380
|
+
|
|
381
|
+
#: (Array labels, Array data, Array legends) -> BarChart
|
|
382
|
+
def bar_chart(labels, data, legends)
|
|
383
|
+
w = BarChart.new(labels, data, legends)
|
|
384
|
+
__dsl_auto_add(w)
|
|
385
|
+
w
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
#: (Array labels, Array data, Array legends) -> LineChart
|
|
389
|
+
def line_chart(labels, data, legends)
|
|
390
|
+
w = LineChart.new(labels, data, legends)
|
|
391
|
+
__dsl_auto_add(w)
|
|
392
|
+
w
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
#: (Array labels, Array values) -> PieChart
|
|
396
|
+
def pie_chart(labels, values)
|
|
397
|
+
w = PieChart.new(labels, values)
|
|
398
|
+
__dsl_auto_add(w)
|
|
399
|
+
w
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
#: (Array x_data, Array y_data, Array legends) -> ScatterChart
|
|
403
|
+
def scatter_chart(x_data, y_data, legends)
|
|
404
|
+
w = ScatterChart.new(x_data, y_data, legends)
|
|
405
|
+
__dsl_auto_add(w)
|
|
406
|
+
w
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
#: (Array labels, Array data, Array legends) -> AreaChart
|
|
410
|
+
def area_chart(labels, data, legends)
|
|
411
|
+
w = AreaChart.new(labels, data, legends)
|
|
412
|
+
__dsl_auto_add(w)
|
|
413
|
+
w
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
#: (Array labels, Array data, Array legends) -> StackedBarChart
|
|
417
|
+
def stacked_bar_chart(labels, data, legends)
|
|
418
|
+
w = StackedBarChart.new(labels, data, legends)
|
|
419
|
+
__dsl_auto_add(w)
|
|
420
|
+
w
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
#: (Float value, Float min_val, Float max_val) -> GaugeChart
|
|
424
|
+
def gauge_chart(value, min_val, max_val)
|
|
425
|
+
w = GaugeChart.new(value, min_val, max_val)
|
|
426
|
+
__dsl_auto_add(w)
|
|
427
|
+
w
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
#: (Array x_labels, Array y_labels, Array data) -> HeatmapChart
|
|
431
|
+
def heatmap_chart(x_labels, y_labels, data)
|
|
432
|
+
w = HeatmapChart.new(x_labels, y_labels, data)
|
|
433
|
+
__dsl_auto_add(w)
|
|
434
|
+
w
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
# --- Generic embed function ---
|
|
438
|
+
# Use this to add any pre-created widget to the current DSL parent.
|
|
439
|
+
#: (untyped w) -> untyped
|
|
440
|
+
def embed(w)
|
|
441
|
+
__dsl_auto_add(w)
|
|
442
|
+
w
|
|
443
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# rbs_inline: enabled
|
|
2
|
+
|
|
3
|
+
# JWMFrame - bridges KUIRuntime (Java) to the Castella App
|
|
4
|
+
# Port of Castella Frame protocol
|
|
5
|
+
|
|
6
|
+
KUIRuntime = Java::Konpeito::Ui::KUIRuntime
|
|
7
|
+
|
|
8
|
+
class JWMFrame
|
|
9
|
+
#: (String title, Integer width, Integer height) -> void
|
|
10
|
+
def initialize(title, width, height)
|
|
11
|
+
@runtime = KUIRuntime.new(title, width, height)
|
|
12
|
+
@on_redraw = nil
|
|
13
|
+
@on_mouse_down = nil
|
|
14
|
+
@on_mouse_up = nil
|
|
15
|
+
@on_cursor_pos = nil
|
|
16
|
+
@on_mouse_wheel = nil
|
|
17
|
+
@on_input_char = nil
|
|
18
|
+
@on_input_key = nil
|
|
19
|
+
@on_resize = nil
|
|
20
|
+
@on_ime_preedit = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#: () { (untyped, bool) -> void } -> void
|
|
24
|
+
def on_redraw(&block)
|
|
25
|
+
@on_redraw = block
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#: () { (MouseEvent) -> void } -> void
|
|
29
|
+
def on_mouse_down(&block)
|
|
30
|
+
@on_mouse_down = block
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#: () { (MouseEvent) -> void } -> void
|
|
34
|
+
def on_mouse_up(&block)
|
|
35
|
+
@on_mouse_up = block
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#: () { (MouseEvent) -> void } -> void
|
|
39
|
+
def on_cursor_pos(&block)
|
|
40
|
+
@on_cursor_pos = block
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#: () { (WheelEvent) -> void } -> void
|
|
44
|
+
def on_mouse_wheel(&block)
|
|
45
|
+
@on_mouse_wheel = block
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#: () { (String) -> void } -> void
|
|
49
|
+
def on_input_char(&block)
|
|
50
|
+
@on_input_char = block
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#: () { (Integer, Integer) -> void } -> void
|
|
54
|
+
def on_input_key(&block)
|
|
55
|
+
@on_input_key = block
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#: () { () -> void } -> void
|
|
59
|
+
def on_resize(&block)
|
|
60
|
+
@on_resize = block
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
#: () { (String, Integer, Integer) -> void } -> void
|
|
64
|
+
def on_ime_preedit(&block)
|
|
65
|
+
@on_ime_preedit = block
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#: () -> bool
|
|
69
|
+
def is_dark_mode
|
|
70
|
+
@runtime.is_dark_mode
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#: () -> untyped
|
|
74
|
+
def get_painter
|
|
75
|
+
@runtime
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
#: () -> Size
|
|
79
|
+
def get_size
|
|
80
|
+
Size.new(@runtime.get_width, @runtime.get_height)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
#: (untyped ev) -> void
|
|
84
|
+
def post_update(ev)
|
|
85
|
+
@runtime.mark_dirty
|
|
86
|
+
@runtime.request_frame
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# --- IME / Text Input control ---
|
|
90
|
+
|
|
91
|
+
#: () -> void
|
|
92
|
+
def enable_text_input
|
|
93
|
+
@runtime.set_text_input_enabled(true)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#: () -> void
|
|
97
|
+
def disable_text_input
|
|
98
|
+
@runtime.set_text_input_enabled(false)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
#: (Integer x, Integer y, Integer w, Integer h) -> void
|
|
102
|
+
def set_ime_cursor_rect(x, y, w, h)
|
|
103
|
+
@runtime.set_text_input_rect(x, y, w, h)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# --- Clipboard ---
|
|
107
|
+
|
|
108
|
+
#: () -> String
|
|
109
|
+
def get_clipboard_text
|
|
110
|
+
@runtime.get_clipboard_text
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#: (String text) -> void
|
|
114
|
+
def set_clipboard_text(text)
|
|
115
|
+
@runtime.set_clipboard_text(text)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
#: () -> void
|
|
119
|
+
def run
|
|
120
|
+
rt = @runtime
|
|
121
|
+
redraw_cb = @on_redraw
|
|
122
|
+
mouse_down_cb = @on_mouse_down
|
|
123
|
+
mouse_up_cb = @on_mouse_up
|
|
124
|
+
cursor_pos_cb = @on_cursor_pos
|
|
125
|
+
mouse_wheel_cb = @on_mouse_wheel
|
|
126
|
+
input_char_cb = @on_input_char
|
|
127
|
+
input_key_cb = @on_input_key
|
|
128
|
+
ime_preedit_cb = @on_ime_preedit
|
|
129
|
+
|
|
130
|
+
rt.set_on_frame {
|
|
131
|
+
redraw_cb.call(rt, false) if redraw_cb
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
rt.set_on_mouse { |type, x, y, button|
|
|
135
|
+
pos = Point.new(x, y)
|
|
136
|
+
ev = MouseEvent.new(pos, button)
|
|
137
|
+
if type == 1
|
|
138
|
+
mouse_down_cb.call(ev) if mouse_down_cb
|
|
139
|
+
elsif type == 2
|
|
140
|
+
mouse_up_cb.call(ev) if mouse_up_cb
|
|
141
|
+
else
|
|
142
|
+
cursor_pos_cb.call(ev) if cursor_pos_cb
|
|
143
|
+
end
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
# Use ScrollDeltaCallback (2 params) to avoid SAM confusion with MouseCallback (4 params)
|
|
147
|
+
rt.set_on_scroll_delta { |dx, dy|
|
|
148
|
+
if mouse_wheel_cb != nil
|
|
149
|
+
pos = Point.new(0.0, 0.0)
|
|
150
|
+
ev = WheelEvent.new(pos, dy)
|
|
151
|
+
mouse_wheel_cb.call(ev)
|
|
152
|
+
end
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
rt.set_on_text { |text|
|
|
156
|
+
input_char_cb.call(text) if input_char_cb
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
rt.set_on_key { |type, key_code, modifiers|
|
|
160
|
+
if type == 1
|
|
161
|
+
input_key_cb.call(key_code, modifiers) if input_key_cb
|
|
162
|
+
end
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
rt.set_on_ime { |text, sel_start, sel_end|
|
|
166
|
+
ime_preedit_cb.call(text, sel_start, sel_end) if ime_preedit_cb
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
rt.run
|
|
170
|
+
end
|
|
171
|
+
end
|