Class: TkScrollText

Inherits:
TkText
  • Object
show all
Defined in:
lib/a-tkcommons.rb

Direct Known Subclasses

TkTextListBox

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, keys = {}) ⇒ TkScrollText

Returns a new instance of TkScrollText.



1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/a-tkcommons.rb', line 1226

def initialize(parent=nil, keys={})
  super(parent, keys)
  @scroll_width = 15
  @v_scroll_on = false
  @h_scroll_on = false
  @v_scroll = TkScrollbar.new(parent,{
    'orient'=>'vertical'}.update(Arcadia.style('scrollbar'))
  )
  @v_scroll.command(proc{|*args|
    self.yview *args
  })
  self.yscrollcommand(proc{|first,last| 
    self.do_yscrollcommand(first,last)
  })
  
  @h_scroll = TkScrollbar.new(parent,{
    'orient'=>'horizontal'}.update(Arcadia.style('scrollbar'))
  )
  @h_scroll.command(proc{|*args|
    self.xview *args
  })
  self.xscrollcommand(proc{|first,last| 
    self.do_xscrollcommand(first,last)
  })
end

Instance Method Details

#add_xscrollcommand(cmd = Proc.new) ⇒ Object



1259
1260
1261
# File 'lib/a-tkcommons.rb', line 1259

def add_xscrollcommand(cmd=Proc.new)
  @h_scroll_command = cmd
end

#add_yscrollcommand(cmd = Proc.new) ⇒ Object



1251
1252
1253
# File 'lib/a-tkcommons.rb', line 1251

def add_yscrollcommand(cmd=Proc.new)
  @v_scroll_command = cmd
end

#do_xscrollcommand(first, last) ⇒ Object



1262
1263
1264
1265
1266
# File 'lib/a-tkcommons.rb', line 1262

def do_xscrollcommand(first,last)
  #p "do_xscrollcommand first=#{first} last=#{last}"
  @h_scroll.set(first,last)
  @h_scroll_command.call(first,last) if !@h_scroll_command.nil?
end

#do_yscrollcommand(first, last) ⇒ Object



1254
1255
1256
1257
1258
# File 'lib/a-tkcommons.rb', line 1254

def do_yscrollcommand(first,last)
  #p "do_yscrollcommand first=#{first} last=#{last}"
  @v_scroll.set(first,last)
  @v_scroll_command.call(first,last) if !@v_scroll_command.nil?
end

#hide_h_scrollObject



1306
1307
1308
1309
1310
# File 'lib/a-tkcommons.rb', line 1306

def hide_h_scroll
  self.place('height' => 0)
  @h_scroll.unpack
  @h_scroll_on = false  
end

#hide_v_scrollObject



1300
1301
1302
1303
1304
# File 'lib/a-tkcommons.rb', line 1300

def hide_v_scroll
  self.place('width' => 0)
  @v_scroll.unpack
  @v_scroll_on = false
end

#show(_x = 0, _y = 0, _border_mode = 'outside') ⇒ Object



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
# File 'lib/a-tkcommons.rb', line 1268

def show(_x=0,_y=0,_border_mode='outside')
  @x=_x
  @y=_y
  place(
    'x'=>@x,
    'y'=>@y,
    'width' => -@x,
    'height' => -@y,
    'relheight'=>1,
    'relwidth'=>1,
    'bordermode'=>_border_mode
 )
 if @v_scroll_on
   show_v_scroll
 end
 if @h_scroll_on
   show_h_scroll
 end
end

#show_h_scrollObject



1294
1295
1296
1297
1298
# File 'lib/a-tkcommons.rb', line 1294

def show_h_scroll
  self.place('height' => -@scroll_width-@y)
  @h_scroll.pack('side' => 'bottom', 'fill' => 'x')
  @h_scroll_on = true
end

#show_v_scrollObject



1288
1289
1290
1291
1292
# File 'lib/a-tkcommons.rb', line 1288

def show_v_scroll
  self.place('width' => -@scroll_width-@x)
  @v_scroll.pack('side' => 'right', 'fill' => 'y')
  @v_scroll_on = true
end