Class: Sirens::WidgetView
- Inherits:
-
AbstractView
- Object
- AbstractView
- Sirens::WidgetView
- Defined in:
- lib/views/widget_view.rb
Overview
A View is the library binding to a GUI interface handle. It is not a Component but is wrapped by a PrimitiveComponent. a View takes care of handling the internals of the GUI objects such as handles, events, default initialization, etc.
By separating the View from the PrimitiveComponent that wraps it makes the PrimitiveComponents responsibilities more consistent with regular Components and it makes it easier to switch between GUI libraries (say, from Gtk to Qt).
Direct Known Subclasses
ButtonView, CheckboxView, InputTextView, ListView, MenuView, RadioButtonView, SplitterView, StackView, TabsView, TextView, TreeView, WindowView
Instance Method Summary collapse
-
#add_view(child_view) ⇒ Object
Adds a child_view.
-
#apply_prop(prop, value) ⇒ Object
Apply the prop to the actual GUI object.
-
#apply_props(props) ⇒ Object
Applies each prop in props to the actual GUI object.
-
#initialize ⇒ WidgetView
constructor
Initializes this View handles.
-
#initialize_handles ⇒ Object
Instantiates this view handles.
-
#main_handle ⇒ Object
Returns the main handle of this View.
-
#subscribe_to_ui_events ⇒ Object
Subscribes this View to the events/signals emitted by the GUI handle(s) of interest.
Methods inherited from AbstractView
accepted_styles, #accepted_styles, #attribute_at, #background_color=, #foreground_color=, #height, #height=, #populate_popup_menu_block=, #remove_view, #set_attribute, #show, #show_popup_menu, #state_colors_from, view_accepted_styles, #width, #width=
Constructor Details
#initialize ⇒ WidgetView
Initializes this View handles
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/views/widget_view.rb', line 21 def initialize() super() @event_handles = Hash[] @main_handle = nil initialize_handles subscribe_to_ui_events end |
Instance Method Details
#add_view(child_view) ⇒ Object
Adds a child_view.
90 91 92 93 94 |
# File 'lib/views/widget_view.rb', line 90 def add_view(child_view) super(child_view) main_handle.add(child_view.main_handle) end |
#apply_prop(prop, value) ⇒ Object
Apply the prop to the actual GUI object.
81 82 83 84 85 |
# File 'lib/views/widget_view.rb', line 81 def apply_prop(prop, value) setter = prop.to_s + '=' send(setter, value) end |
#apply_props(props) ⇒ Object
Applies each prop in props to the actual GUI object.
70 71 72 73 74 75 76 |
# File 'lib/views/widget_view.rb', line 70 def apply_props(props) accepted_styles = self.accepted_styles props.each_pair { |prop, value| apply_prop(prop, value) if accepted_styles.include?(prop) } end |
#initialize_handles ⇒ Object
Instantiates this view handles. A View usually has a single handle to the GUI library, but in same cases it may have more than one. For instance when adding a Scroll decorator to the actual widget.
37 38 39 |
# File 'lib/views/widget_view.rb', line 37 def initialize_handles() raise RuntimeError.new("Subclass #{self.class.name} must implement the method ::initialize_handles().") end |
#main_handle ⇒ Object
Returns the main handle of this View. The main handle is the one that this View parent add as its child. Also, it is the handle that receives the style props and events by default.
61 62 63 |
# File 'lib/views/widget_view.rb', line 61 def main_handle() @main_handle end |
#subscribe_to_ui_events ⇒ Object
Subscribes this View to the events/signals emitted by the GUI handle(s) of interest. When an event/signal is received calls the proper event_handler provided by the PrimitiveComponent, if one was given.
This mechanism of event handler callbacks is more simple and lightweight than making this View to announce events using the Observer pattern, and since there is only one PrimitiveComponent wrapping each View using the Observer pattern would be unnecessary complex.
50 51 52 |
# File 'lib/views/widget_view.rb', line 50 def subscribe_to_ui_events() raise RuntimeError.new("Subclass #{self.class.name} must implement the method ::subscribe_to_ui_events().") end |