From 8e2d33d3a5d17531a36e629bcf4c0bc36cbf1cfe Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 2 Nov 2014 20:40:40 +0100 Subject: Imported Upstream version 14.04.10 --- src/dash-button.vala | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/dash-button.vala (limited to 'src/dash-button.vala') diff --git a/src/dash-button.vala b/src/dash-button.vala new file mode 100644 index 0000000..c562a28 --- /dev/null +++ b/src/dash-button.vala @@ -0,0 +1,89 @@ +/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*- + * + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: Michael Terry + */ + +public class DashButton : FlatButton, Fadable +{ + protected FadeTracker fade_tracker { get; protected set; } + private Gtk.Label text_label; + + private string _text = ""; + public string text + { + get { return _text; } + set + { + _text = value; + text_label.set_markup ("%s".printf (value)); + } + } + + public DashButton (string text) + { + fade_tracker = new FadeTracker (this); + + var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + + /* Add text */ + text_label = new Gtk.Label (""); + text_label.use_markup = true; + text_label.hexpand = true; + text_label.halign = Gtk.Align.START; + hbox.add (text_label); + this.text = text; + + /* Add chevron */ + var path = Path.build_filename (Config.PKGDATADIR, "arrow_right.png", null); + try + { + var pixbuf = new Gdk.Pixbuf.from_file (path); + var image = new CachedImage (pixbuf); + image.valign = Gtk.Align.CENTER; + hbox.add (image); + } + catch (Error e) + { + debug ("Error loading image %s: %s", path, e.message); + } + + hbox.show_all (); + add (hbox); + + try + { + var style = new Gtk.CssProvider (); + style.load_from_data ("* {padding: 6px 8px 6px 8px; + -GtkWidget-focus-line-width: 0px; + }", -1); + this.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + catch (Error e) + { + debug ("Internal error loading session chooser style: %s", e.message); + } + } + + public override bool draw (Cairo.Context c) + { + c.push_group (); + base.draw (c); + c.pop_group_to_source (); + c.paint_with_alpha (fade_tracker.alpha); + return false; + } +} -- cgit v1.2.3