The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Button.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/Button.vala.
Switch keyboard focus with tab key in name and description tab
1 /* 2 Copyright (C) 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Cairo; 16 17 namespace BirdFont { 18 19 public class Button : Widget { 20 21 Text label; 22 double padding; 23 double font_size; 24 25 public signal void action (); 26 27 public Button (string label) { 28 font_size = 17 * MainWindow.units; 29 this.label = new Text (label, font_size); 30 padding = 15 * MainWindow.units; 31 } 32 33 public override void draw (Context cr) { 34 cr.save (); 35 Theme.color (cr, "Button Background 3"); 36 draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding); 37 cr.fill (); 38 cr.restore (); 39 40 cr.save (); 41 Theme.color (cr, "Button Border 3"); 42 cr.set_line_width (1); 43 draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding); 44 cr.stroke (); 45 cr.restore (); 46 47 cr.save (); 48 Theme.text_color (label, "Button Foreground"); 49 label.draw_at_top (cr, widget_x + padding, widget_y + (2 * padding - font_size - 3 * MainWindow.units) / 2.0); 50 cr.restore (); 51 } 52 53 public override double get_height () { 54 return 2 * padding; 55 } 56 57 public override double get_width () { 58 return label.get_width () + 2 * padding; 59 } 60 61 public override void button_press (uint button, double x, double y) { 62 if (is_over (x, y)) { 63 action (); 64 } 65 } 66 } 67 68 } 69