Skip to content

Instantly share code, notes, and snippets.

@yuntan
Created June 26, 2020 15:30
Show Gist options
  • Save yuntan/bfe028947ec19dd822c3ae02d49eafb6 to your computer and use it in GitHub Desktop.
Save yuntan/bfe028947ec19dd822c3ae02d49eafb6 to your computer and use it in GitHub Desktop.
require 'gtk3'
class Model < GLib::Object
type_register
include Gio::ListModel
def initialize
super
@array = ["apple", "banana", "orange"] * 10
end
def do_get_item_type
GLib::STRING
end
def do_get_n_items
@array.length
end
def do_get_item(pos)
@array[pos]
end
end
listbox = Gtk::ListBox.new
model = Model.new
listbox.bind_model model do |item|
Gtk::Label.new item
end
window = Gtk::Window.new
window << listbox
window.show_all
Gtk.main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment