4
4
namespace Lsc.Widgets {
5
public class CategoryButton : Button {
6
public CategoryButton (string icon, string name, bool fill = false) {
7
get_style_context ().add_provider (CategoriesView.style_provider, -1);
5
public class Category : Object {
9
public Category (string image, string group) {
15
public class CategoryButton : EventBox {
16
public CategoryButton (Category desc, bool fill = false) {
10
if (icon != "" && ! fill) {
18
visible_window = false;
20
if (desc.image != "" && ! fill) {
11
21
Box container = new Box(Orientation.HORIZONTAL, 3);
22
container.border_width = 5;
12
23
Box label_box = new Box(Orientation.VERTICAL, 0);
13
24
label_box.valign = Align.CENTER;
14
Image image_widget = new Image.from_icon_name(icon, IconSize.LARGE_TOOLBAR);
25
Image image_widget = new Image.from_icon_name(desc.image, IconSize.DND);
16
Label title = new Label("<b>"+name+"</b>");
27
Label title = new Label("<b>"+Utils.nicer_pkg_name(desc.name)+"</b>");
17
28
title.ellipsize = Pango.EllipsizeMode.END;
18
29
title.halign = Align.START;
19
30
title.valign = Align.END;
38
public class CategoriesView : Box {
40
private string CSS_STYLE = """
41
.CategoriesView *:first-child .button:first-child {
42
border-width: 1 0 0 1;
43
border-radius: 4 0 0 0;
44
-unico-outer-stroke-width: 1 0 0 1;
47
.CategoriesView *:first-child .button {
48
border-width: 1 0 0 1;
49
border-radius: 0 0 0 0;
50
-unico-outer-stroke-width: 1 0 0 0;
53
.CategoriesView *:first-child .button:last-child {
54
border-width: 1 1 0 1;
55
border-radius: 0 4 0 0;
56
-unico-outer-stroke-width: 1 1 0 0;
59
.CategoriesView *.button:first-child {
62
border-width: 1 0 0 1;
63
border-radius: 0 0 0 0;
64
-unico-outer-stroke-width: 0 0 0 1;
67
.CategoriesView *.button {
70
border-width: 1 0 0 1;
71
border-radius: 0 0 0 0;
72
-unico-outer-stroke-width: 0 0 0 0;
75
.CategoriesView *.button:last-child {
78
border-width: 1 1 0 1;
79
border-radius: 0 0 0 0;
80
-unico-outer-stroke-width: 0 1 0 0;
83
.CategoriesView *:last-child .button:first-child {
84
border-width: 1 0 1 1;
85
border-radius: 0 0 0 4;
86
-unico-outer-stroke-width: 0 0 1 1;
89
.CategoriesView *:last-child .button {
90
border-width: 1 0 1 1;
91
border-radius: 0 0 0 0;
92
-unico-outer-stroke-width: 0 0 1 0;
95
.CategoriesView *:last-child .button:last-child {
96
border-width: 1 1 1 1;
97
border-radius: 0 0 4 0;
98
-unico-outer-stroke-width: 0 1 1 0;
101
internal static CssProvider style_provider;
103
public signal void category_choosed ();
49
public class CategoriesView : RoundBox {
50
public signal void category_choosed (string group);
106
public Box box_child;
53
private Box box_child;
55
private Separator separator;
107
56
private CategoryButton button_child;
57
public int columns { get; set; }
109
58
private int actual_col;
111
public void add_category (string image, string name) {
112
if (actual_col == columns) {
113
box_child = new Box(Orientation.HORIZONTAL, 0);
114
box_child.homogeneous = true;
116
pack_start(box_child, true, true, 0);
120
button_child = new CategoryButton(image, name);
121
button_child.clicked.connect(() => { category_choosed(); });
122
button_child.show_all();
124
box_child.pack_start(button_child, true, true, 0);
128
public void fill_space () {
59
private new List<Category> children = null;
61
private void pack_separator () {
62
separator = new Separator(Orientation.HORIZONTAL);
63
separator.margin_left = 1;
64
separator.margin_right = 1;
66
pack_start(separator, false, false, 0);
69
public void add_category (string image, string group) {
70
children.append(new Category(image, group));
73
public void reconfigure_grid () {
74
foreach (Widget widget in main.get_children()) {
80
foreach (Category button_desc in children) {
81
if (actual_col == columns) {
82
box_child = new Box(Orientation.HORIZONTAL, 5);
83
box_child.homogeneous = true;
85
main.pack_start(box_child, true, true, 0);
88
button_child = new CategoryButton(button_desc);
89
button_child.button_press_event.connect(() => {
90
category_choosed("cat");
94
box_child.pack_start(button_child, true, true, 0);
95
button_child.show_all();
129
100
while (actual_col != columns) {
130
button_child = new CategoryButton("", "", true);
131
button_child.clicked.connect(() => { category_choosed(); });
101
button_child = new CategoryButton(new Category("", ""), true);
102
box_child.pack_start(button_child, true, true, 0);
132
103
button_child.show_all();
133
box_child.pack_start(button_child, true, true, 0);
138
public CategoriesView (int cols) {
108
public CategoriesView () {
109
base(Orientation.VERTICAL, 0);
142
if (style_provider == null) {
143
style_provider = new CssProvider();
145
style_provider.load_from_data (CSS_STYLE, -1);
147
warning ("CategoryView: %s. The widget will not look as intended", e.message);
151
orientation = Orientation.VERTICAL;
153
get_style_context().add_class("CategoriesView");
155
box_child = new Box(Orientation.HORIZONTAL, 0);
113
main = new Box(Orientation.VERTICAL, 5);
114
main.border_width = 5;
116
box_child = new Box(Orientation.HORIZONTAL, 5);
156
117
box_child.homogeneous = true;
157
pack_start(box_child, true, true, 0);
118
main.pack_start(box_child, true, true, 0);
120
Label title = new Label("<b>Categories</b>");
121
title.use_markup = true;
122
title.halign = Align.START;
125
pack_start(title, false, false, 0);
127
pack_start(main, false, false, 0);
129
notify["columns"].connect(reconfigure_grid);