[gnome-games/wip/exalm/ds: 10/15] nintendo-ds: Use NintendoDsLayout for UI
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/ds: 10/15] nintendo-ds: Use NintendoDsLayout for UI
- Date: Wed, 14 Aug 2019 11:46:56 +0000 (UTC)
commit a8ebc37c02c537648462d3aa590b73897e0e3e4f
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed Aug 14 01:51:05 2019 +0500
nintendo-ds: Use NintendoDsLayout for UI
Simplify the UI before reducing GSettings usage to avoid passing strings
around.
.../nintendo-ds/src/nintendo-ds-layout-item.vala | 18 ++---
.../src/nintendo-ds-layout-switcher.vala | 76 +++-------------------
plugins/nintendo-ds/src/nintendo-ds-runner.vala | 14 ++--
3 files changed, 26 insertions(+), 82 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-layout-item.vala
b/plugins/nintendo-ds/src/nintendo-ds-layout-item.vala
index 34837291..09b969c1 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-layout-item.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-item.vala
@@ -9,21 +9,21 @@ private class Games.NintendoDsLayoutItem : Gtk.ListBoxRow {
[GtkChild]
private Gtk.Label subtitle;
- private string layout;
+ public NintendoDsLayout layout { get; construct; }
- public NintendoDsLayoutItem (string layout, string title, string? subtitle, string icon) {
- this.layout = layout;
+ public NintendoDsLayoutItem (NintendoDsLayout layout) {
+ Object (layout: layout);
+ }
- this.icon.icon_name = icon;
- this.title.label = title;
+ public override void constructed () {
+ this.icon.icon_name = layout.get_icon ();
+ this.title.label = layout.get_title ();
if (subtitle != null) {
- this.subtitle.label = subtitle;
+ this.subtitle.label = layout.get_subtitle ();
this.subtitle.show ();
}
- }
- public string get_layout () {
- return layout;
+ base.constructed ();
}
}
diff --git a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
index 0e8220f9..6f88b4be 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-layout-switcher.vala
@@ -14,14 +14,7 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
private Gtk.ListBox list_box;
private Settings settings;
- private HashTable<string, NintendoDsLayoutItem> items;
-
- private string[] LAYOUTS = {
- "top/bottom",
- "left/right",
- "right/left",
- "quick switch",
- };
+ private HashTable<NintendoDsLayout, NintendoDsLayoutItem> items;
static construct {
var icon_theme = Gtk.IconTheme.get_default ();
@@ -29,15 +22,11 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
}
construct {
- items = new HashTable<string, NintendoDsLayoutItem> (str_hash, str_equal);
- foreach (string layout in LAYOUTS) {
- string icon = get_layout_icon (layout);
- string title = get_layout_title (layout);
- string subtitle = get_layout_subtitle (layout);
+ items = new HashTable<NintendoDsLayout, NintendoDsLayoutItem> (direct_hash, direct_equal);
+ foreach (var layout in NintendoDsLayout.get_layouts ()) {
+ var item = new NintendoDsLayoutItem (layout);
- var item = new NintendoDsLayoutItem (layout, title, subtitle, icon);
items[layout] = item;
-
list_box.add (item);
}
@@ -50,15 +39,16 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
}
private void update_ui () {
- var layout = settings.get_string ("screen-layout");
+ var layout_value = settings.get_string ("screen-layout");
var view_bottom = settings.get_boolean ("view-bottom-screen");
- layout_image.icon_name = get_layout_icon (layout);
+ var layout = NintendoDsLayout.from_value (layout_value);
+ layout_image.icon_name = layout.get_icon ();
var item = items[layout];
list_box.select_row (item);
- change_screen_revealer.reveal_child = (layout == "quick switch");
+ change_screen_revealer.reveal_child = (layout == NintendoDsLayout.QUICK_SWITCH);
change_screen_image.icon_name = view_bottom ? "view-top-screen-symbolic" :
"view-bottom-screen-symbolic-symbolic";
}
@@ -73,56 +63,10 @@ private class Games.NintendoDsLayoutSwitcher : Gtk.Box {
private void on_row_activated (Gtk.ListBoxRow row) {
var layout_item = row as NintendoDsLayoutItem;
- var layout = layout_item.get_layout ();
+ var layout = layout_item.layout;
- settings.set_string ("screen-layout", layout);
+ settings.set_string ("screen-layout", layout.get_value ());
layout_popover.popdown ();
}
-
- 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_title (string layout) {
- switch (layout) {
- case "top/bottom":
- return _("Vertical");
-
- case "left/right":
- case "right/left":
- return _("Side by side");
-
- case "quick switch":
- return _("Single screen");
- }
-
- return _("Unknown");
- }
-
- private string? get_layout_subtitle (string layout) {
- switch (layout) {
- case "left/right":
- return _("Bottom to the right");
-
- case "right/left":
- return _("Bottom to the left");
- }
-
- return null;
- }
}
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 2bfa91be..8157fe3e 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -5,17 +5,17 @@ private class Games.NintendoDsRunner : RetroRunner {
private ulong settings_changed_id;
// Map the 1,2,3,4 key values to the 4 screen layouts of the Nintendo DS
- private static HashTable<uint, string> layouts;
+ private static HashTable<uint, NintendoDsLayout?> layouts;
private const string SCREENS_LAYOUT_OPTION = "desmume_screens_layout";
static construct {
- layouts = new HashTable<uint, string> (direct_hash, direct_equal);
+ layouts = new HashTable<uint, NintendoDsLayout?> (direct_hash, direct_equal);
- layouts[Gdk.Key.@1] = "top/bottom";
- layouts[Gdk.Key.@2] = "left/right";
- layouts[Gdk.Key.@3] = "right/left";
- layouts[Gdk.Key.@4] = "quick switch";
+ layouts[Gdk.Key.@1] = NintendoDsLayout.TOP_BOTTOM;
+ layouts[Gdk.Key.@2] = NintendoDsLayout.LEFT_RIGHT;
+ layouts[Gdk.Key.@3] = NintendoDsLayout.RIGHT_LEFT;
+ layouts[Gdk.Key.@4] = NintendoDsLayout.QUICK_SWITCH;
}
construct {
@@ -93,7 +93,7 @@ private class Games.NintendoDsRunner : RetroRunner {
var shortcut_layout = layouts[event.keyval];
if (shortcut_layout != null) {
- settings.set_string ("screen-layout", shortcut_layout);
+ settings.set_string ("screen-layout", shortcut_layout.get_value ());
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]