← Back to team overview

elementaryart team mailing list archive

[Merge] lp:~xapantu/granite/modebutton into lp:granite

 

xapantu has proposed merging lp:~xapantu/granite/modebutton into lp:granite.

Requested reviews:
  elementary desktop team (elementaryart)

For more details, see:
https://code.launchpad.net/~xapantu/granite/modebutton/+merge/72954

ModeButton fixes and improvements to follow mockups.
-- 
https://code.launchpad.net/~xapantu/granite/modebutton/+merge/72954
Your team elementary desktop team is requested to review the proposed merge of lp:~xapantu/granite/modebutton into lp:granite.
=== modified file 'demo/main.vala'
--- demo/main.vala	2011-08-04 13:04:24 +0000
+++ demo/main.vala	2011-08-25 20:19:23 +0000
@@ -16,6 +16,27 @@
         notebook.append_page(welcome, new Gtk.Label("Welcome"));
         welcome.append("gtk-open", "Open", "Open a file");
         welcome.append("gtk-save", "Save", "Save with a much longer description");
+        
+        var mode_button = new ModeButton();
+        mode_button.valign = Gtk.Align.CENTER;
+        mode_button.halign = Gtk.Align.CENTER;
+        mode_button.append(new Gtk.Label("Hardware"));
+        mode_button.append(new Gtk.Label("Input"));
+        mode_button.append(new Gtk.Label("Output"));
+        mode_button.append(new Gtk.Label("Quite long"));
+        mode_button.append(new Gtk.Label("Veruy very long \n with a line break"));
+        
+        var vbox = new Gtk.VBox(false, 0);
+        
+        vbox.pack_start(mode_button);
+
+        mode_button = new ModeButton();
+        mode_button.valign = Gtk.Align.CENTER;
+        mode_button.halign = Gtk.Align.CENTER;
+        mode_button.append(new Gtk.Label("Small"));
+        mode_button.append(new Gtk.Label("a"));
+        vbox.pack_start(mode_button);
+        notebook.append_page(vbox, new Gtk.Label("ModeButton"));
         win.show_all();
         win.resize(800, 600);
     }

=== modified file 'lib/Widgets/ModeButton.vala'
--- lib/Widgets/ModeButton.vala	2011-07-18 14:53:59 +0000
+++ lib/Widgets/ModeButton.vala	2011-08-25 20:19:23 +0000
@@ -76,6 +76,8 @@
 			set_visible_window (false);
 			
 			set_size_request(-1, 24);
+			
+			get_style_context().add_class("button");
 		}
 		
 		private void add_child (Builder builder, Object child, string? type) {
@@ -88,6 +90,11 @@
 			box.pack_start (widget, true, true, 3);
 			int index = (int) box.get_children ().length () - 2;
 			mode_added (index, widget);
+			int height;
+			widget.set_margin_right(3);
+			widget.set_margin_left(3);
+			widget.set_margin_top(3);
+			widget.set_margin_bottom(3);
 		}
 
 		public new void remove (int index) {
@@ -184,7 +191,7 @@
 		}
 
 		protected override bool draw (Cairo.Context cr) {
-		
+			StyleContext context = get_style_context();
 			int width, height;
 			float item_x, item_width;
 
@@ -193,56 +200,59 @@
 
 			var n_children = (int) box.get_children ().length ();
 
-			style.draw_box (cr, StateType.NORMAL, ShadowType.ETCHED_OUT, this, "button", 0, 0, width, height);
+			context.set_state(Gtk.StateFlags.NORMAL);
+			Gtk.render_background(context, cr, 0, 0, width, height);
+			Gtk.render_frame(context, cr, 0, 0, width, height);
+
+			if (hovered >= 0 && selected != hovered) {
+				if (n_children > 1) {
+					item_width = width / n_children;
+					item_x = hovered * width/n_children;
+				} else {
+					item_x = 0;
+					item_width = width;
+				}
+
+				cr.move_to(item_x, 0);
+				cr.line_to(item_x, height);
+				cr.line_to(item_x+item_width + 1, height);
+				cr.line_to(item_x+item_width + 1, 0);
+				cr.clip();
+
+				context.set_state(Gtk.StateFlags.PRELIGHT);
+				Gtk.render_background(context, cr, 0, 0, width, height);
+				Gtk.render_frame(context, cr, 0, 0, width, height);
+			}
+
+			cr.restore();
+			cr.save();
 			if (_selected >= 0) {
 				if (n_children > 1) {
 					item_width = width / n_children;
-					item_x = (item_width * _selected) + 1;
+					item_x = _selected * width / n_children;
 				} else {
 					item_x = 0;
 					item_width = width;
 				}
-
+				
 				cr.move_to (item_x, 0);
 				cr.line_to (item_x, height);
-				cr.line_to (item_x+item_width, height);
-				cr.line_to (item_x+item_width, 0);
+				cr.line_to (item_x+item_width + 1, height);
+				cr.line_to (item_x+item_width + 1, 0);
 				cr.clip ();
 
-				style.draw_box (cr, StateType.SELECTED,
-								ShadowType.IN, this, "button",
-								0, 0,
-								width, height);
-			}
-
-			cr.restore();
-			cr.save();
-
-			if (hovered >= 0 && selected != hovered) {
-				if (n_children > 1) {
-					item_width = width / n_children;
-					if (hovered == 0)
-						item_x = 0;
-					else
-						item_x = item_width * hovered + 1;
-				} else {
-					item_x = 0;
-					item_width = width;
-				}
-
-				cr.move_to(item_x, 0);
-				cr.line_to(item_x, height);
-				cr.line_to(item_x+item_width, height);
-				cr.line_to(item_x+item_width, 0);
-				cr.clip();
-
-				style.draw_box (cr, StateType.PRELIGHT,
-								ShadowType.ETCHED_OUT, this, "button",
-								0, 0,
-								width, height);
-			}
-
-			cr.restore();
+				context.set_state(Gtk.StateFlags.ACTIVE);
+				Gtk.render_background(context, cr, 0, 0, width, height);
+				Gtk.render_frame(context, cr, 0, 0, width, height);
+			}
+
+			cr.restore();
+
+			context.set_state(Gtk.StateFlags.NORMAL);
+			for(int i = 1; i < n_children; i++)
+			{
+				Gtk.render_line(context, cr, i*width/n_children, 2, i*width/n_children, height - 2);
+			}
 
 			propagate_draw (box, cr);
 


Follow ups