Remove uses of deprecated HBox/VBox
[libprolooks.git] / src / KnobWithDisplay.vala
blob60bcee3e42eace434f9a46497d4c506305ed4f3c
1 /*
2 Copyright 2009 by Hans Baier
3 License: LGPLv2+
4 */
6 using Gtk;
8 namespace Prolooks {
10 public class KnobWithDisplay : EventBox {
11 private Box vbox;
12 private Knob knob;
13 private ValueDisplay display;
15 public string unit { get; set; }
17 // This function is called whenever the knob value changes
18 public delegate void DisplayFunc (Knob knob, ValueDisplay display, KnobWithDisplay knob_with_display);
20 private DisplayFunc? display_func = null;
21 public void set_display_func (DisplayFunc func) {
22 display_func = func;
25 // delegating properties
26 [Description(nick="show matrix", blurb="Whether a pixel matrix should be drawn in the display background (much faster if false)")]
27 public bool show_matrix { get { return display.show_matrix; } set { display.show_matrix = value; } }
28 public Adjustment adjustment { get { return knob.get_adjustment (); } set { knob.set_adjustment (value); } }
29 [Description(nick="knob mode", blurb="determines, how the knob will work / look like")]
30 public KnobMode knob_mode { get { return knob.knob_mode; } set { knob.knob_mode = value; } }
31 [Description(nick="decimal places", blurb="The value will be rounded to the given number of decimal places")]
32 public uint decimal_places { get { return knob.decimal_places; } set { knob.decimal_places = value; } }
34 construct {
35 vbox = new Box (Gtk.Orientation.VERTICAL, 0);
36 knob = new Knob ();
37 vbox.pack_start (knob);
38 display = new ValueDisplay ();
39 vbox.pack_start (display);
40 knob.user_data = display;
41 decimal_places = 2;
42 var adj = knob.get_adjustment ();
43 knob.value_changed += (knob) => {
44 ValueDisplay disp = knob.user_data as ValueDisplay;
45 string text;
47 if (display_func != null) {
48 display_func (knob, display, this);
49 } else {
50 text = "%.*f".printf (knob.decimal_places, knob.get_value ()) + " " + unit;
51 disp.text = text;
55 add (vbox);
56 show_matrix = true;
57 GLib.Timeout.add (512, ()=> {
58 knob.value_changed ();
59 });
63 } // namespace Prolooks