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.



1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/a-tkcommons.rb', line 1181

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



1214
1215
1216
# File 'lib/a-tkcommons.rb', line 1214

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

#add_yscrollcommand(cmd = Proc.new) ⇒ Object



1206
1207
1208
# File 'lib/a-tkcommons.rb', line 1206

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

#do_xscrollcommand(first, last) ⇒ Object



1217
1218
1219
1220
1221
# File 'lib/a-tkcommons.rb', line 1217

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



1209
1210
1211
1212
1213
# File 'lib/a-tkcommons.rb', line 1209

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



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

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

#hide_v_scrollObject



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

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



1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
# File 'lib/a-tkcommons.rb', line 1223

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



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

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



1243
1244
1245
1246
1247
# File 'lib/a-tkcommons.rb', line 1243

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