-
Notifications
You must be signed in to change notification settings - Fork 1
/
00033.php
85 lines (69 loc) · 2.22 KB
/
00033.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* PHP-GTK Cookbook
*
* https://andor.com.br/php-gtk/cook/how-to-set-color-on-gtktreeview-column-header-with-css
*/
Gtk::init();
$window = new \GtkWindow();
$window->set_size_request(500, 500);
$window->set_title("PHP-GTK");
// create a box
$vbox = new \GtkBox(GtkOrientation::VERTICAL);
$vbox->set_border_width(10);
// create the treeview, added it inside a scrolled window, and pack scrolled windows to box
$treeview = new GtkTreeView();
$scroll = new GtkScrolledWindow();
$scroll->add($treeview);
$vbox->pack_start($scroll, TRUE, TRUE, 0);
// columns
$renderer = new GtkCellRendererText();
$column1 = new GtkTreeViewColumn("Name", $renderer, "text", 0);
$column1->get_button()->set_name("my_column1"); // add custom name to button inside column
$treeview->append_column($column1);
$renderer = new GtkCellRendererText();
$column2 = new GtkTreeViewColumn("Phone", $renderer, "text", 1);
$column2->get_button()->set_name("my_column2"); // add custom name to button inside column
$treeview->append_column($column2);
$renderer = new GtkCellRendererText();
$column3 = new GtkTreeViewColumn("Genre", $renderer, "text", 2);
$column3->get_button()->set_name("my_column3"); // add custom name to button inside column
$treeview->append_column($column3);
// create model
$model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING, GObject::TYPE_STRING);
$treeview->set_model($model);
// add values
$model->append(["Bruno", "+55 43 9 9282-2039", "M"]);
$model->append(["Natália", "+55 17 8273-0293", "F"]);
$model->append(["Maria", "+49 4190-8140", "F"]);
$model->append(["Sven", "+49 0291-2450", "M"]);
// add to window
$window->add($vbox);
// create and add CSS
$css_provider = new GtkCssProvider();
$css_provider->load_from_data("
#my_column1 {
background: #1a87ce;
border: none;
color: #000;
}
#my_column2 {
background: #cd9c41;
border: none;
color: #000;
}
#my_column3 {
background: #c54e48;
border: none;
color: #000;
}
");
$style_context = new GtkStyleContext();
$style_context->add_provider_for_screen($css_provider, 600);
// connect to signal that close program
$window->connect("destroy", function() {
Gtk::main_quit();
});
// show all and start
$window->show_all();
Gtk::main();