Class: Split
Overview
—————————————————————————– #
File: SplitLayout.rb
Description:
Author: j kepler http://github.com/mare-imbrium/canis/
Date: 2014-05-10 - 13:48
License: MIT
Last update: 2014-05-10 20:19
—————————————————————————– #
SplitLayout.rb Copyright (C) 2012-2014 j kepler
----
This layout allows for complex arrangements of stacks and flows. One can divide the layout
into splits (vertical or horizontal) and keep dividing a split, or placing a component in it.
However, to keep it simple and reduce the testing, I am insisting that a weightage be specified
with a split.
layout = SplitLayout.new :height => -1, :top_margin => 1, :bottom_margin => 1, :left_margin => 1
x, y = layout.vsplit( 0.30, 0.70)
x.component = mylist
y1, y2 = y.split( 0.40, 0.60 )
y2.component = mytable
y11,y12,y13 = y1.vsplit( 0.3, 0.3, 0.4)
y11 = list1
y12 = list2
y13 = list3
Or hopefully:
layout.split(0.3, 0.7) do |x,y|
x.component = mylist
y.split(0.4, 0.6) do |a,b|
b.component = mytable
a.vsplit( 0.3, 0.3, 0.4) do | p,q,r |
p.component = list1
end
end
end
Instance Attribute Summary collapse
-
#component ⇒ Object
Returns the value of attribute component.
-
#height ⇒ Object
Returns the value of attribute height.
-
#left ⇒ Object
Returns the value of attribute left.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
link to parent own weight.
-
#split_wts ⇒ Object
weights of child splits, given in cons.
-
#splits ⇒ Object
readonly
Returns the value of attribute splits.
-
#top ⇒ Object
Returns the value of attribute top.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#weight ⇒ Object
link to parent own weight.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #_split(type, args, &block) ⇒ Object
-
#initialize(type, weight, parent) ⇒ Split
constructor
A new instance of Split.
- #split(*args, &block) ⇒ Object
- #vsplit(*args, &block) ⇒ Object
Constructor Details
#initialize(type, weight, parent) ⇒ Split
Returns a new instance of Split.
52 53 54 55 56 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 52 def initialize type, weight, parent @type = type @weight = weight @parent = parent end |
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component.
41 42 43 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 41 def component @component end |
#height ⇒ Object
Returns the value of attribute height.
44 45 46 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 44 def height @height end |
#left ⇒ Object
Returns the value of attribute left.
44 45 46 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 44 def left @left end |
#name ⇒ Object
Returns the value of attribute name.
42 43 44 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 42 def name @name end |
#parent ⇒ Object
link to parent own weight
47 48 49 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 47 def parent @parent end |
#split_wts ⇒ Object
weights of child splits, given in cons
49 50 51 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 49 def split_wts @split_wts end |
#splits ⇒ Object (readonly)
Returns the value of attribute splits.
43 44 45 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 43 def splits @splits end |
#top ⇒ Object
Returns the value of attribute top.
44 45 46 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 44 def top @top end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
50 51 52 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 50 def type @type end |
#weight ⇒ Object
link to parent own weight
47 48 49 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 47 def weight @weight end |
#width ⇒ Object
Returns the value of attribute width.
44 45 46 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 44 def width @width end |
Instance Method Details
#_split(type, args, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 57 def _split type, args, &block @split_wts = args @splits = [] args.each do |e| @splits << Split.new(type, e, self) end if block_given? yield @splits.flatten else return @splits.flatten end end |
#split(*args, &block) ⇒ Object
69 70 71 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 69 def split *args, &block _split :h, args, &block end |
#vsplit(*args, &block) ⇒ Object
72 73 74 |
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 72 def vsplit *args, &block _split :v, args, &block end |