File: gtk-helper.vala

package info (click to toggle)
peek 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,768 kB
  • sloc: xml: 234; sh: 85; python: 69; makefile: 14
file content (55 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Peek Copyright (c) 2017 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

using Gtk;
using Cairo;

namespace Peek {

  public class GtkHelper {
    public static void hide_button_label (Button button) {
      var label = GtkHelper.find_first_child_of_type (button, typeof (Label));
      label.hide ();
    }

    public static void show_button_label (Button button) {
      var label = GtkHelper.find_first_child_of_type (button, typeof (Label));
      label.show ();
    }

    public static Widget? find_first_child_of_type (Container container, Type type) {
      var children = container.get_children ();

      foreach (var child in children) {
        var child_type = child.get_type ();
        if (child_type.is_a (type)) {
          return child;
        } else if (child_type.is_a (typeof (Container))) {
          return find_first_child_of_type ((Container) child, type);
        }
      }

      return null;
    }

    public static Region create_region_from_widget (Widget widget) {
      var rectangle = Cairo.RectangleInt () {
        width = widget.get_allocated_width (),
        height = widget.get_allocated_height ()
      };

      widget.translate_coordinates (
        widget.get_toplevel (), 0, 0,
        out rectangle.x, out rectangle.y);
      var region = new Region.rectangle (rectangle);

      return region;
    }
  }
}