[gnome-games/wip/exalm/ds-popover: 11/16] nintendo-ds: Add NintendoDsLayoutSwitcher
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/ds-popover: 11/16] nintendo-ds: Add NintendoDsLayoutSwitcher
- Date: Fri, 18 Jan 2019 22:09:59 +0000 (UTC)
commit bbaff2abbdb3695bb99bcef0a4e52d4ee30a1f82
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Jan 6 20:48:44 2019 +0500
nintendo-ds: Add NintendoDsLayoutSwitcher
Provides a popover to switch between available screen modes and a separate
button to swap screens in quick switch mode.
plugins/nintendo-ds/data/nintendo-ds.gresource.xml | 1 +
.../data/ui/nintendo-ds-layout-switcher.ui | 73 +++++++++++++
plugins/nintendo-ds/src/meson.build | 1 +
.../src/nintendo-ds-layout-switcher.vala | 115 +++++++++++++++++++++
4 files changed, 190 insertions(+)
---
diff --git a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
index 179e7203..135d986e 100644
--- a/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
+++ b/plugins/nintendo-ds/data/nintendo-ds.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/Games/plugins/nintendo-ds">
<file>ui/nintendo-ds-layout-item.ui</file>
+ <file>ui/nintendo-ds-layout-switcher.ui</file>
<file>icons/screen-layout-left-right-symbolic.svg</file>
<file>icons/screen-layout-quick-switch-symbolic.svg</file>
<file>icons/screen-layout-right-left-symbolic.svg</file>
diff --git a/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
new file mode 100644
index 00000000..bc02fac9
--- /dev/null
+++ b/plugins/nintendo-ds/data/ui/nintendo-ds-layout-switcher.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.16"/>
+ <template class="GamesNintendoDsLayoutSwitcher" parent="GtkBox">
+ <property name="visible">True</property>
+
+ <child>
+ <object class="GtkRevealer" id="change_screen_revealer">
+ <property name="visible">True</property>
+ <property name="transition-type">slide-left</property>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="margin-right">6</property>
+ <signal name="clicked" handler="on_screen_changed"/>
+ <child internal-child="accessible">
+ <object class="AtkObject">
+ <property name="accessible-name" translatable="yes">Change Screen</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage" id="change_screen_image">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="popover">layout_popover</property>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="a11y-display-discs">
+ <property name="accessible-name" translatable="yes">Screen Layout</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkImage" id="layout_image">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">pan-down-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkPopover" id="layout_popover">
+ <property name="visible">False</property>
+ <child>
+ <object class="GtkFlowBox" id="flow_box">
+ <property name="visible">True</property>
+ <property name="margin">6</property>
+ <property name="homogeneous">True</property>
+ <property name="max-children-per-line">4</property>
+ <signal name="child-activated" handler="on_item_activated"/>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/plugins/nintendo-ds/src/meson.build b/plugins/nintendo-ds/src/meson.build
index 358c0f46..a8713655 100644
--- a/plugins/nintendo-ds/src/meson.build
+++ b/plugins/nintendo-ds/src/meson.build
@@ -1,6 +1,7 @@
vala_sources = [
'nintendo-ds-icon.vala',
'nintendo-ds-layout-item.vala',
+ 'nintendo-ds-layout-switcher.vala',
'nintendo-ds-plugin.vala',
]
diff --git a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
new file mode 100644
index 00000000..48ad9ec7
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -0,0 +1,115 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/plugins/nintendo-ds/ui/nintendo-ds-layout-switcher.ui")]
+private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
+ [GtkChild]
+ private Gtk.Revealer change_screen_revealer;
+ [GtkChild]
+ private Gtk.Image change_screen_image;
+ [GtkChild]
+ private Gtk.Image layout_image;
+ [GtkChild]
+ private Gtk.Popover layout_popover;
+ [GtkChild]
+ private Gtk.FlowBox flow_box;
+
+ private Settings settings;
+ private HashTable<string, NintendoDsLayoutItem> items;
+
+ private string[] LAYOUTS = {
+ "top/bottom",
+ "left/right",
+ "right/left",
+ "quick switch",
+ };
+
+ static construct {
+ var icon_theme = Gtk.IconTheme.get_default ();
+ icon_theme.add_resource_path ("/org/gnome/Games/plugins/nintendo-ds/icons");
+ }
+
+ construct {
+ items = new HashTable<string, NintendoDsLayoutItem> (str_hash, str_equal);
+ foreach (string layout in LAYOUTS) {
+ string name = get_layout_name (layout);
+ string icon = get_layout_icon (layout);
+
+ var item = new NintendoDsLayoutItem (layout, name, icon);
+ items[layout] = item;
+
+ flow_box.add (item);
+ }
+
+ settings = new Settings ("org.gnome.Games.plugins.nintendo-ds");
+ settings.changed.connect (update_ui);
+
+ layout_popover.show.connect (update_ui);
+
+ update_ui ();
+ }
+
+ private void update_ui () {
+ var layout = settings.get_string ("screen-layout");
+ var view_bottom = settings.get_boolean ("view-bottom-screen");
+
+ layout_image.icon_name = get_layout_icon (layout);
+
+ var item = items[layout];
+ flow_box.select_child (item);
+
+ change_screen_revealer.reveal_child = (layout == "quick switch");
+ change_screen_image.icon_name = view_bottom ? "view-top-screen-symbolic" :
"view-bottom-screen-symbolic-symbolic";
+ }
+
+ [GtkCallback]
+ private void on_screen_changed (Gtk.Button button) {
+ var view_bottom = settings.get_boolean ("view-bottom-screen");
+
+ settings.set_boolean ("view-bottom-screen", !view_bottom);
+ }
+
+ [GtkCallback]
+ private void on_item_activated (Gtk.FlowBoxChild child) {
+ var layout_item = child as NintendoDsLayoutItem;
+
+ var layout = layout_item.get_layout ();
+
+ settings.set_string ("screen-layout", layout);
+ }
+
+ private string get_layout_icon (string layout) {
+ switch (layout) {
+ case "top/bottom":
+ return "screen-layout-top-bottom-symbolic";
+
+ case "left/right":
+ return "screen-layout-left-right-symbolic";
+
+ case "right/left":
+ return "screen-layout-right-left-symbolic";
+
+ case "quick switch":
+ return "screen-layout-quick-switch-symbolic";
+ }
+
+ return "video-display-symbolic";
+ }
+
+ private string get_layout_name (string layout) {
+ switch (layout) {
+ case "top/bottom":
+ return _("Top/Bottom");
+
+ case "left/right":
+ return _("Left/Right");
+
+ case "right/left":
+ return _("Right/Left");
+
+ case "quick switch":
+ return _("Quick Switch");
+ }
+
+ return _("Unknown");
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]