|
| 1 | +#include "shell/script/binding_types_breeze_ui.h" |
1 | 2 | #include "binding_types.hpp" |
2 | 3 | #include "breeze_ui/animator.h" |
3 | 4 | #include "breeze_ui/ui.h" |
@@ -41,6 +42,7 @@ namespace mb_shell::js { |
41 | 42 | return; \ |
42 | 43 | auto lock = $rt_lock(); \ |
43 | 44 | widget->prop_name = value; \ |
| 45 | + widget->needs_repaint = true; \ |
44 | 46 | } |
45 | 47 |
|
46 | 48 | // Macro for callback function getter/setter pairs |
@@ -112,60 +114,10 @@ breeze_ui::js_widget::children() const { |
112 | 114 | return result; |
113 | 115 | } |
114 | 116 |
|
115 | | -std::string breeze_ui::js_text_widget::get_text() const { |
116 | | - auto text_widget = std::dynamic_pointer_cast<ui::text_widget>($widget); |
117 | | - if (!text_widget) |
118 | | - return ""; |
119 | | - return text_widget->text; |
120 | | -} |
121 | | - |
122 | | -void breeze_ui::js_text_widget::set_text(std::string text) { |
123 | | - auto text_widget = std::dynamic_pointer_cast<ui::text_widget>($widget); |
124 | | - if (!text_widget) |
125 | | - return; |
126 | | - auto lock = $rt_lock(); |
127 | | - text_widget->text = text; |
128 | | - text_widget->needs_repaint = true; |
129 | | -} |
130 | | - |
131 | | -int breeze_ui::js_text_widget::get_font_size() const { |
132 | | - auto text_widget = std::dynamic_pointer_cast<ui::text_widget>($widget); |
133 | | - if (!text_widget) |
134 | | - return 0; |
135 | | - return text_widget->font_size; |
136 | | -} |
137 | | - |
138 | | -void breeze_ui::js_text_widget::set_font_size(int size) { |
139 | | - auto text_widget = std::dynamic_pointer_cast<ui::text_widget>($widget); |
140 | | - if (!text_widget) |
141 | | - return; |
142 | | - auto lock = $rt_lock(); |
143 | | - text_widget->font_size = size; |
144 | | - text_widget->needs_repaint = true; |
145 | | -} |
146 | | - |
147 | | -std::tuple<float, float, float, float> |
148 | | -breeze_ui::js_text_widget::get_color() const { |
149 | | - auto text_widget = std::dynamic_pointer_cast<ui::text_widget>($widget); |
150 | | - if (!text_widget) |
151 | | - return {0.0f, 0.0f, 0.0f, 0.0f}; |
152 | | - auto color_array = *text_widget->color; |
153 | | - return {color_array[0], color_array[1], color_array[2], color_array[3]}; |
154 | | -} |
155 | | - |
156 | | -void breeze_ui::js_text_widget::set_color( |
157 | | - std::optional<std::tuple<float, float, float, float>> color) { |
158 | | - auto text_widget = std::dynamic_pointer_cast<ui::text_widget>($widget); |
159 | | - if (!text_widget) |
160 | | - return; |
161 | | - if (color.has_value()) { |
162 | | - text_widget->color.animate_to( |
163 | | - {std::get<0>(color.value()), std::get<1>(color.value()), |
164 | | - std::get<2>(color.value()), std::get<3>(color.value())}); |
165 | | - } else { |
166 | | - text_widget->color.animate_to({0.0f, 0.0f, 0.0f, 0.0f}); |
167 | | - } |
168 | | -} |
| 117 | +IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, text, std::string); |
| 118 | +IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, font_size, int); |
| 119 | +IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, max_width, float); |
| 120 | +IMPL_COLOR_PROP(breeze_ui::js_text_widget, ui::text_widget, color); |
169 | 121 |
|
170 | 122 | void breeze_ui::js_widget::append_child_after(std::shared_ptr<js_widget> child, |
171 | 123 | int after_index) { |
@@ -317,40 +269,44 @@ struct widget_js_base : public ui::flex_widget { |
317 | 269 | ctx.rt.post_loop_thread_task( |
318 | 270 | [=, callback = this->on_update]() mutable { |
319 | 271 | callback(ctx); |
320 | | - }, true); |
| 272 | + }, |
| 273 | + true); |
321 | 274 | } |
322 | 275 |
|
323 | 276 | if (ctx.hovered(this) && ctx.mouse_clicked && on_click) { |
324 | 277 | ctx.rt.post_loop_thread_task( |
325 | | - [callback = this->on_click]() mutable { callback(0); }, true); |
| 278 | + [callback = this->on_click]() mutable { callback(0); }, |
| 279 | + true); |
326 | 280 | } |
327 | 281 |
|
328 | 282 | if (ctx.hovered(this) && !previous_hovered && on_mouse_enter) { |
329 | 283 | ctx.rt.post_loop_thread_task( |
330 | 284 | [=, callback = this->on_mouse_enter]() mutable { |
331 | 285 | callback(); |
332 | | - }, true); |
| 286 | + }, |
| 287 | + true); |
333 | 288 | } else if (!ctx.hovered(this) && previous_hovered && |
334 | 289 | on_mouse_leave) { |
335 | 290 | ctx.rt.post_loop_thread_task( |
336 | 291 | [=, callback = this->on_mouse_leave]() mutable { |
337 | 292 | callback(); |
338 | | - }, true); |
| 293 | + }, |
| 294 | + true); |
339 | 295 | } |
340 | 296 |
|
341 | 297 | previous_hovered = ctx.hovered(this); |
342 | 298 | if (ctx.mouse_down_on(this) && on_mouse_down) { |
343 | 299 | ctx.rt.post_loop_thread_task( |
344 | 300 | [=, callback = this->on_mouse_down]() mutable { |
345 | 301 | callback(); |
346 | | - }, true); |
| 302 | + }, |
| 303 | + true); |
347 | 304 | } |
348 | 305 |
|
349 | 306 | if (ctx.mouse_up && on_mouse_up) { |
350 | 307 | ctx.rt.post_loop_thread_task( |
351 | | - [=, callback = this->on_mouse_up]() mutable { |
352 | | - callback(); |
353 | | - }, true); |
| 308 | + [=, callback = this->on_mouse_up]() mutable { callback(); }, |
| 309 | + true); |
354 | 310 | } |
355 | 311 |
|
356 | 312 | if (ctx.mouse_x != prev_mouse_x || ctx.mouse_y != prev_mouse_y) { |
@@ -506,7 +462,8 @@ IMPL_ANIMATED_PROP(breeze_ui::js_flex_layout_widget, widget_js_base, |
506 | 462 |
|
507 | 463 | IMPL_SIMPLE_PROP(breeze_ui::js_flex_layout_widget, widget_js_base, auto_size, |
508 | 464 | bool) |
509 | | - |
| 465 | +IMPL_SIMPLE_PROP(breeze_ui::js_flex_layout_widget, widget_js_base, flex_grow, |
| 466 | + float) |
510 | 467 | IMPL_SIMPLE_PROP(breeze_ui::js_flex_layout_widget, widget_js_base, gap, float) |
511 | 468 | std::string breeze_ui::js_flex_layout_widget::get_justify_content() const { |
512 | 469 | auto widget = std::dynamic_pointer_cast<ui::flex_widget>($widget); |
|
0 commit comments