Class: Glimmer::SWT::GridLayoutProxy

Inherits:
LayoutProxy show all
Defined in:
lib/glimmer/swt/grid_layout_proxy.rb

Instance Attribute Summary collapse

Attributes inherited from LayoutProxy

#args, #parent

Instance Method Summary collapse

Methods inherited from LayoutProxy

#css_class, #dom, for, layout_class, layout_exists?

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Constructor Details

#initialize(parent, args) ⇒ GridLayoutProxy

Returns a new instance of GridLayoutProxy.



8
9
10
11
12
13
14
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 8

def initialize(parent, args)
  super(parent, args)
  self.horizontal_spacing = 10
  self.vertical_spacing = 10
  self.num_columns = @args.first || 1        
  reapply
end

Instance Attribute Details

#horizontal_spacingObject

Returns the value of attribute horizontal_spacing.



6
7
8
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 6

def horizontal_spacing
  @horizontal_spacing
end

#make_columns_equal_widthObject

Returns the value of attribute make_columns_equal_width.



6
7
8
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 6

def make_columns_equal_width
  @make_columns_equal_width
end

#margin_heightObject

Returns the value of attribute margin_height.



6
7
8
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 6

def margin_height
  @margin_height
end

#margin_widthObject

Returns the value of attribute margin_width.



6
7
8
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 6

def margin_width
  @margin_width
end

#num_columnsObject

Returns the value of attribute num_columns.



6
7
8
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 6

def num_columns
  @num_columns
end

#vertical_spacingObject

Returns the value of attribute vertical_spacing.



6
7
8
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 6

def vertical_spacing
  @vertical_spacing
end

Instance Method Details

#reapplyObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 54

def reapply
  layout_css = <<~CSS
    display: grid;
    grid-template-columns: #{'auto ' * @num_columns.to_i};
    grid-template-rows: min-content;
    grid-row-gap: #{@vertical_spacing}px;
    grid-column-gap: #{@horizontal_spacing}px;
    justify-content: start;
    place-content: start;
    align-items: stretch;
  CSS
  layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|          
    @parent.dom_element.css(key, value) unless key.nil?
  end      
end