[four-in-a-row/arnaudb/new-ui: 12/12] Introduce GameActionBar.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row/arnaudb/new-ui: 12/12] Introduce GameActionBar.
- Date: Thu, 19 Dec 2019 19:50:55 +0000 (UTC)
commit 23d8531707498bf5164a04be2a114f33b2cbb88d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Dec 19 18:30:05 2019 +0100
Introduce GameActionBar.
data/four-in-a-row.css | 16 ++++++++
data/ui/adaptative-window.ui | 2 +-
data/ui/four-in-a-row.ui | 4 +-
data/ui/game-actionbar.ui | 39 ++++++++++++++++++
src/four-in-a-row.gresource.xml | 1 +
src/four-in-a-row.vala | 6 ++-
src/game-actionbar.vala | 91 +++++++++++++++++++++++++++++++++++++++++
src/game-window.vala | 81 +++++++++++++++++++++++++++++-------
src/meson.build | 1 +
9 files changed, 221 insertions(+), 20 deletions(-)
---
diff --git a/data/four-in-a-row.css b/data/four-in-a-row.css
index 84699d2..ddc4b56 100644
--- a/data/four-in-a-row.css
+++ b/data/four-in-a-row.css
@@ -36,6 +36,7 @@ GtkButtonBox {
.thin-window .game-box { padding:1.0rem; }
.extra-thin-window.thin-window .game-box,
.flat-window .game-box { padding:0.5rem; }
+.extra-thin-window.thin-window .game-box {
padding-bottom:calc(0.5rem+47px); } /* FIXME hackish, height of the actionbar using MySettings(TM)... */
.extra-flat-window.flat-window .game-box { padding:0.4rem; }
/*\
@@ -49,6 +50,21 @@ GtkButtonBox {
.extra-thin-window button.start-game-button { margin-top:1.0rem; }
+label.game-name-label:dir(ltr) {
+ margin-left : 12px;
+}
+label.game-name-label:dir(rtl) {
+ margin-right: 12px;
+}
+
+/* the actionbar is in an overlay... */
+actionbar {
+ background-color:@theme_bg_color;
+}
+actionbar:backdrop {
+ background-color:@theme_unfocused_bg_color;
+}
+
/*\
* * options buttons
\*/
diff --git a/data/ui/adaptative-window.ui b/data/ui/adaptative-window.ui
index f9e31f2..897dad0 100644
--- a/data/ui/adaptative-window.ui
+++ b/data/ui/adaptative-window.ui
@@ -19,7 +19,7 @@
<requires lib="gtk+" version="3.12"/>
<template class="AdaptativeWindow" parent="GtkApplicationWindow">
<property name="height-request">284</property> <!-- 288px max for Purism Librem 5 landscape, for 720px
width; update gschema also -->
- <property name="width-request">490</property> <!-- 350</property> <! - 360px max for Purism Librem 5
portrait, for 648px height; update gschema also -->
+ <property name="width-request">350</property> <!-- 360px max for Purism Librem 5 portrait, for 648px
height; update gschema also -->
<signal name="window-state-event" handler="on_window_state_event"/>
<signal name="size-allocate" handler="on_size_allocate"/>
<signal name="destroy" handler="on_destroy"/>
diff --git a/data/ui/four-in-a-row.ui b/data/ui/four-in-a-row.ui
index 5d4d4df..9f9aeb3 100644
--- a/data/ui/four-in-a-row.ui
+++ b/data/ui/four-in-a-row.ui
@@ -88,7 +88,7 @@
</object>
</child>
<child>
- <object class="GtkOverlay">
+ <object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<child>
<object class="GtkStack" id="stack">
@@ -113,7 +113,7 @@
<child>
<object class="GtkBox" id="game_box">
<property name="visible">True</property>
- <property name="orientation">horizontal</property>
+ <property name="orientation">vertical</property>
<style>
<class name="game-box"/>
</style>
diff --git a/data/ui/game-actionbar.ui b/data/ui/game-actionbar.ui
new file mode 100644
index 0000000..e5b640b
--- /dev/null
+++ b/data/ui/game-actionbar.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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/>.
+-->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="GameActionBar" parent="GtkRevealer">
+ <property name="visible">True</property>
+ <property name="reveal-child">True</property>
+ <child>
+ <object class="GtkActionBar" id="action_bar">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="game_label">
+ <property name="visible">True</property>
+ <style>
+ <class name="game-name-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/four-in-a-row.gresource.xml b/src/four-in-a-row.gresource.xml
index d6739c3..b0e11c9 100644
--- a/src/four-in-a-row.gresource.xml
+++ b/src/four-in-a-row.gresource.xml
@@ -13,6 +13,7 @@
<file preprocess="xml-stripblanks" compressed="true"
alias="adaptative-window.ui">../data/ui/adaptative-window.ui</file>
<file preprocess="xml-stripblanks" compressed="true"
alias="fiar-screens.ui">../data/ui/fiar-screens.ui</file>
<file preprocess="xml-stripblanks" compressed="true"
alias="game-window.ui">../data/ui/four-in-a-row.ui</file>
+ <file preprocess="xml-stripblanks" compressed="true"
alias="game-actionbar.ui">../data/ui/game-actionbar.ui</file>
<file preprocess="xml-stripblanks" compressed="true"
alias="history-button.ui">../data/ui/history-button.ui</file>
</gresource>
</gresources>
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 08fae3f..a1bb16f 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -830,7 +830,8 @@ private class FourInARow : Gtk.Application
app_menu.freeze ();
- MenuButton history_button = new HistoryButton (/* direction: down */ false);
+ MenuButton history_button_1 = new HistoryButton (/* direction: down */ false);
+ MenuButton history_button_2 = new HistoryButton (/* direction: up */ true);
/* Window */
window = new GameWindow ("/org/gnome/Four-in-a-row/ui/four-in-a-row.css",
@@ -840,7 +841,8 @@ private class FourInARow : Gtk.Application
(Box) new_game_screen,
game_board_view,
app_menu,
- history_button);
+ history_button_1,
+ history_button_2);
scorebox = new Scorebox (window, this);
diff --git a/src/game-actionbar.vala b/src/game-actionbar.vala
new file mode 100644
index 0000000..297006c
--- /dev/null
+++ b/src/game-actionbar.vala
@@ -0,0 +1,91 @@
+/* -*- 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/Four-in-a-row/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 ();
+ }
+}
diff --git a/src/game-window.vala b/src/game-window.vala
index 87f2582..6ec0137 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -29,7 +29,7 @@ private enum GameWindowFlags {
}
[GtkTemplate (ui = "/org/gnome/Four-in-a-row/ui/game-window.ui")]
-private class GameWindow : AdaptativeWindow
+private class GameWindow : AdaptativeWindow, AdaptativeWidget
{
/* settings */
private bool window_is_tiled;
@@ -44,6 +44,7 @@ private class GameWindow : AdaptativeWindow
/* private widgets */
[GtkChild] private HeaderBar headerbar;
+ [GtkChild] private Overlay overlay;
[GtkChild] private Stack stack;
private Button? start_game_button = null;
@@ -55,7 +56,8 @@ private class GameWindow : AdaptativeWindow
[GtkChild] private Box new_game_box;
private Widget view;
- private Widget? game_widget;
+ private Widget? game_widget_1;
+ private GameActionBar actionbar;
/* signals */
internal signal void play ();
@@ -66,7 +68,7 @@ private class GameWindow : AdaptativeWindow
// internal signal void redo ();
internal signal void hint ();
- internal GameWindow (string? css_resource, string name, bool start_now, GameWindowFlags flags, Box
new_game_screen, Widget _view, GLib.Menu app_menu, Widget? _game_widget)
+ internal GameWindow (string? css_resource, string name, bool start_now, GameWindowFlags flags, Box
new_game_screen, Widget _view, GLib.Menu app_menu, Widget? _game_widget_1, Widget? game_widget_2)
{
Object (window_title: name,
specific_css_class_or_empty: "",
@@ -82,24 +84,31 @@ private class GameWindow : AdaptativeWindow
}
view = _view;
- game_widget = _game_widget;
+ game_widget_1 = _game_widget_1;
/* window config */
install_ui_action_entries ();
program_name = name;
set_title (name);
- headerbar.set_title (name);
+ if (!is_extra_thin)
+ headerbar.set_title (name);
info_button.set_menu_model (app_menu);
/* add widgets */
- if (game_widget != null)
+ if (game_widget_1 != null)
{
- headerbar.pack_end ((!) game_widget);
- add_adaptative_child ((AdaptativeWidget) (!) game_widget);
+ headerbar.pack_end ((!) game_widget_1);
+ add_adaptative_child ((AdaptativeWidget) (!) game_widget_1);
}
+ actionbar = new GameActionBar (name, game_widget_2, /* show actionbar */ start_now);
+ actionbar.show ();
+ actionbar.valign = Align.END;
+ overlay.add_overlay (actionbar);
new_game_box.pack_start (new_game_screen, true, true, 0);
add_adaptative_child ((AdaptativeWidget) new_game_screen);
+ add_adaptative_child ((AdaptativeWidget) actionbar);
+ add_adaptative_child ((AdaptativeWidget) this);
if (GameWindowFlags.SHOW_START_BUTTON in flags)
{
/* Translators: when configuring a new game, label of the blue Start button (with a mnemonic
that appears pressing Alt) */
@@ -202,8 +211,16 @@ private class GameWindow : AdaptativeWindow
internal void set_subtitle (string? subtitle)
{
- headerbar.set_title (subtitle);
+ if (!is_extra_thin)
+ headerbar.set_title (subtitle);
last_subtitle = subtitle;
+ if (subtitle == null)
+ actionbar.set_visibility (false);
+ else
+ {
+ actionbar.update_title ((!) subtitle);
+ actionbar.set_visibility (true);
+ }
}
internal void finish_game ()
@@ -233,6 +250,35 @@ private class GameWindow : AdaptativeWindow
undo_action.set_enabled (allow);
}
+ /*\
+ * * adaptative stuff
+ \*/
+
+ private bool is_extra_thin = false;
+ 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;
+
+ if (is_extra_thin)
+ {
+ headerbar.set_title (null);
+ if (game_widget_1 != null)
+ ((!) game_widget_1).hide ();
+ }
+ else
+ {
+ if (game_widget_1 != null)
+ ((!) game_widget_1).show ();
+ if (stack.get_visible_child_name () == "start-box")
+ headerbar.set_title (program_name);
+ else
+ headerbar.set_title (last_subtitle);
+ }
+ }
+
/*\
* * Showing the Stack
\*/
@@ -240,11 +286,13 @@ private class GameWindow : AdaptativeWindow
private string? last_subtitle = null;
private void show_new_game_screen ()
{
- headerbar.set_title (program_name);
+ if (!is_extra_thin)
+ headerbar.set_title (program_name);
+ actionbar.set_visibility (false);
stack.set_visible_child_name ("start-box");
- if (game_widget != null)
- ((!) game_widget).hide ();
+ if (game_widget_1 != null)
+ ((!) game_widget_1).hide ();
new_game_button.hide ();
if (!game_finished && back_button.visible)
@@ -255,12 +303,15 @@ private class GameWindow : AdaptativeWindow
private void show_view ()
{
- headerbar.set_title (last_subtitle);
+ if (!is_extra_thin)
+ headerbar.set_title (last_subtitle);
+ actionbar.set_visibility (true);
stack.set_visible_child_name ("game-box");
back_button.hide (); // TODO transition?
- if (game_widget != null)
- ((!) game_widget).show ();
+ if (game_widget_1 != null
+ && stack.get_visible_child_name () == "start-box")
+ ((!) game_widget_1).show ();
new_game_button.show ();
if (game_finished)
diff --git a/src/meson.build b/src/meson.build
index a0a06dd..f6c261f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -21,6 +21,7 @@ sources = files(
'adaptative-window.vala',
'ai.vala',
'four-in-a-row.vala',
+ 'game-actionbar.vala',
'game-board-view.vala',
'game-board.vala',
'game-window.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]