Created
July 29, 2013 15:35
-
-
Save voldyman/6105207 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// http://imgur.com/EKKMKNn | |
using Gtk; | |
class OptionBox : EventBox { | |
public signal void clicked (); | |
public OptionBox (string title, string info) { | |
var main_grid = new Grid (); | |
var title_label = new Label (null); | |
var info_label = new Label (info); | |
var opt_switch = new Switch(); | |
title_label.set_markup ("<b>%s</b>".printf (title)); | |
main_grid.attach (title_label, 0, 0, 1, 1); | |
main_grid.attach (info_label , 0, 1, 2, 1); | |
main_grid.attach (opt_switch , 2, 0, 1, 1); | |
add (main_grid); | |
button_press_event.connect (release_handler); | |
} | |
private bool release_handler () { | |
this.clicked(); | |
return true; | |
} | |
} | |
class MainWindow : Window { | |
private Label info_label; | |
public MainWindow () { | |
var pane = new Paned (Orientation.HORIZONTAL); | |
var list_box = new Box (Orientation.VERTICAL, 10); | |
var scrlr = new ScrolledWindow (null, null); | |
scrlr.add_with_viewport (list_box); | |
for (int i = 0; i<10; i++) { | |
var opt_box = new OptionBox (i.to_string (), "doodle"); | |
opt_box.clicked.connect (clicked); | |
list_box.pack_start (opt_box); | |
} | |
pane.add1 (scrlr); | |
var info_box = new Box (Orientation.VERTICAL, 0); | |
info_label = new Label ("Info about the selected item"); | |
info_box.add (info_label); | |
pane.add2 (info_box); | |
add (pane); | |
} | |
private void clicked () { | |
info_label.label ("me got clicked"); | |
} | |
} | |
int main (string[] args) { | |
Gtk.init (ref args); | |
var window = new MainWindow (); | |
window.title = "UI Test"; | |
window.window_position = WindowPosition.CENTER; | |
window.set_default_size (350, 70); | |
window.destroy.connect (Gtk.main_quit); | |
window.show_all (); | |
Gtk.main (); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment