DisplayDemo: fix abuse of width and height properties in toggle_size
[libprolooks.git] / prolooks / DisplayDemo.vala
blob4c177a969315041180a0908a33a2b1922b086151
1 /*
2 Copyright 2009 by Hans Baier
3 License: LGPLv2+
4 */
6 using Gtk;
7 using Gdk;
9 namespace Prolooks {
11 public class TestDisplay : DisplayBase {
12 public TestDisplay() {
13 set_size_request (width, height);
16 protected override bool draw_contents(Cairo.Context cr, Gdk.EventExpose event) {
17 string str = "123| 45| 67890";
18 text(cr, str, 20, 20, 20);
19 Cairo.TextExtents ext = Cairo.TextExtents();
20 cr.text_extents (str, ref ext);
22 Color line_color;
23 Color.parse (text_color_default, out line_color);
24 set_source_color (cr, line_color, 0.5);
26 cr.move_to (20, 20 + ext.y_bearing);
27 cr.rel_line_to (0, ext.height);
28 cr.stroke();
30 cr.move_to (20 + ext.x_advance + ext.x_bearing, 20 + ext.y_bearing);
31 cr.rel_line_to (0, ext.height);
32 cr.stroke();
34 cr.move_to (3, 29);
35 cr.rel_line_to (width - 20, 0);
36 cr.stroke();
37 return false;
40 private bool orig_size = true;
42 public void toggle_size() {
43 stdout.printf("orig_size: %d\n", (int)orig_size);
44 int new_width, new_height;
45 if (orig_size) {
46 new_width = 291;
47 new_height = 49;
48 orig_size = false;
49 } else {
50 new_width = 383;
51 new_height = 72;
52 orig_size = true;
55 set_size_request (new_width, new_height);
58 static int main (string[] args) {
59 Gtk.init (ref args);
61 var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
62 var vbox = new VBox(false, 2);
63 var resize_button = new Button.with_label("Resize");
64 var alignment = new Gtk.Alignment (0.5f, 0.5f, 0.5f, 0.5f);
65 TestDisplay display = new TestDisplay ();
67 alignment.bottom_padding = 10;
68 alignment.top_padding = 10;
69 alignment.left_padding = 10;
70 alignment.right_padding = 10;
71 alignment.add (display);
72 alignment.set_size_request(display.width + 20, display.height + 20);
74 resize_button.pressed += display.toggle_size;
75 resize_button.set_size_request(100, 25);
77 vbox.add (alignment);
78 vbox.add (resize_button);
80 window.add (vbox);
81 window.destroy += Gtk.main_quit;
82 window.show_all ();
83 Gtk.main ();
84 return 0;
88 } // namespace prolooks