Class: TkScrollWidget

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

Instance Method Summary collapse

Constructor Details

#initialize(widget) ⇒ TkScrollWidget



1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
# File 'lib/a-tkcommons.rb', line 1270

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



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

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

#add_yscrollcommand(cmd = Proc.new) ⇒ Object



1297
1298
1299
# File 'lib/a-tkcommons.rb', line 1297

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

#do_xscrollcommand(first, last) ⇒ Object



1310
1311
1312
1313
# File 'lib/a-tkcommons.rb', line 1310

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



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

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

#hideObject



1335
1336
1337
1338
1339
# File 'lib/a-tkcommons.rb', line 1335

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

#hide_h_scrollObject



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

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

#hide_v_scrollObject



1353
1354
1355
1356
1357
# File 'lib/a-tkcommons.rb', line 1353

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



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

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



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

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



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

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