File: game-actionbar.vala

package info (click to toggle)
gnome-taquin 3.38.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,184 kB
  • sloc: xml: 81; python: 11; makefile: 6
file content (130 lines) | stat: -rw-r--r-- 4,321 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-

   This file is part of a GNOME game

   Copyright (C) 2019 – Arnaud Bonatti <arnaud.bonatti@gmail.com>

   This application is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This application 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 application.  If not, see <https://www.gnu.org/licenses/>.
*/

using Gtk;

[GtkTemplate (ui = "/org/gnome/Taquin/ui/game-actionbar.ui")]
private class GameActionBar : Revealer, AdaptativeWidget
{
    [CCode (notify = false)] public bool show_actionbar  { private get; protected construct set; default = false; }
    [CCode (notify = false)] public bool window_has_name { private get; protected construct set; default = false; }
    [CCode (notify = false)] public string  window_name  { private get; protected construct set; default = ""   ; }
    [CCode (notify = false)] public Widget? game_widget  { private get; protected construct    ; default = null ; }

    [GtkChild] private ActionBar action_bar;
    [GtkChild] private Label game_label;

    construct
    {
        if (game_widget != null)
            action_bar.pack_end ((!) game_widget);

        if (window_has_name)
            game_label.set_label (window_name);

        update_visibility ();
    }

    internal GameActionBar (string _game_name, Widget? _game_widget, bool _show_actionbar)
    {
        Object (window_has_name : _game_name != "",
                window_name     : _game_name,
                game_widget     : _game_widget,
                show_actionbar  : _show_actionbar);
    }

    /*\
    * * adaptative stuff
    \*/

    private bool is_extra_thin = true;
    protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
    {
//        if (game_widget != null)
//            ((AdaptativeWidget) (!) game_widget).set_window_size (new_size);

        bool _is_extra_thin = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
        if (_is_extra_thin == is_extra_thin)
            return;
        is_extra_thin = _is_extra_thin;
        update_visibility ();
    }

    private void update_visibility ()
    {
        set_reveal_child (is_extra_thin && show_actionbar);
    }

    /*\
    * * some internal calls
    \*/

    internal void update_title (string new_title)
    {
        window_name = new_title;
        window_has_name = new_title != "";
        game_label.set_label (window_name);
    }

    internal void set_visibility (bool new_visibility)
    {
        show_actionbar = new_visibility;
        update_visibility ();
    }
}

[GtkTemplate (ui = "/org/gnome/Taquin/ui/game-actionbar-placeholder.ui")]
private class GameActionBarPlaceHolder : Revealer, AdaptativeWidget
{
    [GtkChild] private Widget placeholder_child;
    private GameActionBar actionbar;

    internal GameActionBarPlaceHolder (GameActionBar _actionbar)
    {
        actionbar = _actionbar;
        actionbar.size_allocate.connect (set_height);
        set_height ();
        set_reveal_child (true);    // seems like setting it in the UI file does not work, while it is OK for GameActionBar...
    }

    private void set_height ()
    {
        Requisition natural_size;
        Widget? widget = actionbar.get_child ();
        if (widget == null)
            return;
        ((!) widget).get_preferred_size (/* minimum size */ null, out natural_size);
        placeholder_child.height_request = natural_size.height;
    }

    /*\
    * * adaptative stuff
    \*/

    private bool is_extra_thin = true;
    protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
    {
        bool _is_extra_thin = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
        if (_is_extra_thin == is_extra_thin)
            return;
        is_extra_thin = _is_extra_thin;
        set_reveal_child (is_extra_thin);
    }
}