[gnome-games/wip/abhinavsingh/gamepad-config: 15/23] ui: Use stack in gamepad prefs page for mapper
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 15/23] ui: Use stack in gamepad prefs page for mapper
- Date: Tue, 20 Jun 2017 20:52:52 +0000 (UTC)
commit 26e1eef3408c2365443f86b6ceb75fff7bea3de6
Author: theawless <theawless gmail com>
Date: Sat Jun 3 16:25:48 2017 +0530
ui: Use stack in gamepad prefs page for mapper
Showing mapper as a dialog resulted in three windows on the screen which
is against HIG recommendation. This commit changes the
PreferencesPageGamepads to use stack and converts GamepadMapper to box.
data/ui/gamepad-mapper.ui | 100 ++++++++++++++++++++------------
data/ui/preferences-page-gamepads.ui | 18 +++++-
src/ui/gamepad-mapper.vala | 40 ++++++++-----
src/ui/preferences-page-gamepads.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-gamepads.ui b/data/ui/preferences-page-gamepads.ui
index d652219..78a98f1 100644
--- a/data/ui/preferences-page-gamepads.ui
+++ b/data/ui/preferences-page-gamepads.ui
@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="GamesPreferencesPageGamepads" parent="GtkBin">
+ <template class="GamesPreferencesPageGamepads" parent="GtkStack">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="visible-child">gamepads_list_holder</property>
+ <property name="transition-type">GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT</property>
<child>
- <object class="GtkScrolledWindow">
+ <object class="GtkBox" id="gamepad_mapper_holder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="name">gamepad_mapper</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="gamepads_list_holder">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
@@ -48,6 +59,9 @@
</object>
</child>
</object>
+ <packing>
+ <property name="name">gamepads_list</property>
+ </packing>
</child>
</template>
</interface>
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index 23a8c0d..b36216e 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 (gamepad);
+ 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-gamepads.vala b/src/ui/preferences-page-gamepads.vala
index 47d45ea..24e48a5 100644
--- a/src/ui/preferences-page-gamepads.vala
+++ b/src/ui/preferences-page-gamepads.vala
@@ -1,7 +1,7 @@
// This file is part of GNOME Games. License: GPL-3.0+.
[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-gamepads.ui")]
-private class Games.PreferencesPageGamepads: Gtk.Bin, PreferencesPage {
+private class Games.PreferencesPageGamepads: Gtk.Stack, PreferencesPage {
private Gtk.Widget _header_content;
public Gtk.Widget header_content {
get { return _header_content; }
@@ -10,10 +10,14 @@ private class Games.PreferencesPageGamepads: Gtk.Bin, PreferencesPage {
[GtkChild]
private Gtk.ListBox gamepads_list_box;
+ [GtkChild]
+ private Gtk.Box gamepad_mapper_holder;
private GamepadMonitor gamepad_monitor;
+ private Gtk.Label default_label;
construct {
- header_content = new Gtk.Label (_("Gamepads"));
+ default_label = new Gtk.Label (_("Gamepads"));
+ header_content = default_label;
header_content.visible = true;
gamepad_monitor = GamepadMonitor.get_instance ();
@@ -57,10 +61,17 @@ private class Games.PreferencesPageGamepads: 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;
+ gamepad_mapper_holder.pack_start (mapper);
+ set_visible_child_name ("gamepad_mapper");
mapper.start ();
- mapper.destroy ();
+ }
+
+ private void on_mapper_back () {
+ header_content = default_label;
+ set_visible_child_name ("gamepads_list");
+ gamepad_mapper_holder.foreach ((child) => child.destroy ());
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]