Class: VER::PanedLayout
- Inherits:
-
Tk::Tile::LabelFrame
- Object
- Tk::Tile::LabelFrame
- VER::PanedLayout
- Defined in:
- lib/ver/layout/paned.rb
Overview
A Layout containing frames in a master and slave pane.
Constant Summary collapse
- OPTIONS =
default options
{masters: 1, slaves: 3, center: 0.5}
Instance Attribute Summary collapse
-
#frames ⇒ Object
readonly
contains the frames in the order they are displayed.
-
#layout_pane ⇒ Object
readonly
contains the master and slave pane.
-
#master_pane ⇒ Object
readonly
contains master frames.
-
#options ⇒ Object
readonly
options specific for the paned layout.
-
#slave_pane ⇒ Object
readonly
contains slave frames.
Instance Method Summary collapse
-
#add_buffer(buffer) ⇒ Object
Add the given
buffer
.frame to the #frames, apply, and focusbuffer
. - #apply ⇒ Object
-
#close_buffer(buffer) ⇒ Object
Forget and destroy the given
buffer
. -
#create_buffer(options = {}) {|buffer| ... } ⇒ Object
Create a new Buffer inside the PanedLayout,
options
are passed to Buffer.new. - #cycle_next(frame) ⇒ Object
- #cycle_prev(frame) ⇒ Object
- #focus_next(frame) ⇒ Object
- #focus_prev(frame) ⇒ Object
-
#forget_buffer(buffer) ⇒ Object
Remove given
buffer
from #frames and apply. - #hide(frame) ⇒ Object
-
#initialize(parent, options = {}) ⇒ PanedLayout
constructor
Create a new PanedLayout for given
parent
andoptions
. - #masters_slaves ⇒ Object
- #push_bottom(frame) ⇒ Object
- #push_down(frame) ⇒ Object
- #push_top(frame) ⇒ Object
- #push_up(frame) ⇒ Object
- #show(frame) ⇒ Object
- #visible ⇒ Object
- #visible?(frame) ⇒ Boolean
Constructor Details
#initialize(parent, options = {}) ⇒ PanedLayout
Create a new PanedLayout for given parent
and options
. The options
may contain :masters and :slaves, which will be merged with the default [OPTIONS].
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ver/layout/paned.rb', line 25 def initialize(parent, = {}) @options = OPTIONS.dup @options[:masters] = .delete(:masters) if .key?(:masters) @options[:slaves] = .delete(:slaves) if .key?(:slaves) super pack(fill: :both, expand: true) @frames = [] @layout_pane = Tk::Tile::PanedWindow.new(self, orient: :horizontal) @master_pane = Tk::Tile::PanedWindow.new(@layout_pane, orient: :vertical) @slave_pane = Tk::Tile::PanedWindow.new(@layout_pane, orient: :vertical) @layout_pane.pack fill: :both, expand: true @layout_pane.add(@master_pane, weight: 1) @layout_pane.add(@slave_pane, weight: 1) @layout_pane.bind('<Map>'){ apply } end |
Instance Attribute Details
#frames ⇒ Object (readonly)
contains the frames in the order they are displayed
5 6 7 |
# File 'lib/ver/layout/paned.rb', line 5 def frames @frames end |
#layout_pane ⇒ Object (readonly)
contains the master and slave pane
8 9 10 |
# File 'lib/ver/layout/paned.rb', line 8 def layout_pane @layout_pane end |
#master_pane ⇒ Object (readonly)
contains master frames
11 12 13 |
# File 'lib/ver/layout/paned.rb', line 11 def master_pane @master_pane end |
#options ⇒ Object (readonly)
options specific for the paned layout
17 18 19 |
# File 'lib/ver/layout/paned.rb', line 17 def @options end |
#slave_pane ⇒ Object (readonly)
contains slave frames
14 15 16 |
# File 'lib/ver/layout/paned.rb', line 14 def slave_pane @slave_pane end |
Instance Method Details
#add_buffer(buffer) ⇒ Object
Add the given buffer
.frame to the #frames, apply, and focus buffer
.
47 48 49 50 51 |
# File 'lib/ver/layout/paned.rb', line 47 def add_buffer(buffer) frames.unshift(buffer.frame) apply buffer.focus end |
#apply ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ver/layout/paned.rb', line 85 def apply masters, slaves = masters_slaves (master_pane.panes - masters.map{|bff| bff.tk_pathname }).each do |bff| master_pane.forget(bff) end (slave_pane.panes - slaves.map{|bff| bff.tk_pathname }).each do |bff| slave_pane.forget(bff) end masters.each{|bff| master_pane.insert(:end, bff, weight: 1) } slaves.each{|bff| slave_pane.insert(:end, bff, weight: 1) } if slaves.empty? layout_pane.forget(slave_pane) rescue nil else layout_pane.add(slave_pane, weight: 1) rescue nil width = layout_pane.winfo_width center = (width * [:center]).to_i # layout_pane.sashpos(0, center) end end |
#close_buffer(buffer) ⇒ Object
Forget and destroy the given buffer
.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ver/layout/paned.rb', line 74 def close_buffer(buffer) forget_buffer(buffer) buffer.frame.destroy if previous = visible.first previous.focus else Methods::Save.quit(nil) end end |
#create_buffer(options = {}) {|buffer| ... } ⇒ Object
Create a new Buffer inside the VER::PanedLayout, options
are passed to Buffer.new. The new Buffer will be at top of the #frames.
64 65 66 67 68 69 |
# File 'lib/ver/layout/paned.rb', line 64 def create_buffer( = {}) buffer = Buffer.new(self, ) yield buffer add_buffer(buffer) buffer end |
#cycle_next(frame) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/ver/layout/paned.rb', line 182 def cycle_next(frame) return unless index = frames.index(frame) frames.push(frames.shift) apply frames[index].focus end |
#cycle_prev(frame) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/ver/layout/paned.rb', line 189 def cycle_prev(frame) return unless index = frames.index(frame) frames.unshift(frames.pop) apply frames[index].focus end |
#focus_next(frame) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/ver/layout/paned.rb', line 137 def focus_next(frame) return unless index = visible.index(frame) found = visible[index + 1] || visible[0] found.focus end |
#focus_prev(frame) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/ver/layout/paned.rb', line 144 def focus_prev(frame) return unless index = visible.index(frame) found = visible[index - 1] found.focus end |
#forget_buffer(buffer) ⇒ Object
Remove given buffer
from #frames and apply.
54 55 56 57 |
# File 'lib/ver/layout/paned.rb', line 54 def forget_buffer(buffer) frames.delete(buffer.frame) apply end |
#hide(frame) ⇒ Object
132 133 134 135 |
# File 'lib/ver/layout/paned.rb', line 132 def hide(frame) frame.shown = false apply end |
#masters_slaves ⇒ Object
111 112 113 114 115 116 |
# File 'lib/ver/layout/paned.rb', line 111 def masters_slaves masters_max, slaves_max = .values_at(:masters, :slaves) frames.compact! possible = frames.select(&:shown?) return [*possible[0, masters_max]], [*possible[masters_max, slaves_max]] end |
#push_bottom(frame) ⇒ Object
176 177 178 179 180 |
# File 'lib/ver/layout/paned.rb', line 176 def push_bottom(frame) frames.push(frames.delete(frame)) apply frames.last.focus unless visible?(frame) end |
#push_down(frame) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/ver/layout/paned.rb', line 161 def push_down(frame) return unless index = frames.index(frame) following = frames[index + 1] || frames[0] frame.raise(following) frames[frames.index(following)], frames[index] = frame, following apply following.focus unless visible?(frame) end |
#push_top(frame) ⇒ Object
171 172 173 174 |
# File 'lib/ver/layout/paned.rb', line 171 def push_top(frame) frames.unshift(frames.delete(frame)) apply end |
#push_up(frame) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/ver/layout/paned.rb', line 151 def push_up(frame) return unless index = frames.index(frame) previous = frames[index - 1] frame.raise(previous) frames[index - 1], frames[index] = frame, previous apply previous.focus unless visible?(frame) end |
#show(frame) ⇒ Object
126 127 128 129 130 |
# File 'lib/ver/layout/paned.rb', line 126 def show(frame) frame.shown = true push_up(frame) until visible?(frame) frame.focus end |
#visible ⇒ Object
122 123 124 |
# File 'lib/ver/layout/paned.rb', line 122 def visible masters_slaves.flatten end |
#visible?(frame) ⇒ Boolean
118 119 120 |
# File 'lib/ver/layout/paned.rb', line 118 def visible?(frame) visible.index(frame) end |