@effindomv2/fui-rs 0.1.3

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 (115) hide show
  1. package/COMMERCIAL.md +7 -0
  2. package/Cargo.toml +34 -0
  3. package/LICENSE.md +9 -0
  4. package/README.md +88 -0
  5. package/package.json +54 -0
  6. package/scripts/build.sh +227 -0
  7. package/scripts/check-runtime-dependency.sh +41 -0
  8. package/scripts/framework-host-services.ts +40 -0
  9. package/scripts/generate-host-events.ts +17 -0
  10. package/scripts/generate-host-services.ts +28 -0
  11. package/scripts/hostgen/common.ts +73 -0
  12. package/scripts/hostgen/registry.ts +159 -0
  13. package/scripts/hostgen/rust-host-events.ts +171 -0
  14. package/scripts/hostgen/rust-host-services.ts +257 -0
  15. package/src/animation.rs +625 -0
  16. package/src/app.rs +324 -0
  17. package/src/assets.rs +572 -0
  18. package/src/bindings/mod.rs +1 -0
  19. package/src/bindings/ui.rs +705 -0
  20. package/src/bitmap.rs +317 -0
  21. package/src/bridge_callbacks.rs +242 -0
  22. package/src/context_menu_manager.rs +332 -0
  23. package/src/controls/anti_selection_area.rs +54 -0
  24. package/src/controls/button.rs +542 -0
  25. package/src/controls/checkbox.rs +372 -0
  26. package/src/controls/combobox.rs +1574 -0
  27. package/src/controls/context_menu.rs +1367 -0
  28. package/src/controls/control_template_set.rs +46 -0
  29. package/src/controls/control_tokens.rs +596 -0
  30. package/src/controls/dialog.rs +590 -0
  31. package/src/controls/dropdown.rs +1010 -0
  32. package/src/controls/form.rs +229 -0
  33. package/src/controls/internal/button_presenter.rs +142 -0
  34. package/src/controls/internal/checkbox_indicator_presenter.rs +210 -0
  35. package/src/controls/internal/dropdown_chevron_presenter.rs +134 -0
  36. package/src/controls/internal/dropdown_field_presenter.rs +269 -0
  37. package/src/controls/internal/dropdown_option_row_presenter.rs +184 -0
  38. package/src/controls/internal/mod.rs +13 -0
  39. package/src/controls/internal/pressable_indicator_presenter.rs +26 -0
  40. package/src/controls/internal/pressable_labeled_control.rs +492 -0
  41. package/src/controls/internal/radio_indicator_presenter.rs +208 -0
  42. package/src/controls/internal/selectable_popup_list.rs +597 -0
  43. package/src/controls/internal/slider_presenter.rs +282 -0
  44. package/src/controls/internal/switch_indicator_presenter.rs +235 -0
  45. package/src/controls/internal/text_input_core.rs +1074 -0
  46. package/src/controls/internal/text_input_presenter.rs +108 -0
  47. package/src/controls/mod.rs +235 -0
  48. package/src/controls/nav_link.rs +395 -0
  49. package/src/controls/popup.rs +191 -0
  50. package/src/controls/progress_bar.rs +287 -0
  51. package/src/controls/radio_button.rs +348 -0
  52. package/src/controls/radio_group.rs +283 -0
  53. package/src/controls/selection_area.rs +82 -0
  54. package/src/controls/shared.rs +68 -0
  55. package/src/controls/slider.rs +701 -0
  56. package/src/controls/switch.rs +293 -0
  57. package/src/controls/templating.rs +49 -0
  58. package/src/controls/tests.rs +3905 -0
  59. package/src/controls/text_area.rs +207 -0
  60. package/src/controls/text_input.rs +192 -0
  61. package/src/debug.rs +146 -0
  62. package/src/drag_drop.rs +424 -0
  63. package/src/drag_gesture.rs +258 -0
  64. package/src/drawing.rs +385 -0
  65. package/src/event.rs +1603 -0
  66. package/src/external_drop.rs +467 -0
  67. package/src/fetch.rs +500 -0
  68. package/src/ffi.rs +3542 -0
  69. package/src/file.rs +1677 -0
  70. package/src/focus_adorner.rs +307 -0
  71. package/src/focus_visibility.rs +121 -0
  72. package/src/frame_scheduler.rs +159 -0
  73. package/src/frame_signal.rs +64 -0
  74. package/src/generated/ffi.rs +798 -0
  75. package/src/generated/framework_host_services.rs +74 -0
  76. package/src/generated/mod.rs +2 -0
  77. package/src/host_services.rs +162 -0
  78. package/src/image_sampling.rs +78 -0
  79. package/src/keyboard_scroll.rs +137 -0
  80. package/src/keyboard_scroll_tracker.rs +385 -0
  81. package/src/lib.rs +547 -0
  82. package/src/logger.rs +56 -0
  83. package/src/mobile_text_selection_toolbar.rs +1034 -0
  84. package/src/navigation.rs +48 -0
  85. package/src/node/core.rs +2210 -0
  86. package/src/node/custom_drawable.rs +149 -0
  87. package/src/node/flex_box.rs +874 -0
  88. package/src/node/grid.rs +304 -0
  89. package/src/node/helpers.rs +442 -0
  90. package/src/node/image.rs +506 -0
  91. package/src/node/mod.rs +315 -0
  92. package/src/node/scroll_bar.rs +845 -0
  93. package/src/node/scroll_box.rs +514 -0
  94. package/src/node/scroll_state.rs +121 -0
  95. package/src/node/scroll_view.rs +557 -0
  96. package/src/node/svg_node.rs +474 -0
  97. package/src/node/text_node.rs +633 -0
  98. package/src/node/virtual_list.rs +678 -0
  99. package/src/panic_hook.rs +36 -0
  100. package/src/persisted.rs +274 -0
  101. package/src/platform.rs +556 -0
  102. package/src/popup_presenter.rs +344 -0
  103. package/src/selection_handle_adorner.rs +838 -0
  104. package/src/signal.rs +134 -0
  105. package/src/text.rs +1065 -0
  106. package/src/theme.rs +571 -0
  107. package/src/timers.rs +106 -0
  108. package/src/tool_tip.rs +167 -0
  109. package/src/tool_tip_manager.rs +691 -0
  110. package/src/transitions.rs +41 -0
  111. package/src/typography.rs +520 -0
  112. package/src/viewport.rs +108 -0
  113. package/src/worker.rs +308 -0
  114. package/src/worker_job.rs +82 -0
  115. package/src/worker_runtime.rs +172 -0
