class ListboxDemo

# Copyright © 2016 Ruby-GNOME2 Project Team # This program is licenced under the same licence as Ruby-GNOME2. #

List Box

GtkListBox allows lists with complicated layouts, using
regular widgets supporting sorting and filtering.

Public Class Methods

new(main_window) click to toggle source
# File gtk3/sample/gtk-demo/listbox.rb, line 12
def initialize(main_window)
  @window = Gtk::Window.new(:toplevel)
  @window.screen = main_window.screen
  @window.title = "List Box"
  @window.set_default_size(400, 600)

  vbox = Gtk::Box.new(:vertical, 12)
  @window.add(vbox)
  label = Gtk::Label.new("Messages from Gtk+ and friends")
  vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
  scrolled = Gtk::ScrolledWindow.new
  scrolled.set_policy(:never, :automatic)
  vbox.pack_start(scrolled, :expand => true, :fill => true, :padding => 0)

  listbox = Gtk::ListBox.new
  scrolled.add(listbox)

  listbox.set_sort_func do |a, b|
    a.sort(b)
  end
  listbox.activate_on_single_click = false
  listbox.signal_connect("row-activated", &:row_activated)
  vbox.show_all

  data = Gio::Resources.lookup_data("/listbox/messages.txt", 0)
  data.to_s.each_line do |line|
    message = Message.new(line)
    row = GtkMessageRow.new(message)
    row.show
    listbox.add(row)
  end
end

Public Instance Methods

run() click to toggle source
# File gtk3/sample/gtk-demo/listbox.rb, line 45
def run
  if !@window.visible?
    @window.show_all
  else
    @window.destroy
  end
  @window
end