GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit a8ebc37c authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko

nintendo-ds: Use NintendoDsLayout for UI

Simplify the UI before reducing GSettings usage to avoid passing strings
around.
parent 94131147
......@@ -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 ();
}
}
......@@ -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;
}
}
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment