Class: Interphase::Layout

Inherits:
Grid show all
Defined in:
lib/interphase/widgets/layout.rb

Overview

A high-level widget which is described using a layout description string, abbreviated to LDS. The LDS specifies a grid in which there are a fixed number of widgets occupying a fixed space.

Instance Attribute Summary collapse

Attributes inherited from Container

#children

Attributes inherited from Widget

#gtk_instance, #name, #parent

Instance Method Summary collapse

Methods inherited from Grid

#add, #columns, #rows

Methods inherited from Container

#add, #method_missing, #respond_to_missing?, #show_all

Methods inherited from Widget

#destroy, #method_missing, #on, #respond_to_missing?, #show, #size

Constructor Details

#initialize(lds, **options, &block) ⇒ Layout

Create a new layout.

lds

The LDS to create the grid from.


14
15
16
17
18
19
20
21
22
# File 'lib/interphase/widgets/layout.rb', line 14

def initialize(lds, **options, &block)
  @lds = lds
  parser = Helpers::LayoutParser.new(lds)

  @description = parser.parse
  @set_slot_names = []

  super(parser.rows, parser.columns, **options, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Interphase::Container

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description


10
11
12
# File 'lib/interphase/widgets/layout.rb', line 10

def description
  @description
end

#ldsObject (readonly)

Returns the value of attribute lds


10
11
12
# File 'lib/interphase/widgets/layout.rb', line 10

def lds
  @lds
end

Instance Method Details

#[]=(name, widget) ⇒ Object

Set the widget contained within a slot. This may only be done once per slot.

slot

The name of the slot.

widget

The widget to put in the slot.


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/interphase/widgets/layout.rb', line 28

def []=(name, widget)
  raise "Already set a widget for slot named #{name}" \
    if @set_slot_names.include? name

  raise "No slot named #{name}" unless @description.widgets.include? name

  @set_slot_names << name
  slot_description = @description.widgets[name]
  
  add(
    widget,
    slot_description.left,
    slot_description.right,
    slot_description.top,
    slot_description.bottom
  )
end