[gnome-games/wip/aplazas/gamepad-config: 13/26] ui: Use stack in PreferencesPageInput
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/gamepad-config: 13/26] ui: Use stack in PreferencesPageInput
- Date: Mon, 10 Jul 2017 11:38:14 +0000 (UTC)
commit 31ff01a5a2936079ac2cd40232512ab8ea731a01
Author: theawless <theawless gmail com>
Date: Sat Jun 3 16:25:48 2017 +0530
ui: Use stack in PreferencesPageInput
Showing GamepadMapper as a Dialog resulted in three windows on the
screen which is against HIG recommendations. This commit changes the
PreferencesPageInput to use stack and GamepadMapper use to box.
https://bugzilla.gnome.org/show_bug.cgi?id=780754
data/ui/gamepad-mapper.ui | 100 ++++++++++++++++++++++--------------
data/ui/preferences-page-input.ui | 18 ++++++-
src/ui/gamepad-mapper.vala | 40 +++++++++------
src/ui/preferences-page-input.vala | 21 ++++++--
4 files changed, 118 insertions(+), 61 deletions(-)
---
diff --git a/data/ui/gamepad-mapper.ui b/data/ui/gamepad-mapper.ui
index 596493a..0b91ddd 100644
--- a/data/ui/gamepad-mapper.ui
+++ b/data/ui/gamepad-mapper.ui
@@ -1,57 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="GamesGamepadMapper" parent="GtkDialog">
- <property name="destroy-with-parent">True</property>
- <property name="type_hint">dialog</property>
- <child internal-child="vbox">
- <object class="GtkBox">
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <property name="margin-top">12</property>
- <property name="margin-bottom">12</property>
- <property name="margin-start">48</property>
- <property name="margin-end">48</property>
- <child>
- <object class="GtkLabel" id="info_message">
- <property name="visible">True</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="error_message">
- <property name="visible">True</property>
- <attributes>
- <attribute name="foreground" value="red"/>
- </attributes>
+ <template class="GamesGamepadMapper" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-start">48</property>
+ <property name="margin-end">48</property>
+ <child>
+ <object class="GtkLabel" id="info_message">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="error_message">
+ <property name="visible">True</property>
+ <attributes>
+ <attribute name="foreground" value="red"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GamesGamepadView" id="gamepad_view">
+ <property name="halign">center</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </template>
+ <object class="GtkBox" id="header_content">
+ <property name="orientation">horizontal</property>
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <property name="hexpand">True</property>
+ <child>
+ <object class="GtkButton" id="back_button">
+ <property name="visible">True</property>
+ <signal name="clicked" handler="on_back_clicked"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="a11y-back">
+ <property name="accessible-name" translatable="yes">Back</property>
</object>
</child>
<child>
- <object class="GamesGamepadView" id="gamepad_view">
- <property name="halign">center</property>
+ <object class="GtkImage" id="back_image">
<property name="visible">True</property>
+ <property name="icon-name">go-previous-symbolic</property>
+ <property name="icon-size">1</property>
</object>
</child>
</object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
</child>
- <child type="action">
- <object class="GtkButton" id="button_apply">
+ <child type="center">
+ <object class="GtkLabel" id="title">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="apply_button">
<property name="visible">True</property>
<property name="can-default">True</property>
<property name="label" translatable="yes">Apply</property>
+ <signal name="clicked" handler="on_apply_clicked"/>
<style>
<class name="suggested-action"/>
</style>
</object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
</child>
- <child type="action">
- <object class="GtkButton" id="button_cancel">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Cancel</property>
- </object>
- </child>
- <action-widgets>
- <action-widget response="apply" default="true">button_apply</action-widget>
- <action-widget response="cancel">button_cancel</action-widget>
- </action-widgets>
- </template>
+ </object>
</interface>
diff --git a/data/ui/preferences-page-input.ui b/data/ui/preferences-page-input.ui
index 877dd49..9ce4607 100644
--- a/data/ui/preferences-page-input.ui
+++ b/data/ui/preferences-page-input.ui
@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="GamesPreferencesPageInput" parent="GtkBin">
+ <template class="GamesPreferencesPageInput" parent="GtkStack">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="visible-child">main_stack_child_holder</property>
+ <property name="transition-type">GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT</property>
<child>
- <object class="GtkScrolledWindow">
+ <object class="GtkBox" id="extra_stack_child_holder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="name">extra_stack_child</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="main_stack_child_holder">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
@@ -48,6 +59,9 @@
</object>
</child>
</object>
+ <packing>
+ <property name="name">main_stack_child</property>
+ </packing>
</child>
</template>
</interface>
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index 2155447..3a07a80 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -1,7 +1,9 @@
// This file is part of GNOME Games. License: GPL-3.0+.
[GtkTemplate (ui = "/org/gnome/Games/ui/gamepad-mapper.ui")]
-private class Games.GamepadMapper : Gtk.Dialog {
+private class Games.GamepadMapper : Gtk.Box {
+ public signal void back ();
+
private enum State {
BEGIN,
CONFIGURE,
@@ -18,16 +20,16 @@ private class Games.GamepadMapper : Gtk.Dialog {
switch (value) {
case State.BEGIN:
- set_response_sensitive (Gtk.ResponseType.APPLY, false);
- header_bar.set_title (_("Configuring ") + gamepad.name);
+ apply_button.set_sensitive (false);
+ title.label = _("Configuring ") + gamepad.name;
connect_to_gamepad ();
break;
case State.CONFIGURE:
break;
case State.FINISH:
- set_response_sensitive (Gtk.ResponseType.APPLY, true);
- header_bar.set_title (_("Finished configuration"));
+ apply_button.set_sensitive (true);
+ title.label = _("Finished configuration");
disconnect_from_gamepad ();
break;
@@ -74,30 +76,36 @@ private class Games.GamepadMapper : Gtk.Dialog {
private Gtk.Label error_message;
[GtkChild]
private GamepadView gamepad_view;
- private Gtk.HeaderBar header_bar;
+ [GtkChild]
+ public Gtk.Box header_content;
+ [GtkChild]
+ private Gtk.Button apply_button;
+ [GtkChild]
+ private Gtk.Label title;
private Gamepad gamepad;
private GamepadMappingBuilder mapping_builder;
private ulong gamepad_event_handler_id;
- construct {
- use_header_bar = 1;
- header_bar = (Gtk.HeaderBar) get_header_bar ();
- }
-
public GamepadMapper (Gamepad gamepad) {
this.gamepad = gamepad;
mapping_builder = new GamepadMappingBuilder ();
+ state = State.BEGIN;
}
public void start () {
- state = State.BEGIN;
-
next_input ();
+ }
+
+ [GtkCallback]
+ private void on_apply_clicked () {
+ save_sdl_string ();
+ back ();
+ }
- var response = run ();
- if (response == Gtk.ResponseType.APPLY)
- save_sdl_string ();
+ [GtkCallback]
+ private void on_back_clicked () {
+ back ();
}
private void connect_to_gamepad () {
diff --git a/src/ui/preferences-page-input.vala b/src/ui/preferences-page-input.vala
index 35170a7..8182d28 100644
--- a/src/ui/preferences-page-input.vala
+++ b/src/ui/preferences-page-input.vala
@@ -1,7 +1,7 @@
// This file is part of GNOME Games. License: GPL-3.0+.
[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-input.ui")]
-private class Games.PreferencesPageInput: Gtk.Bin, PreferencesPage {
+private class Games.PreferencesPageInput: Gtk.Stack, PreferencesPage {
private Gtk.Widget _header_content;
public Gtk.Widget header_content {
get { return _header_content; }
@@ -10,10 +10,14 @@ private class Games.PreferencesPageInput: Gtk.Bin, PreferencesPage {
[GtkChild]
private Gtk.ListBox gamepads_list_box;
+ [GtkChild]
+ private Gtk.Box extra_stack_child_holder;
private GamepadMonitor gamepad_monitor;
+ private Gtk.Label default_label;
construct {
- header_content = new Gtk.Label (_("Input"));
+ default_label = new Gtk.Label (_("Input"));
+ header_content = default_label;
header_content.visible = true;
gamepad_monitor = GamepadMonitor.get_instance ();
@@ -57,10 +61,17 @@ private class Games.PreferencesPageInput: Gtk.Bin, PreferencesPage {
if (gamepad == null)
return;
-
var mapper = new GamepadMapper(gamepad);
- mapper.set_transient_for ((Gtk.Window) get_toplevel ());
+ mapper.back.connect (on_mapper_back);
+ header_content = mapper.header_content;
+ extra_stack_child_holder.pack_start (mapper);
+ set_visible_child_name ("extra_stack_child");
mapper.start ();
- mapper.destroy ();
+ }
+
+ private void on_mapper_back () {
+ header_content = default_label;
+ set_visible_child_name ("main_stack_child");
+ extra_stack_child_holder.foreach ((child) => child.destroy ());
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]