Class: TkScrollWidget

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

Instance Method Summary collapse

Constructor Details

#initialize(widget) ⇒ TkScrollWidget

Returns a new instance of TkScrollWidget.



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
# File 'lib/a-tkcommons.rb', line 1315

def initialize(widget)
  @widget = widget
  @parent = TkWinfo.parent(@widget)
  @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|
    @widget.yview *args
  })
  @widget.yscrollcommand(proc{|first,last| 
    do_yscrollcommand(first,last)
  })
  
  @h_scroll = TkScrollbar.new(@parent,{
    'orient'=>'horizontal'}.update(Arcadia.style('scrollbar'))
  )
  @h_scroll.command(proc{|*args|
    @widget.xview *args
  })
  @widget.xscrollcommand(proc{|first,last| 
    do_xscrollcommand(first,last)
  })
end

Instance Method Details

#add_xscrollcommand(cmd = Proc.new) ⇒ Object



1356
1357
1358
# File 'lib/a-tkcommons.rb', line 1356

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

#add_yscrollcommand(cmd = Proc.new) ⇒ Object



1347
1348
1349
# File 'lib/a-tkcommons.rb', line 1347

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

#destroyObject



1342
1343
1344
1345
# File 'lib/a-tkcommons.rb', line 1342

def destroy
  @h_scroll.destroy
  @v_scroll.destroy
end

#do_xscrollcommand(first, last) ⇒ Object



1360
1361
1362
1363
# File 'lib/a-tkcommons.rb', line 1360

def do_xscrollcommand(first,last)
  @h_scroll.set(first,last)
  @h_scroll_command.call(first,last) if !@h_scroll_command.nil?
end

#do_yscrollcommand(first, last) ⇒ Object



1351
1352
1353
1354
# File 'lib/a-tkcommons.rb', line 1351

def do_yscrollcommand(first,last)
  @v_scroll.set(first,last)
  @v_scroll_command.call(first,last) if !@v_scroll_command.nil?
end

#hideObject



1385
1386
1387
1388
1389
# File 'lib/a-tkcommons.rb', line 1385

def hide
  @widget.unplace
  @v_scroll.unpack
  @h_scroll.unpack
end

#hide_h_scrollObject



1409
1410
1411
1412
1413
# File 'lib/a-tkcommons.rb', line 1409

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

#hide_v_scrollObject



1403
1404
1405
1406
1407
# File 'lib/a-tkcommons.rb', line 1403

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

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



1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
# File 'lib/a-tkcommons.rb', line 1365

def show(_x=0,_y=0,_border_mode='outside')
  @x=_x
  @y=_y
  @widget.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



1397
1398
1399
1400
1401
# File 'lib/a-tkcommons.rb', line 1397

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

#show_v_scrollObject



1391
1392
1393
1394
1395
# File 'lib/a-tkcommons.rb', line 1391

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