[baobab/wip/grid-layout: 6/9] Relayout the location widget
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/grid-layout: 6/9] Relayout the location widget
- Date: Sun, 15 Apr 2012 13:27:47 +0000 (UTC)
commit cf37fe9ec2bfca4d3091bc87329e23e47ec53a59
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sun Apr 15 15:03:18 2012 +0200
Relayout the location widget
src/baobab-location-widget.vala | 114 +++++++++++++++++++++++++++++++++------
1 files changed, 97 insertions(+), 17 deletions(-)
---
diff --git a/src/baobab-location-widget.vala b/src/baobab-location-widget.vala
index fc527de..de8b665 100644
--- a/src/baobab-location-widget.vala
+++ b/src/baobab-location-widget.vala
@@ -22,6 +22,8 @@ namespace Baobab {
public abstract class BaseLocationWidget : Gtk.Grid {
+ protected const int ICON_SIZE = 48;
+
protected static Gtk.SizeGroup name_size_group = null;
protected static Gtk.SizeGroup mount_point_size_group = null;
protected static Gtk.SizeGroup size_size_group = null;
@@ -42,10 +44,56 @@ namespace Baobab {
}
public BaseLocationWidget () {
- orientation = Gtk.Orientation.HORIZONTAL;
column_spacing = 10;
margin = 6;
}
+
+ protected override void get_preferred_width (out int minimum, out int natural) {
+ int min, nat;
+ base.get_preferred_width (out min, out nat);
+
+ var state = get_state_flags ();
+ var border = get_style_context ().get_padding (state);
+ minimum = min + border.left + border.right;
+ natural = nat + border.left + border.right;
+ }
+
+ protected override void get_preferred_height (out int minimum, out int natural) {
+ int min, nat;
+ base.get_preferred_height (out min, out nat);
+
+ var state = get_state_flags ();
+ var border = get_style_context ().get_padding (state);
+ minimum = min + border.top + border.bottom;
+ natural = nat + border.top + border.bottom;
+ }
+
+ protected override void size_allocate (Gtk.Allocation alloc) {
+ var state = get_state_flags ();
+ var border = get_style_context ().get_padding (state);
+
+ var adjusted_alloc = Gtk.Allocation ();
+ adjusted_alloc.x = alloc.x + border.left;
+ adjusted_alloc.y = alloc.y + border.top;
+ adjusted_alloc.width = alloc.width - border.left - border.right;
+ adjusted_alloc.height = alloc.height - border.top - border.bottom;
+
+ base.size_allocate (adjusted_alloc);
+
+ set_allocation (alloc);
+ }
+
+ protected override bool draw (Cairo.Context cr) {
+ Gtk.Allocation alloc;
+ get_allocation (out alloc);
+
+ get_style_context ().render_background (cr, 0, 0, alloc.width, alloc.height);
+ get_style_context ().render_frame (cr, 0, 0, alloc.width, alloc.height);
+
+ base.draw (cr);
+
+ return false;
+ }
}
public class LocationWidget : BaseLocationWidget {
@@ -56,50 +104,82 @@ namespace Baobab {
ensure_size_groups ();
var icon_theme = Gtk.IconTheme.get_default ();
- var icon_info = icon_theme.lookup_by_gicon (location.icon, 64, 0);
+ var icon_info = icon_theme.lookup_by_gicon (location.icon, BaseLocationWidget.ICON_SIZE, 0);
+
+ var info_grid = new Gtk.Grid ();
try {
var pixbuf = icon_info.load_icon ();
var image = new Gtk.Image.from_pixbuf (pixbuf);
- add (image);
+ info_grid.attach (image, 1, -1, 1, 1);
} catch (Error e) {
warning ("Failed to load icon %s: %s", location.icon.to_string(), e.message);
}
var label = new Gtk.Label (location.name);
+ label.set_markup ("<b>" + location.name + "</b>");
label.xalign = 0;
- name_size_group.add_widget (label);
- add (label);
+ info_grid.attach (label, 2, -1, 1, 1);
- label = new Gtk.Label (location.mount_point != null ? location.mount_point : "");
- label.hexpand = true;
- label.halign = Gtk.Align.CENTER;
- label.xalign = 0;
+
+ info_grid.column_spacing = 10;
+ info_grid.row_spacing = 6;
+ info_grid.valign = Gtk.Align.CENTER;
+
+ label = new Gtk.Label (_("Size"));
+ label.halign = Gtk.Align.END;
label.get_style_context ().add_class ("dim-label");
- mount_point_size_group.add_widget (label);
- add (label);
+ info_grid.attach (label, 1, 0, 1, 1);
label = new Gtk.Label (location.size != null ? format_size (location.size) : "");
- size_size_group.add_widget (label);
- add (label);
+ label.halign = Gtk.Align.START;
+ info_grid.attach (label, 2, 0, 1, 1);
+
if (location.used != null) {
+ label = new Gtk.Label (_("Usage"));
+ label.halign = Gtk.Align.END;
+ label.get_style_context ().add_class ("dim-label");
+ info_grid.attach (label, 1, 1, 1, 1);
+
var progress = new Gtk.ProgressBar ();
progress.valign = Gtk.Align.CENTER;
progress.set_fraction ((double) location.used / location.size);
used_size_group.add_widget (progress);
- add (progress);
+ info_grid.attach (progress, 2, 1, 1, 1);
} else {
- label = new Gtk.Label (_("Usage unknown"));
+ label = new Gtk.Label ("");
+ info_grid.attach (label, 2, 3, 1, 1);
used_size_group.add_widget (label);
- add (label);
}
+ label = new Gtk.Label (_("Mounted at"));
+ label.halign = Gtk.Align.END;
+ label.get_style_context ().add_class ("dim-label");
+ info_grid.attach (label, 1, 2, 1, 1);
+
+ label = new Gtk.Label (location.mount_point != null ? location.mount_point : "not mounted");
+ //label.hexpand = true;
+ label.halign = Gtk.Align.START;
+ label.xalign = 0;
+ label.max_width_chars = 20;
+ label.ellipsize = Pango.EllipsizeMode.END;
+ if (location.mount_point != null)
+ label.set_tooltip_text (location.mount_point);
+ mount_point_size_group.add_widget (label);
+ info_grid.attach (label, 2, 2, 1, 1);
+
+ attach (info_grid, 0, 1, 1, 1);
+
+ //size_size_group.add_widget (label);
+ //add (label);
+
string button_label = location.mount_point != null ? _("Scan") : _("Mount and scan");
var button = new Gtk.Button.with_label (button_label);
button.valign = Gtk.Align.CENTER;
+ button.halign = Gtk.Align.END;
button_size_group.add_widget (button);
- add (button);
+ attach (button, 0, 2, 1, 1);
button.clicked.connect(() => { action (location); });
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]