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

accepted_styles() click to toggle source

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
new() click to toggle source

Initializes this View handles

Calls superclass method
# File lib/views/abstract_view.rb, line 39
def initialize()
    super()

    @child_views = []
    @attributes = Hash[]
end
view_accepted_styles() click to toggle source

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

accepted_styles() click to toggle source

Answer the styles accepted by this view.

# File lib/views/abstract_view.rb, line 70
def accepted_styles()
    self.class.accepted_styles
end
add_view(child_view) click to toggle source

Adds a child_view.

# File lib/views/abstract_view.rb, line 142
def add_view(child_view)
    @child_views << child_view
end
attribute_at(key) click to toggle source

Accessing

# File lib/views/abstract_view.rb, line 48
def attribute_at(key)
    @attributes[key]
end
background_color=(value) click to toggle source
# 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
foreground_color=(value, state: :normal) click to toggle source
# 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
height() click to toggle source
# File lib/views/abstract_view.rb, line 88
def height()
    main_handle.height_request
end
height=(value) click to toggle source
# File lib/views/abstract_view.rb, line 84
def height=(value)
    main_handle.height_request = value
end
main_handle() click to toggle source

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
populate_popup_menu_block=(populate_popup_menu_block) click to toggle source

Popup menu

# File lib/views/abstract_view.rb, line 157
def populate_popup_menu_block=(populate_popup_menu_block)
    @populate_popup_menu_block = populate_popup_menu_block
end
remove_view(child_view) click to toggle source

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
set_attribute(key, value) click to toggle source
# File lib/views/abstract_view.rb, line 52
def set_attribute(key, value)
    @attributes[key] = value
end
show() click to toggle source

Makes this component visible.

# File lib/views/abstract_view.rb, line 133
def show()
    main_handle.show_all
end
show_popup_menu(props) click to toggle source

Create and show a popup menu

# File lib/views/abstract_view.rb, line 164
def show_popup_menu(props)
    menu = MenuView.new

    @populate_popup_menu_block.call(menu: menu)

    menu.open(props) unless menu.empty?
end
state_colors_from(value) click to toggle source
# 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
width() click to toggle source
# File lib/views/abstract_view.rb, line 80
def width()
    main_handle.width_request
end
width=(value) click to toggle source

Styles

# File lib/views/abstract_view.rb, line 76
def width=(value)
    main_handle.width_request = value
end