Created
June 26, 2020 15:30
-
-
Save yuntan/bfe028947ec19dd822c3ae02d49eafb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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