Class: Glimmer::SWT::GridLayoutProxy

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

Constant Summary collapse

STYLE =
<<~CSS
  .grid-layout {
    display: grid;
    grid-template-rows: min-content;
    place-content: start;
    align-items: stretch;
  }
CSS

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.



17
18
19
20
21
22
23
24
25
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 17

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

Instance Attribute Details

#horizontal_spacingObject

Returns the value of attribute horizontal_spacing.



15
16
17
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 15

def horizontal_spacing
  @horizontal_spacing
end

#make_columns_equal_widthObject

Returns the value of attribute make_columns_equal_width.



15
16
17
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 15

def make_columns_equal_width
  @make_columns_equal_width
end

#margin_heightObject

Returns the value of attribute margin_height.



15
16
17
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 15

def margin_height
  @margin_height
end

#margin_widthObject

Returns the value of attribute margin_width.



15
16
17
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 15

def margin_width
  @margin_width
end

#num_columnsObject

Returns the value of attribute num_columns.



15
16
17
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 15

def num_columns
  @num_columns
end

#vertical_spacingObject

Returns the value of attribute vertical_spacing.



15
16
17
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 15

def vertical_spacing
  @vertical_spacing
end

Instance Method Details

#reapplyObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/glimmer/swt/grid_layout_proxy.rb', line 69

def reapply
  # TODO get rid of this method
  layout_css = <<~CSS
    grid-template-columns: #{'auto ' * @num_columns.to_i};
    grid-row-gap: #{@vertical_spacing}px;
    grid-column-gap: #{@horizontal_spacing}px;
  CSS
  if @parent.css_classes.include?('grid-layout')
    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
    if @parent.is_a?(GroupProxy)
      @parent.dom_element.find('legend').css('grid-column-start', "span #{@num_columns.to_i}")
    end
  else
    layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
      @parent.dom_element.css(key, 'initial') unless key.nil?
    end
  end
end