Class: Ruflet::WidgetBuilder

Inherits:
Object
  • Object
show all
Includes:
UI::ControlMethods
Defined in:
lib/ruflet_ui/ruflet/ui/widget_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UI::CupertinoControlMethods

#cupertino_action_sheet, #cupertino_alert_dialog, #cupertino_button, #cupertino_dialog_action, #cupertino_filled_button, #cupertino_navigation_bar, #cupertino_slider, #cupertino_switch, #cupertino_text_field, #cupertinoactionsheet, #cupertinoalertdialog, #cupertinobutton, #cupertinodialogaction, #cupertinofilledbutton, #cupertinonavigationbar, #cupertinoslider, #cupertinoswitch, #cupertinotextfield

Methods included from UI::MaterialControlMethods

#alert_dialog, #alertdialog, #app_bar, #appbar, #bar_chart, #bar_chart_group, #bar_chart_rod, #bar_chart_rod_stack_item, #barchart, #barchartgroup, #barchartrod, #barchartrodstackitem, #bottom_sheet, #bottomsheet, #button, #candlestick_chart, #candlestick_chart_spot, #candlestickchart, #candlestickchartspot, #center, #chart_axis, #chart_axis_label, #chartaxis, #chartaxislabel, #checkbox, #clipboard, #column, #container, #drag_target, #draggable, #dragtarget, #elevated_button, #fab, #filled_button, #filledbutton, #floating_action_button, #floatingactionbutton, #gesture_detector, #gesturedetector, #grid_view, #gridview, #icon, #icon_button, #iconbutton, #image, #line_chart, #line_chart_data, #line_chart_data_point, #linechart, #linechartdata, #linechartdatapoint, #markdown, #navigation_bar, #navigation_bar_destination, #navigationbar, #navigationbardestination, #pie_chart, #pie_chart_section, #piechart, #piechartsection, #radar_chart, #radar_chart_title, #radar_data_set, #radar_data_set_entry, #radarchart, #radarcharttitle, #radardataset, #radardatasetentry, #radio, #radio_group, #radiogroup, #row, #scatter_chart, #scatter_chart_spot, #scatterchart, #scatterchartspot, #snack_bar, #snackbar, #stack, #tab, #tab_bar, #tab_bar_view, #tabbar, #tabbarview, #tabs, #text, #text_button, #text_field, #textbutton, #textfield, #url_launcher, #view, #web_view, #webview

Constructor Details

#initializeWidgetBuilder

Returns a new instance of WidgetBuilder.



12
13
14
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 12

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 10

def children
  @children
end

Instance Method Details

#build_service(type, **props, &block) ⇒ Object



49
50
51
52
53
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 49

def build_service(type, **props, &block)
  mapped_props = props.dup
  node = UI::ControlFactory.build(type, **mapped_props)
  node
end

#build_widget(type, **props, &block) ⇒ Object



48
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 48

def build_widget(type, **props, &block) = control(type, **props, &block)

#control(type, **props, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 24

def control(type, **props, &block)
  mapped_props = props.dup
  prop_children = extract_children_prop(mapped_props)

  node = UI::ControlFactory.build(type, **mapped_props)
  if block
    nested = WidgetBuilder.new
    block_result = nested.instance_eval(&block)
    if block_result.is_a?(Control) && !nested.children.any? { |c| c.object_id == block_result.object_id }
      nested.children << block_result
    end
    node.children.concat(nested.children)
  end

  if prop_children
    Array(prop_children).each do |child|
      node.children << child if child.is_a?(Control)
    end
  end

  @children << node
  node
end

#service(type, **props, &block) ⇒ Object



20
21
22
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 20

def service(type, **props, &block)
  build_service(type, **props, &block)
end

#widget(type, **props, &block) ⇒ Object



16
17
18
# File 'lib/ruflet_ui/ruflet/ui/widget_builder.rb', line 16

def widget(type, **props, &block)
  control(type, **props, &block)
end