ruflet 0.0.1

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 (71) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3 -0
  3. data/lib/ruflet/version.rb +5 -0
  4. data/lib/ruflet.rb +40 -0
  5. data/lib/ruflet_protocol/ruflet/protocol.rb +62 -0
  6. data/lib/ruflet_protocol.rb +4 -0
  7. data/lib/ruflet_ui/ruflet/app.rb +20 -0
  8. data/lib/ruflet_ui/ruflet/colors.rb +200 -0
  9. data/lib/ruflet_ui/ruflet/control.rb +154 -0
  10. data/lib/ruflet_ui/ruflet/dsl.rb +182 -0
  11. data/lib/ruflet_ui/ruflet/event.rb +28 -0
  12. data/lib/ruflet_ui/ruflet/icon_data.rb +57 -0
  13. data/lib/ruflet_ui/ruflet/icons/cupertino/cupertino_icons.rb +54 -0
  14. data/lib/ruflet_ui/ruflet/icons/cupertino_icon_lookup.rb +112 -0
  15. data/lib/ruflet_ui/ruflet/icons/material_icon_lookup.rb +112 -0
  16. data/lib/ruflet_ui/ruflet/icons/material_icons.rb +55 -0
  17. data/lib/ruflet_ui/ruflet/page.rb +550 -0
  18. data/lib/ruflet_ui/ruflet/ui/control_factory.rb +22 -0
  19. data/lib/ruflet_ui/ruflet/ui/control_methods.rb +16 -0
  20. data/lib/ruflet_ui/ruflet/ui/control_registry.rb +13 -0
  21. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_action_sheet_control.rb +13 -0
  22. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_alert_dialog_control.rb +13 -0
  23. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_button_control.rb +13 -0
  24. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_dialog_action_control.rb +13 -0
  25. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_filled_button_control.rb +13 -0
  26. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_navigation_bar_control.rb +13 -0
  27. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_slider_control.rb +13 -0
  28. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_switch_control.rb +13 -0
  29. data/lib/ruflet_ui/ruflet/ui/controls/cupertino/cupertino_text_field_control.rb +13 -0
  30. data/lib/ruflet_ui/ruflet/ui/controls/material/alert_dialog_control.rb +13 -0
  31. data/lib/ruflet_ui/ruflet/ui/controls/material/app_bar_control.rb +13 -0
  32. data/lib/ruflet_ui/ruflet/ui/controls/material/bottom_sheet_control.rb +13 -0
  33. data/lib/ruflet_ui/ruflet/ui/controls/material/button_control.rb +24 -0
  34. data/lib/ruflet_ui/ruflet/ui/controls/material/checkbox_control.rb +13 -0
  35. data/lib/ruflet_ui/ruflet/ui/controls/material/column_control.rb +13 -0
  36. data/lib/ruflet_ui/ruflet/ui/controls/material/container_control.rb +13 -0
  37. data/lib/ruflet_ui/ruflet/ui/controls/material/drag_target_control.rb +13 -0
  38. data/lib/ruflet_ui/ruflet/ui/controls/material/draggable_control.rb +13 -0
  39. data/lib/ruflet_ui/ruflet/ui/controls/material/elevated_button_control.rb +13 -0
  40. data/lib/ruflet_ui/ruflet/ui/controls/material/filled_button_control.rb +13 -0
  41. data/lib/ruflet_ui/ruflet/ui/controls/material/floating_action_button_control.rb +28 -0
  42. data/lib/ruflet_ui/ruflet/ui/controls/material/gesture_detector_control.rb +13 -0
  43. data/lib/ruflet_ui/ruflet/ui/controls/material/icon_button_control.rb +13 -0
  44. data/lib/ruflet_ui/ruflet/ui/controls/material/icon_control.rb +24 -0
  45. data/lib/ruflet_ui/ruflet/ui/controls/material/image_control.rb +13 -0
  46. data/lib/ruflet_ui/ruflet/ui/controls/material/markdown_control.rb +13 -0
  47. data/lib/ruflet_ui/ruflet/ui/controls/material/navigation_bar_control.rb +13 -0
  48. data/lib/ruflet_ui/ruflet/ui/controls/material/navigation_bar_destination_control.rb +13 -0
  49. data/lib/ruflet_ui/ruflet/ui/controls/material/radio_control.rb +13 -0
  50. data/lib/ruflet_ui/ruflet/ui/controls/material/radio_group_control.rb +13 -0
  51. data/lib/ruflet_ui/ruflet/ui/controls/material/row_control.rb +13 -0
  52. data/lib/ruflet_ui/ruflet/ui/controls/material/snack_bar_control.rb +13 -0
  53. data/lib/ruflet_ui/ruflet/ui/controls/material/stack_control.rb +13 -0
  54. data/lib/ruflet_ui/ruflet/ui/controls/material/tab_bar_control.rb +13 -0
  55. data/lib/ruflet_ui/ruflet/ui/controls/material/tab_bar_view_control.rb +13 -0
  56. data/lib/ruflet_ui/ruflet/ui/controls/material/tab_control.rb +13 -0
  57. data/lib/ruflet_ui/ruflet/ui/controls/material/tabs_control.rb +63 -0
  58. data/lib/ruflet_ui/ruflet/ui/controls/material/text_button_control.rb +13 -0
  59. data/lib/ruflet_ui/ruflet/ui/controls/material/text_control.rb +13 -0
  60. data/lib/ruflet_ui/ruflet/ui/controls/material/text_field_control.rb +13 -0
  61. data/lib/ruflet_ui/ruflet/ui/controls/material/view_control.rb +13 -0
  62. data/lib/ruflet_ui/ruflet/ui/cupertino_control_factory.rb +40 -0
  63. data/lib/ruflet_ui/ruflet/ui/cupertino_control_methods.rb +26 -0
  64. data/lib/ruflet_ui/ruflet/ui/cupertino_control_registry.rb +35 -0
  65. data/lib/ruflet_ui/ruflet/ui/material_control_factory.rb +94 -0
  66. data/lib/ruflet_ui/ruflet/ui/material_control_methods.rb +116 -0
  67. data/lib/ruflet_ui/ruflet/ui/material_control_registry.rb +88 -0
  68. data/lib/ruflet_ui/ruflet/ui/shared_control_forwarders.rb +85 -0
  69. data/lib/ruflet_ui/ruflet/ui/widget_builder.rb +48 -0
  70. data/lib/ruflet_ui.rb +112 -0
  71. metadata +109 -0
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruflet
4
+ module UI
5
+ module CupertinoControlRegistry
6
+ TYPE_MAP = {
7
+ "cupertino_button" => "CupertinoButton",
8
+ "cupertinobutton" => "CupertinoButton",
9
+ "cupertino_filled_button" => "CupertinoFilledButton",
10
+ "cupertinofilledbutton" => "CupertinoFilledButton",
11
+ "cupertino_text_field" => "CupertinoTextField",
12
+ "cupertinotextfield" => "CupertinoTextField",
13
+ "cupertino_switch" => "CupertinoSwitch",
14
+ "cupertinoswitch" => "CupertinoSwitch",
15
+ "cupertino_slider" => "CupertinoSlider",
16
+ "cupertinoslider" => "CupertinoSlider",
17
+ "cupertino_alert_dialog" => "CupertinoAlertDialog",
18
+ "cupertinoalertdialog" => "CupertinoAlertDialog",
19
+ "cupertino_action_sheet" => "CupertinoActionSheet",
20
+ "cupertinoactionsheet" => "CupertinoActionSheet",
21
+ "cupertino_dialog_action" => "CupertinoDialogAction",
22
+ "cupertinodialogaction" => "CupertinoDialogAction",
23
+ "cupertino_navigation_bar" => "CupertinoNavigationBar",
24
+ "cupertinonavigationbar" => "CupertinoNavigationBar"
25
+ }.freeze
26
+
27
+ EVENT_PROPS = {
28
+ on_click: "click",
29
+ on_change: "change",
30
+ on_submit: "submit",
31
+ on_dismiss: "dismiss"
32
+ }.freeze
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "controls/material/text_control"
4
+ require_relative "controls/material/view_control"
5
+ require_relative "controls/material/container_control"
6
+ require_relative "controls/material/column_control"
7
+ require_relative "controls/material/row_control"
8
+ require_relative "controls/material/stack_control"
9
+ require_relative "controls/material/gesture_detector_control"
10
+ require_relative "controls/material/draggable_control"
11
+ require_relative "controls/material/drag_target_control"
12
+ require_relative "controls/material/text_field_control"
13
+ require_relative "controls/material/button_control"
14
+ require_relative "controls/material/elevated_button_control"
15
+ require_relative "controls/material/text_button_control"
16
+ require_relative "controls/material/filled_button_control"
17
+ require_relative "controls/material/icon_button_control"
18
+ require_relative "controls/material/icon_control"
19
+ require_relative "controls/material/image_control"
20
+ require_relative "controls/material/app_bar_control"
21
+ require_relative "controls/material/floating_action_button_control"
22
+ require_relative "controls/material/checkbox_control"
23
+ require_relative "controls/material/radio_control"
24
+ require_relative "controls/material/radio_group_control"
25
+ require_relative "controls/material/alert_dialog_control"
26
+ require_relative "controls/material/snack_bar_control"
27
+ require_relative "controls/material/bottom_sheet_control"
28
+ require_relative "controls/material/markdown_control"
29
+ require_relative "controls/material/tabs_control"
30
+ require_relative "controls/material/tab_control"
31
+ require_relative "controls/material/tab_bar_control"
32
+ require_relative "controls/material/tab_bar_view_control"
33
+ require_relative "controls/material/navigation_bar_control"
34
+ require_relative "controls/material/navigation_bar_destination_control"
35
+
36
+ module Ruflet
37
+ module UI
38
+ module MaterialControlFactory
39
+ module_function
40
+
41
+ CLASS_MAP = {
42
+ "text" => Controls::TextControl,
43
+ "view" => Controls::ViewControl,
44
+ "column" => Controls::ColumnControl,
45
+ "row" => Controls::RowControl,
46
+ "stack" => Controls::StackControl,
47
+ "container" => Controls::ContainerControl,
48
+ "gesturedetector" => Controls::GestureDetectorControl,
49
+ "gesture_detector" => Controls::GestureDetectorControl,
50
+ "draggable" => Controls::DraggableControl,
51
+ "dragtarget" => Controls::DragTargetControl,
52
+ "drag_target" => Controls::DragTargetControl,
53
+ "textfield" => Controls::TextFieldControl,
54
+ "text_field" => Controls::TextFieldControl,
55
+ "button" => Controls::ButtonControl,
56
+ "elevatedbutton" => Controls::ElevatedButtonControl,
57
+ "elevated_button" => Controls::ElevatedButtonControl,
58
+ "textbutton" => Controls::TextButtonControl,
59
+ "text_button" => Controls::TextButtonControl,
60
+ "filledbutton" => Controls::FilledButtonControl,
61
+ "filled_button" => Controls::FilledButtonControl,
62
+ "iconbutton" => Controls::IconButtonControl,
63
+ "icon_button" => Controls::IconButtonControl,
64
+ "icon" => Controls::IconControl,
65
+ "image" => Controls::ImageControl,
66
+ "appbar" => Controls::AppBarControl,
67
+ "app_bar" => Controls::AppBarControl,
68
+ "floatingactionbutton" => Controls::FloatingActionButtonControl,
69
+ "floating_action_button" => Controls::FloatingActionButtonControl,
70
+ "checkbox" => Controls::CheckboxControl,
71
+ "radio" => Controls::RadioControl,
72
+ "radiogroup" => Controls::RadioGroupControl,
73
+ "radio_group" => Controls::RadioGroupControl,
74
+ "alertdialog" => Controls::AlertDialogControl,
75
+ "alert_dialog" => Controls::AlertDialogControl,
76
+ "snackbar" => Controls::SnackBarControl,
77
+ "snack_bar" => Controls::SnackBarControl,
78
+ "bottomsheet" => Controls::BottomSheetControl,
79
+ "bottom_sheet" => Controls::BottomSheetControl,
80
+ "markdown" => Controls::MarkdownControl,
81
+ "tabs" => Controls::TabsControl,
82
+ "tab" => Controls::TabControl,
83
+ "tabbar" => Controls::TabBarControl,
84
+ "tab_bar" => Controls::TabBarControl,
85
+ "tabbarview" => Controls::TabBarViewControl,
86
+ "tab_bar_view" => Controls::TabBarViewControl,
87
+ "navigationbar" => Controls::NavigationBarControl,
88
+ "navigation_bar" => Controls::NavigationBarControl,
89
+ "navigationbardestination" => Controls::NavigationBarDestinationControl,
90
+ "navigation_bar_destination" => Controls::NavigationBarDestinationControl
91
+ }.freeze
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruflet
4
+ module UI
5
+ module MaterialControlMethods
6
+ def view(**props, &block) = build_widget(:view, **props, &block)
7
+ def column(**props, &block) = build_widget(:column, **props, &block)
8
+
9
+ def center(**props, &block)
10
+ mapped = props.dup
11
+ defaults = { expand: true, alignment: { x: 0, y: 0 } }
12
+
13
+ if block
14
+ nested = WidgetBuilder.new
15
+ block_result = nested.instance_eval(&block)
16
+ child =
17
+ if nested.children.any?
18
+ nested.children.first
19
+ elsif block_result.is_a?(Ruflet::Control)
20
+ block_result
21
+ end
22
+ mapped[:content] = child if child
23
+ end
24
+
25
+ build_widget(:container, **normalize_container_props(defaults.merge(mapped)))
26
+ end
27
+
28
+ def row(**props, &block) = build_widget(:row, **props, &block)
29
+ def stack(**props, &block) = build_widget(:stack, **props, &block)
30
+ def container(**props, &block) = build_widget(:container, **normalize_container_props(props), &block)
31
+ def gesture_detector(**props, &block) = build_widget(:gesturedetector, **props, &block)
32
+ def gesturedetector(**props, &block) = gesture_detector(**props, &block)
33
+ def draggable(**props, &block) = build_widget(:draggable, **props, &block)
34
+ def drag_target(**props, &block) = build_widget(:dragtarget, **props, &block)
35
+ def dragtarget(**props, &block) = drag_target(**props, &block)
36
+
37
+ def text(value = nil, **props)
38
+ mapped = props.dup
39
+ mapped[:value] = value unless value.nil?
40
+ build_widget(:text, **mapped)
41
+ end
42
+
43
+ def button(**props) = build_widget(:button, **props)
44
+ def elevated_button(**props) = build_widget(:elevatedbutton, **props)
45
+ def elevatedbutton(**props) = elevated_button(**props)
46
+ def text_button(**props) = build_widget(:textbutton, **props)
47
+ def textbutton(**props) = text_button(**props)
48
+ def filled_button(**props) = build_widget(:filledbutton, **props)
49
+ def filledbutton(**props) = filled_button(**props)
50
+
51
+ def icon_button(**props) = build_widget(:iconbutton, **props)
52
+ def iconbutton(**props) = icon_button(**props)
53
+ def text_field(**props) = build_widget(:textfield, **props)
54
+ def textfield(**props) = text_field(**props)
55
+ def checkbox(**props) = build_widget(:checkbox, **props)
56
+ def radio(**props) = build_widget(:radio, **props)
57
+ def radio_group(**props) = build_widget(:radiogroup, **props)
58
+ def radiogroup(**props) = radio_group(**props)
59
+ def alert_dialog(**props) = build_widget(:alertdialog, **props)
60
+ def alertdialog(**props) = alert_dialog(**props)
61
+ def snack_bar(**props) = build_widget(:snackbar, **props)
62
+ def snackbar(**props) = snack_bar(**props)
63
+ def bottom_sheet(**props) = build_widget(:bottomsheet, **props)
64
+ def bottomsheet(**props) = bottom_sheet(**props)
65
+
66
+ def markdown(value = nil, **props)
67
+ mapped = props.dup
68
+ mapped[:value] = value unless value.nil?
69
+ build_widget(:markdown, **mapped)
70
+ end
71
+
72
+ def icon(**props) = build_widget(:icon, **props)
73
+
74
+ def image(src = nil, **props)
75
+ mapped = props.dup
76
+ mapped[:src] = src unless src.nil?
77
+ build_widget(:image, **mapped)
78
+ end
79
+
80
+ def app_bar(**props) = build_widget(:appbar, **props)
81
+ def appbar(**props) = app_bar(**props)
82
+ def floating_action_button(**props) = build_widget(:floatingactionbutton, **props)
83
+ def floatingactionbutton(**props) = floating_action_button(**props)
84
+ def tabs(**props, &block) = build_widget(:tabs, **props, &block)
85
+ def tab(**props, &block) = build_widget(:tab, **props, &block)
86
+ def tab_bar(**props, &block) = build_widget(:tabbar, **props, &block)
87
+ def tabbar(**props, &block) = tab_bar(**props, &block)
88
+ def tab_bar_view(**props, &block) = build_widget(:tabbarview, **props, &block)
89
+ def tabbarview(**props, &block) = tab_bar_view(**props, &block)
90
+ def navigation_bar(**props, &block) = build_widget(:navigationbar, **props, &block)
91
+ def navigationbar(**props, &block) = navigation_bar(**props, &block)
92
+ def navigation_bar_destination(**props, &block) = build_widget(:navigationbardestination, **props, &block)
93
+ def navigationbardestination(**props, &block) = navigation_bar_destination(**props, &block)
94
+
95
+ def fab(content = nil, **props)
96
+ mapped = props.dup
97
+ mapped[:content] = content unless content.nil?
98
+ build_widget(:floatingactionbutton, **mapped)
99
+ end
100
+
101
+ private
102
+
103
+ # Flet container alignment expects a vector-like object ({x:, y:}),
104
+ # not a plain string. Keep common shorthand compatible.
105
+ def normalize_container_props(props)
106
+ mapped = props.dup
107
+ alignment = mapped[:alignment] || mapped["alignment"]
108
+ if alignment == "center" || alignment == :center
109
+ mapped[:alignment] = { x: 0, y: 0 }
110
+ mapped.delete("alignment")
111
+ end
112
+ mapped
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruflet
4
+ module UI
5
+ module MaterialControlRegistry
6
+ TYPE_MAP = {
7
+ "text" => "Text",
8
+ "column" => "Column",
9
+ "row" => "Row",
10
+ "stack" => "Stack",
11
+ "view" => "View",
12
+ "container" => "Container",
13
+ "checkbox" => "Checkbox",
14
+ "radio" => "Radio",
15
+ "radiogroup" => "RadioGroup",
16
+ "radio_group" => "RadioGroup",
17
+ "alertdialog" => "AlertDialog",
18
+ "alert_dialog" => "AlertDialog",
19
+ "snackbar" => "SnackBar",
20
+ "snack_bar" => "SnackBar",
21
+ "bottomsheet" => "BottomSheet",
22
+ "bottom_sheet" => "BottomSheet",
23
+ "markdown" => "Markdown",
24
+ "textbutton" => "TextButton",
25
+ "text_button" => "TextButton",
26
+ "filledbutton" => "FilledButton",
27
+ "filled_button" => "FilledButton",
28
+ "gesturedetector" => "GestureDetector",
29
+ "gesture_detector" => "GestureDetector",
30
+ "draggable" => "Draggable",
31
+ "dragtarget" => "DragTarget",
32
+ "drag_target" => "DragTarget",
33
+ "textfield" => "TextField",
34
+ "text_field" => "TextField",
35
+ "button" => "Button",
36
+ "elevatedbutton" => "Button",
37
+ "elevated_button" => "Button",
38
+ "iconbutton" => "IconButton",
39
+ "icon_button" => "IconButton",
40
+ "icon" => "Icon",
41
+ "image" => "Image",
42
+ "appbar" => "AppBar",
43
+ "app_bar" => "AppBar",
44
+ "floatingactionbutton" => "FloatingActionButton",
45
+ "floating_action_button" => "FloatingActionButton",
46
+ "tabs" => "Tabs",
47
+ "tab" => "Tab",
48
+ "tabbar" => "TabBar",
49
+ "tab_bar" => "TabBar",
50
+ "tabbarview" => "TabBarView",
51
+ "tab_bar_view" => "TabBarView",
52
+ "navigationbar" => "NavigationBar",
53
+ "navigation_bar" => "NavigationBar",
54
+ "navigationbardestination" => "NavigationBarDestination",
55
+ "navigation_bar_destination" => "NavigationBarDestination"
56
+ }.freeze
57
+
58
+ EVENT_PROPS = {
59
+ on_click: "click",
60
+ on_change: "change",
61
+ on_action: "action",
62
+ on_submit: "submit",
63
+ on_dismiss: "dismiss",
64
+ on_tap: "tap",
65
+ on_double_tap: "double_tap",
66
+ on_long_press: "long_press",
67
+ on_hover: "hover",
68
+ on_pan_start: "pan_start",
69
+ on_pan_update: "pan_update",
70
+ on_pan_end: "pan_end",
71
+ on_scale_start: "scale_start",
72
+ on_scale_update: "scale_update",
73
+ on_scale_end: "scale_end",
74
+ on_vertical_drag_start: "vertical_drag_start",
75
+ on_vertical_drag_update: "vertical_drag_update",
76
+ on_vertical_drag_end: "vertical_drag_end",
77
+ on_horizontal_drag_start: "horizontal_drag_start",
78
+ on_horizontal_drag_update: "horizontal_drag_update",
79
+ on_horizontal_drag_end: "horizontal_drag_end",
80
+ on_accept: "accept",
81
+ on_will_accept: "will_accept",
82
+ on_accept_with_details: "accept_with_details",
83
+ on_move: "move",
84
+ on_leave: "leave"
85
+ }.freeze
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruflet
4
+ module UI
5
+ module SharedControlForwarders
6
+ def control(type, **props, &block) = control_delegate.control(type, **props, &block)
7
+ def widget(type, **props, &block) = control_delegate.widget(type, **props, &block)
8
+ def view(**props, &block) = control_delegate.view(**props, &block)
9
+ def column(**props, &block) = control_delegate.column(**props, &block)
10
+ def center(**props, &block) = control_delegate.center(**props, &block)
11
+ def row(**props, &block) = control_delegate.row(**props, &block)
12
+ def stack(**props, &block) = control_delegate.stack(**props, &block)
13
+ def container(**props, &block) = control_delegate.container(**props, &block)
14
+ def gesture_detector(**props, &block) = control_delegate.gesture_detector(**props, &block)
15
+ def gesturedetector(**props, &block) = control_delegate.gesturedetector(**props, &block)
16
+ def draggable(**props, &block) = control_delegate.draggable(**props, &block)
17
+ def drag_target(**props, &block) = control_delegate.drag_target(**props, &block)
18
+ def dragtarget(**props, &block) = control_delegate.dragtarget(**props, &block)
19
+ def text(value = nil, **props) = control_delegate.text(value, **props)
20
+ def button(**props) = control_delegate.button(**props)
21
+ def elevated_button(**props) = control_delegate.elevated_button(**props)
22
+ def elevatedbutton(**props) = control_delegate.elevatedbutton(**props)
23
+ def text_button(**props) = control_delegate.text_button(**props)
24
+ def textbutton(**props) = control_delegate.textbutton(**props)
25
+ def filled_button(**props) = control_delegate.filled_button(**props)
26
+ def filledbutton(**props) = control_delegate.filledbutton(**props)
27
+ def icon_button(**props) = control_delegate.icon_button(**props)
28
+ def iconbutton(**props) = control_delegate.iconbutton(**props)
29
+ def text_field(**props) = control_delegate.text_field(**props)
30
+ def textfield(**props) = control_delegate.textfield(**props)
31
+ def checkbox(**props) = control_delegate.checkbox(**props)
32
+ def radio(**props) = control_delegate.radio(**props)
33
+ def radio_group(**props) = control_delegate.radio_group(**props)
34
+ def radiogroup(**props) = control_delegate.radiogroup(**props)
35
+ def alert_dialog(**props) = control_delegate.alert_dialog(**props)
36
+ def alertdialog(**props) = control_delegate.alertdialog(**props)
37
+ def snack_bar(**props) = control_delegate.snack_bar(**props)
38
+ def snackbar(**props) = control_delegate.snackbar(**props)
39
+ def bottom_sheet(**props) = control_delegate.bottom_sheet(**props)
40
+ def bottomsheet(**props) = control_delegate.bottomsheet(**props)
41
+ def markdown(value = nil, **props) = control_delegate.markdown(value, **props)
42
+ def icon(**props) = control_delegate.icon(**props)
43
+ def image(src = nil, **props) = control_delegate.image(src, **props)
44
+ def fab(content = nil, **props) = control_delegate.fab(content, **props)
45
+ def app_bar(**props) = control_delegate.app_bar(**props)
46
+ def appbar(**props) = control_delegate.appbar(**props)
47
+ def floating_action_button(**props) = control_delegate.floating_action_button(**props)
48
+ def floatingactionbutton(**props) = control_delegate.floatingactionbutton(**props)
49
+ def tabs(**props, &block) = control_delegate.tabs(**props, &block)
50
+ def tab(**props, &block) = control_delegate.tab(**props, &block)
51
+ def tab_bar(**props, &block) = control_delegate.tab_bar(**props, &block)
52
+ def tabbar(**props, &block) = control_delegate.tabbar(**props, &block)
53
+ def tab_bar_view(**props, &block) = control_delegate.tab_bar_view(**props, &block)
54
+ def tabbarview(**props, &block) = control_delegate.tabbarview(**props, &block)
55
+ def navigation_bar(**props, &block) = control_delegate.navigation_bar(**props, &block)
56
+ def navigationbar(**props, &block) = control_delegate.navigationbar(**props, &block)
57
+ def navigation_bar_destination(**props, &block) = control_delegate.navigation_bar_destination(**props, &block)
58
+ def navigationbardestination(**props, &block) = control_delegate.navigationbardestination(**props, &block)
59
+ def cupertino_button(**props) = control_delegate.cupertino_button(**props)
60
+ def cupertinobutton(**props) = control_delegate.cupertinobutton(**props)
61
+ def cupertino_filled_button(**props) = control_delegate.cupertino_filled_button(**props)
62
+ def cupertinofilledbutton(**props) = control_delegate.cupertinofilledbutton(**props)
63
+ def cupertino_text_field(**props) = control_delegate.cupertino_text_field(**props)
64
+ def cupertinotextfield(**props) = control_delegate.cupertinotextfield(**props)
65
+ def cupertino_switch(**props) = control_delegate.cupertino_switch(**props)
66
+ def cupertinoswitch(**props) = control_delegate.cupertinoswitch(**props)
67
+ def cupertino_slider(**props) = control_delegate.cupertino_slider(**props)
68
+ def cupertinoslider(**props) = control_delegate.cupertinoslider(**props)
69
+ def cupertino_alert_dialog(**props) = control_delegate.cupertino_alert_dialog(**props)
70
+ def cupertinoalertdialog(**props) = control_delegate.cupertinoalertdialog(**props)
71
+ def cupertino_action_sheet(**props) = control_delegate.cupertino_action_sheet(**props)
72
+ def cupertinoactionsheet(**props) = control_delegate.cupertinoactionsheet(**props)
73
+ def cupertino_dialog_action(**props) = control_delegate.cupertino_dialog_action(**props)
74
+ def cupertinodialogaction(**props) = control_delegate.cupertinodialogaction(**props)
75
+ def cupertino_navigation_bar(**props) = control_delegate.cupertino_navigation_bar(**props)
76
+ def cupertinonavigationbar(**props) = control_delegate.cupertinonavigationbar(**props)
77
+
78
+ private
79
+
80
+ def control_delegate
81
+ raise NotImplementedError, "control_delegate must be implemented by the including/extended context"
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "control_methods"
4
+ require_relative "control_factory"
5
+
6
+ module Ruflet
7
+ class WidgetBuilder
8
+ include UI::ControlMethods
9
+
10
+ attr_reader :children
11
+
12
+ def initialize
13
+ @children = []
14
+ end
15
+
16
+ def widget(type, **props, &block)
17
+ control(type, **props, &block)
18
+ end
19
+
20
+ def control(type, **props, &block)
21
+ mapped_props = props.dup
22
+ prop_children = mapped_props.delete(:controls) || mapped_props.delete("controls")
23
+
24
+ node = UI::ControlFactory.build(type, **mapped_props)
25
+ if block
26
+ nested = WidgetBuilder.new
27
+ block_result = nested.instance_eval(&block)
28
+ if block_result.is_a?(Control) && !nested.children.any? { |c| c.object_id == block_result.object_id }
29
+ nested.children << block_result
30
+ end
31
+ node.children.concat(nested.children)
32
+ end
33
+
34
+ if prop_children
35
+ Array(prop_children).each do |child|
36
+ node.children << child if child.is_a?(Control)
37
+ end
38
+ end
39
+
40
+ @children << node
41
+ node
42
+ end
43
+
44
+ def build_widget(type, **props, &block) = control(type, **props, &block)
45
+
46
+ private
47
+ end
48
+ end
data/lib/ruflet_ui.rb ADDED
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruflet_protocol"
4
+ require_relative "ruflet_ui/ruflet/colors"
5
+ require_relative "ruflet_ui/ruflet/icon_data"
6
+ require_relative "ruflet_ui/ruflet/icons/material_icons"
7
+ require_relative "ruflet_ui/ruflet/icons/cupertino/cupertino_icons"
8
+ require_relative "ruflet_ui/ruflet/control"
9
+ require_relative "ruflet_ui/ruflet/ui/widget_builder"
10
+ require_relative "ruflet_ui/ruflet/ui/shared_control_forwarders"
11
+ require_relative "ruflet_ui/ruflet/event"
12
+ require_relative "ruflet_ui/ruflet/page"
13
+ require_relative "ruflet_ui/ruflet/app"
14
+ require_relative "ruflet_ui/ruflet/dsl"
15
+
16
+ module Ruflet
17
+ module MainAxisAlignment
18
+ CENTER = "center"
19
+ START = "start"
20
+ FINISH = "end"
21
+ SPACE_BETWEEN = "spaceBetween"
22
+ SPACE_AROUND = "spaceAround"
23
+ SPACE_EVENLY = "spaceEvenly"
24
+ end
25
+
26
+ module CrossAxisAlignment
27
+ CENTER = "center"
28
+ START = "start"
29
+ FINISH = "end"
30
+ STRETCH = "stretch"
31
+ end
32
+
33
+ module TextAlign
34
+ LEFT = "left"
35
+ RIGHT = "right"
36
+ CENTER = "center"
37
+ JUSTIFY = "justify"
38
+ START = "start"
39
+ FINISH = "end"
40
+ end
41
+
42
+ module Icons
43
+ REMOVE = MaterialIcons::REMOVE
44
+ ADD = MaterialIcons::ADD
45
+
46
+ class << self
47
+ def const_missing(name)
48
+ if Ruflet::MaterialIcons.const_defined?(name, false)
49
+ return Ruflet::MaterialIcons.const_get(name)
50
+ end
51
+
52
+ if Ruflet::CupertinoIcons.const_defined?(name, false)
53
+ return Ruflet::CupertinoIcons.const_get(name)
54
+ end
55
+
56
+ super
57
+ end
58
+
59
+ def [](name)
60
+ key = name.to_s.upcase.to_sym
61
+ return Ruflet::MaterialIcons.const_get(key) if Ruflet::MaterialIcons.const_defined?(key, false)
62
+ return Ruflet::CupertinoIcons.const_get(key) if Ruflet::CupertinoIcons.const_defined?(key, false)
63
+
64
+ Ruflet::IconData.new(name.to_s)
65
+ end
66
+ end
67
+ end
68
+
69
+ class << self
70
+ include UI::SharedControlForwarders
71
+
72
+ def app(host: "0.0.0.0", port: 8550, &block)
73
+ DSL.app(host: host, port: port, &block)
74
+ end
75
+
76
+ private
77
+
78
+ def control_delegate
79
+ WidgetBuilder.new
80
+ end
81
+ end
82
+
83
+ module UI
84
+ class << self
85
+ include SharedControlForwarders
86
+
87
+ def app(**opts, &block) = Ruflet.app(**opts, &block)
88
+ def page(**props, &block) = Ruflet::DSL.page(**props, &block)
89
+
90
+ private
91
+
92
+ def control_delegate
93
+ Ruflet::DSL
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ module Kernel
100
+ include Ruflet::UI::SharedControlForwarders
101
+
102
+ private
103
+
104
+ def app(**opts, &block) = Ruflet::DSL.app(**opts, &block)
105
+ def page(**props, &block) = Ruflet::DSL.page(**props, &block)
106
+
107
+ def control_delegate
108
+ Ruflet::DSL
109
+ end
110
+
111
+ private(*Ruflet::UI::SharedControlForwarders.instance_methods(false))
112
+ end