@@ -0,0 +1,108 @@
1
+ use crate::controls::TextInputColors;
2
+ use crate::ffi::{CursorStyle, Unit};
3
+ use crate::node::{FlexBox, TextCore};
4
+ use crate::theme::Theme;
5
+ use std::cell::RefCell;
6
+ use std::rc::Rc;
7
+
8
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9
+ pub struct TextInputVisualState {
10
+ pub multiline: bool,
11
+ pub enabled: bool,
12
+ pub wrapping: bool,
13
+ }
14
+
15
+ pub trait TextInputPresenter {
16
+ fn bind(&self, host: FlexBox, editor_host: TextCore, placeholder_host: FlexBox);
17
+ fn apply(&self, theme: Theme, state: &TextInputVisualState, colors: Option<TextInputColors>);
18
+ }
19
+
20
+ pub trait TextInputTemplate {
21
+ fn create(&self) -> Rc<dyn TextInputPresenter>;
22
+ }
23
+
24
+ #[derive(Clone, Default)]
25
+ pub struct DefaultTextInputPresenter {
26
+ host: RefCell<Option<FlexBox>>,
27
+ editor_host: RefCell<Option<TextCore>>,
28
+ placeholder_host: RefCell<Option<FlexBox>>,
29
+ }
30
+
31
+ impl DefaultTextInputPresenter {
32
+ pub fn new() -> Self {
33
+ Self::default()
34
+ }
35
+ }
36
+
37
+ impl TextInputPresenter for DefaultTextInputPresenter {
38
+ fn bind(&self, host: FlexBox, editor_host: TextCore, placeholder_host: FlexBox) {
39
+ *self.host.borrow_mut() = Some(host);
40
+ *self.editor_host.borrow_mut() = Some(editor_host);
41
+ *self.placeholder_host.borrow_mut() = Some(placeholder_host);
42
+ }
43
+
44
+ fn apply(&self, theme: Theme, state: &TextInputVisualState, colors: Option<TextInputColors>) {
45
+ let Some(host) = self.host.borrow().clone() else {
46
+ return;
47
+ };
48
+ let Some(editor_host) = self.editor_host.borrow().clone() else {
49
+ return;
50
+ };
51
+ let Some(placeholder_host) = self.placeholder_host.borrow().clone() else {
52
+ return;
53
+ };
54
+
55
+ let horizontal_padding = theme.spacing.md;
56
+ let vertical_padding = theme.spacing.sm;
57
+ let editable_cursor = if state.enabled {
58
+ CursorStyle::Text
59
+ } else {
60
+ CursorStyle::Default
61
+ };
62
+ let shell_cursor = if !state.multiline && state.enabled {
63
+ CursorStyle::Text
64
+ } else {
65
+ CursorStyle::Default
66
+ };
67
+ let bg = colors
68
+ .filter(|value| value.has_background())
69
+ .map(|value| value.background_color())
70
+ .unwrap_or(theme.colors.surface);
71
+ let border_color = colors
72
+ .filter(|value| value.has_border())
73
+ .map(|value| value.border_color())
74
+ .unwrap_or(theme.colors.border);
75
+
76
+ host.bg_color(bg)
77
+ .corner_radius(theme.spacing.sm)
78
+ .border(1.0, border_color)
79
+ .padding(
80
+ horizontal_padding,
81
+ vertical_padding,
82
+ horizontal_padding,
83
+ vertical_padding,
84
+ )
85
+ .cursor(shell_cursor)
86
+ .opacity(if state.enabled { 1.0 } else { 0.6 });
87
+ editor_host.cursor(editable_cursor);
88
+ placeholder_host
89
+ .position(horizontal_padding, vertical_padding)
90
+ .width(100.0, Unit::Percent)
91
+ .cursor(editable_cursor);
92
+ }
93
+ }
94
+
95
+ #[derive(Clone)]
96
+ pub struct DefaultTextInputTemplate;
97
+
98
+ impl TextInputTemplate for DefaultTextInputTemplate {
99
+ fn create(&self) -> Rc<dyn TextInputPresenter> {
100
+ Rc::new(DefaultTextInputPresenter::new())
101
+ }
102
+ }
103
+
104
+ pub const DEFAULT_TEXT_INPUT_TEMPLATE: DefaultTextInputTemplate = DefaultTextInputTemplate;
105
+
106
+ pub fn create_default_text_input_presenter() -> Rc<dyn TextInputPresenter> {
107
+ DEFAULT_TEXT_INPUT_TEMPLATE.create()
108
+ }
@@ -0,0 +1,235 @@
1
+ use crate::bindings::ui;
2
+ use crate::event::{KeyEventArgs, PointerEventArgs};
3
+ use crate::ffi::{
4
+ AlignItems, CursorStyle, FlexDirection, JustifyContent, Orientation, PositionType,
5
+ SemanticCheckedState, SemanticRole, Unit,
6
+ };
7
+ use crate::node::{
8
+ flex_box, row, Border, Child, FlexBox, HasFlexBoxRoot, Node, NodeRef, TextNode, WeakNodeRef,
9
+ };
10
+ use crate::theme::{current_theme, subscribe};
11
+ use std::cell::{Cell, RefCell};
12
+ use std::rc::Rc;
13
+
14
+ pub(crate) mod internal;
15
+ mod shared;
16
+ use internal::pressable_labeled_control::PressableLabeledControl;
17
+ use radio_group::WeakRadioGroupEventTarget;
18
+ pub(crate) use shared::*;
19
+
20
+ #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
21
+ pub struct ClickEventArgs {
22
+ pub click_count: i32,
23
+ }
24
+
25
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
26
+ pub enum CheckState {
27
+ False,
28
+ True,
29
+ Mixed,
30
+ }
31
+
32
+ impl CheckState {
33
+ fn semantic(self) -> SemanticCheckedState {
34
+ match self {
35
+ Self::False => SemanticCheckedState::False,
36
+ Self::True => SemanticCheckedState::True,
37
+ Self::Mixed => SemanticCheckedState::Mixed,
38
+ }
39
+ }
40
+
41
+ pub fn is_checked(self) -> bool {
42
+ self == Self::True
43
+ }
44
+ }
45
+
46
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
47
+ pub struct CheckboxChangedEventArgs {
48
+ pub state: CheckState,
49
+ pub checked: bool,
50
+ }
51
+
52
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
53
+ pub struct RadioButtonChangedEventArgs {
54
+ pub checked: bool,
55
+ }
56
+
57
+ #[derive(Clone, Debug, PartialEq, Eq)]
58
+ pub struct RadioGroupChangedEventArgs {
59
+ pub value: String,
60
+ }
61
+
62
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
63
+ pub struct SwitchChangedEventArgs {
64
+ pub checked: bool,
65
+ }
66
+
67
+ #[derive(Clone, Copy, Debug, PartialEq)]
68
+ pub struct SliderChangedEventArgs {
69
+ pub value: f32,
70
+ }
71
+
72
+ #[derive(Clone, Debug, PartialEq, Eq)]
73
+ pub struct DropdownChangedEventArgs<T> {
74
+ pub item: T,
75
+ pub selected_index: i32,
76
+ }
77
+
78
+ #[derive(Clone, Debug, PartialEq, Eq)]
79
+ pub struct ComboBoxChangedEventArgs<T> {
80
+ pub item: T,
81
+ pub selected_index: i32,
82
+ }
83
+
84
+ pub mod anti_selection_area;
85
+ pub mod button;
86
+ pub mod checkbox;
87
+ pub mod combobox;
88
+ pub mod context_menu;
89
+ pub mod control_template_set;
90
+ pub mod control_tokens;
91
+ pub mod dialog;
92
+ pub mod dropdown;
93
+ pub mod form;
94
+ pub mod nav_link;
95
+ pub mod popup;
96
+ pub mod progress_bar;
97
+ pub mod radio_button;
98
+ pub mod radio_group;
99
+ pub mod selection_area;
100
+ pub mod slider;
101
+ pub mod switch;
102
+ pub mod templating;
103
+ #[cfg(test)]
104
+ mod tests;
105
+ pub mod text_area;
106
+ pub mod text_input;
107
+
108
+ pub use anti_selection_area::AntiSelectionArea;
109
+ pub use button::Button;
110
+ pub use checkbox::Checkbox;
111
+ pub use combobox::{ComboBox, ComboBoxCommitMode, ComboBoxFilterMode, ComboBoxItem};
112
+ pub use context_menu::{
113
+ run_context_menu_action, ContextMenu, ContextMenuAction, ContextMenuVisibilityChangedEventArgs,
114
+ MenuItem,
115
+ };
116
+ pub use control_template_set::{
117
+ clear_control_templates, get_control_templates, use_control_templates, ControlTemplateSet,
118
+ };
119
+ pub use control_tokens::{
120
+ ButtonColors, DropdownColors, DropdownSizing, LabeledControlColors, LabeledControlSizing,
121
+ SliderColors, SliderSizing, TextInputColors,
122
+ };
123
+ pub use dialog::{Dialog, DialogShownEventArgs};
124
+ pub use dropdown::{Dropdown, DropdownItem};
125
+ pub use form::Form;
126
+ pub use nav_link::{NavLink, NavigateEventArgs};
127
+ pub use popup::Popup;
128
+ pub use progress_bar::ProgressBar;
129
+ pub use radio_button::RadioButton;
130
+ pub use radio_group::RadioGroup;
131
+ pub use selection_area::SelectionArea;
132
+ pub use slider::Slider;
133
+ pub use switch::Switch;
134
+ pub use templating::{
135
+ create_default_button_presenter, create_default_checkbox_indicator_presenter,
136
+ create_default_dropdown_chevron_presenter, create_default_dropdown_field_presenter,
137
+ create_default_dropdown_option_row_presenter, create_default_radio_indicator_presenter,
138
+ create_default_slider_presenter, create_default_switch_indicator_presenter,
139
+ create_default_text_input_presenter, ButtonPresenter, ButtonTemplate, ButtonVisualState,
140
+ CheckboxIndicatorPresenter, CheckboxIndicatorTemplate, CheckboxIndicatorVisualState,
141
+ DefaultButtonTemplate, DefaultCheckboxIndicatorTemplate, DefaultDropdownChevronTemplate,
142
+ DefaultDropdownFieldTemplate, DefaultDropdownOptionRowTemplate, DefaultRadioIndicatorTemplate,
143
+ DefaultSliderTemplate, DefaultSwitchIndicatorTemplate, DefaultTextInputTemplate,
144
+ DropdownChevronMetrics, DropdownChevronPresenter, DropdownChevronTemplate,
145
+ DropdownChevronVisualState, DropdownFieldMetrics, DropdownFieldPresenter,
146
+ DropdownFieldTemplate, DropdownFieldVisualState, DropdownOptionRowMetrics,
147
+ DropdownOptionRowPresenter, DropdownOptionRowTemplate, DropdownOptionRowVisualState,
148
+ PressableIndicatorMetrics, PressableIndicatorPresenter, PressableIndicatorVisualState,
149
+ RadioIndicatorPresenter, RadioIndicatorTemplate, RadioIndicatorVisualState, SliderPresenter,
150
+ SliderPresenterMetrics, SliderTemplate, SliderVisualState, SwitchIndicatorPresenter,
151
+ SwitchIndicatorTemplate, SwitchIndicatorVisualState, TextInputPresenter, TextInputTemplate,
152
+ TextInputVisualState, DEFAULT_BUTTON_TEMPLATE, DEFAULT_CHECKBOX_INDICATOR_TEMPLATE,
153
+ DEFAULT_DROPDOWN_CHEVRON_TEMPLATE, DEFAULT_DROPDOWN_FIELD_TEMPLATE,
154
+ DEFAULT_DROPDOWN_OPTION_ROW_TEMPLATE, DEFAULT_RADIO_INDICATOR_TEMPLATE,
155
+ DEFAULT_SLIDER_TEMPLATE, DEFAULT_SWITCH_INDICATOR_TEMPLATE, DEFAULT_TEXT_INPUT_TEMPLATE,
156
+ };
157
+ pub use text_area::TextArea;
158
+ pub use text_input::TextInput;
159
+
160
+ pub fn button(label: impl Into<String>) -> Button {
161
+ Button::new(label)
162
+ }
163
+
164
+ pub fn selection_area() -> SelectionArea {
165
+ SelectionArea::new()
166
+ }
167
+
168
+ pub fn anti_selection_area() -> AntiSelectionArea {
169
+ AntiSelectionArea::new()
170
+ }
171
+
172
+ pub fn checkbox(label: impl Into<String>) -> Checkbox {
173
+ Checkbox::new(label)
174
+ }
175
+
176
+ pub fn combo_box() -> ComboBox {
177
+ ComboBox::new()
178
+ }
179
+
180
+ pub fn context_menu<I>(items: I) -> ContextMenu
181
+ where
182
+ I: IntoIterator<Item = MenuItem>,
183
+ {
184
+ let menu = ContextMenu::new();
185
+ menu.items(items);
186
+ menu
187
+ }
188
+
189
+ pub fn popup() -> Popup {
190
+ Popup::new()
191
+ }
192
+
193
+ pub fn dialog(title: impl Into<String>, body: impl Into<String>) -> Dialog {
194
+ Dialog::new(title, body)
195
+ }
196
+
197
+ pub fn dropdown() -> Dropdown {
198
+ Dropdown::new()
199
+ }
200
+
201
+ pub fn form() -> Form {
202
+ Form::new()
203
+ }
204
+
205
+ pub fn nav_link(href: impl Into<String>) -> NavLink {
206
+ NavLink::new(href)
207
+ }
208
+
209
+ pub fn radio_button(label: impl Into<String>) -> RadioButton {
210
+ RadioButton::new(label)
211
+ }
212
+
213
+ pub fn radio_group() -> RadioGroup {
214
+ RadioGroup::new()
215
+ }
216
+
217
+ pub fn switch(label: impl Into<String>) -> Switch {
218
+ Switch::new(label)
219
+ }
220
+
221
+ pub fn progress_bar() -> ProgressBar {
222
+ ProgressBar::new()
223
+ }
224
+
225
+ pub fn slider() -> Slider {
226
+ Slider::new()
227
+ }
228
+
229
+ pub fn text_input() -> TextInput {
230
+ TextInput::new()
231
+ }
232
+
233
+ pub fn text_area() -> TextArea {
234
+ TextArea::new()
235
+ }