class Sirens::AbstractView
A View is the library binding to a GUI interface handle. It is not a Component
but is wrapped by a Component
. 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 Component
that wraps it makes the Component
responsibilities more consistent with regular Components and it makes it easier to switch between GUI libraries (say, from Gtk to Qt).
Public Class Methods
Answer the styles accepted by this view.
# File lib/views/abstract_view.rb, line 22 def accepted_styles() @accepted_styles ||= Set.new(view_accepted_styles) end
Initializes this View handles
# File lib/views/abstract_view.rb, line 39 def initialize() super() @child_views = [] @attributes = Hash[] end
Answer the styles accepted by this view.
# File lib/views/abstract_view.rb, line 29 def view_accepted_styles() [ :width, :height, :background_color, :foreground_color ].freeze end
Public Instance Methods
Answer the styles accepted by this view.
# File lib/views/abstract_view.rb, line 70 def accepted_styles() self.class.accepted_styles end
Adds a child_view.
# File lib/views/abstract_view.rb, line 142 def add_view(child_view) @child_views << child_view end
Accessing
# File lib/views/abstract_view.rb, line 48 def attribute_at(key) @attributes[key] end
# File lib/views/abstract_view.rb, line 92 def background_color=(value) state_colors_from(value).each_pair do |state, value| next if value.nil? main_handle.override_background_color( state, Gdk::RGBA.parse(value) ) end end
# File lib/views/abstract_view.rb, line 100 def foreground_color=(value, state: :normal) state_colors_from(value).each_pair do |state, value| next if value.nil? main_handle.override_color( state, Gdk::RGBA.parse(value) ) end end
# File lib/views/abstract_view.rb, line 88 def height() main_handle.height_request end
# File lib/views/abstract_view.rb, line 84 def height=(value) main_handle.height_request = value end
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.
# File lib/views/abstract_view.rb, line 61 def main_handle() raise RuntimeError.new("Subclass #{self.class.name} must implement the method ::initialize_handles().") end
Removes a child view.
# File lib/views/abstract_view.rb, line 149 def remove_view(child_view) @child_views.delete(child_view) main_handle.remove(child_view.main_handle) end
# File lib/views/abstract_view.rb, line 52 def set_attribute(key, value) @attributes[key] = value end
Makes this component visible.
# File lib/views/abstract_view.rb, line 133 def show() main_handle.show_all end
# File lib/views/abstract_view.rb, line 108 def state_colors_from(value) colors = Hash[ normal: nil, active: nil, prelight: nil, selected: nil, insensitive: nil, ] if value.kind_of?(Hash) value.each_pair do |state, value| colors[state] = value end else colors[:normal] = value end colors end
# File lib/views/abstract_view.rb, line 80 def width() main_handle.width_request end
Styles
# File lib/views/abstract_view.rb, line 76 def width=(value) main_handle.width_request = value end