[baobab/wip/grid-layout: 8/8] location-widget: Draw background and border



commit db4b6a83711bfa933882c5aad538c84e21e03e39
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Apr 12 11:32:06 2012 +0200

    location-widget: Draw background and border

 src/baobab-location-widget.vala |   30 +++++++++++++++++++++++++++---
 src/baobab.css                  |    6 ++++++
 src/baobab.gresource.xml        |    1 +
 3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/src/baobab-location-widget.vala b/src/baobab-location-widget.vala
index 89aed4b..b4bca6b 100644
--- a/src/baobab-location-widget.vala
+++ b/src/baobab-location-widget.vala
@@ -23,7 +23,7 @@ namespace Baobab {
     public class LocationView : Gtk.Container {
         private int column_width = -1;
         private int row_height = -1;
-        
+
         List<Gtk.Widget> children = null;
 
         public LocationView () {
@@ -66,7 +66,7 @@ namespace Baobab {
                 child_alloc.y = alloc.y + row * row_height;
                 child_alloc.width = column_width;
                 child_alloc.height = row_height;
-                    
+
                 child.size_allocate (child_alloc);
 
                 if (++col >= columns) {
@@ -134,6 +134,8 @@ namespace Baobab {
 
         public delegate void ActionOnClick (Location? location = null);
 
+        private int padding;
+
         protected void ensure_size_groups () {
             if (name_size_group != null)
                 return;
@@ -148,7 +150,29 @@ namespace Baobab {
         public BaseLocationWidget () {
             //orientation = Gtk.Orientation.HORIZONTAL;
             column_spacing = 10;
-            margin = 6;
+            padding = 6;
+            margin = 10 + padding;
+
+            var css_provider = new Gtk.CssProvider ();
+            var bytes = GLib.resources_lookup_data ("/org/gnome/baobab/ui/baobab.css", 0);
+            css_provider.load_from_data ((string) bytes.get_data (), -1);
+
+            var context = get_style_context ();
+            context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER);
+            context.add_class (Gtk.STYLE_CLASS_FRAME);
+        }
+
+        protected override bool draw (Cairo.Context cr) {
+            Gtk.Allocation alloc;
+            get_allocation (out alloc);
+
+            cr.reset_clip ();
+            get_style_context ().render_background (cr, -padding, -padding, alloc.width + 2*padding, alloc.height + 2*padding);
+            get_style_context ().render_frame (cr, -padding, -padding, alloc.width + 2*padding, alloc.height + 2*padding);
+
+            base.draw (cr);
+
+            return false;
         }
     }
 
diff --git a/src/baobab.css b/src/baobab.css
new file mode 100644
index 0000000..38350c6
--- /dev/null
+++ b/src/baobab.css
@@ -0,0 +1,6 @@
+BaobabBaseLocationWidget.frame {
+    /*border-color: #ff0000;*/
+    border-width: 1px;
+    border-style: solid;
+    border-radius : 4px;
+}
diff --git a/src/baobab.gresource.xml b/src/baobab.gresource.xml
index d0789b8..aed7e6a 100644
--- a/src/baobab.gresource.xml
+++ b/src/baobab.gresource.xml
@@ -3,5 +3,6 @@
   <gresource prefix="/org/gnome/baobab/ui">
     <file preprocess="xml-stripblanks">baobab-main-window.ui</file>
     <file preprocess="xml-stripblanks">baobab-menu.ui</file>
+    <file>baobab.css</file>
   </gresource>
 </gresources>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]