[gnome-nibbles/arnaudb/kill-preferences-dialog: 6/8] Fix some warnings.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/kill-preferences-dialog: 6/8] Fix some warnings.
- Date: Thu, 11 Jun 2020 22:58:59 +0000 (UTC)
commit 25035eec27a585da1f633718a7464b4dff351098
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jun 11 17:44:17 2020 +0200
Fix some warnings.
When a key was not configured,
it warned on Controls display.
src/controls.vala | 56 ++++++++++++++++++++++++++-----------------------------
1 file changed, 26 insertions(+), 30 deletions(-)
---
diff --git a/src/controls.vala b/src/controls.vala
index 4622165..773c179 100644
--- a/src/controls.vala
+++ b/src/controls.vala
@@ -71,46 +71,42 @@ private class ControlsGrid : Grid
var player_id = _("Player %d").printf (worm_id + 1);
name_label.set_markup (@"<b><span font-family=\"Sans\" color=\"$(color.to_string
())\">$(player_id)</span></b>");
- arrow_up.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.NONE));
- arrow_down.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.UPSIDEDOWN));
- arrow_left.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.COUNTERCLOCKWISE));
+ arrow_up.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.NONE));
+ arrow_down.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.UPSIDEDOWN));
+ arrow_left.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.COUNTERCLOCKWISE));
arrow_right.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.CLOCKWISE));
- string upper_key;
- upper_key = Gdk.keyval_name (worm_props.up).up ();
- if (upper_key == "UP")
+ configure_label (Gdk.keyval_name (worm_props.up), ref move_up_label);
+ configure_label (Gdk.keyval_name (worm_props.down), ref move_down_label);
+ configure_label (Gdk.keyval_name (worm_props.left), ref move_left_label);
+ configure_label (Gdk.keyval_name (worm_props.right), ref move_right_label);
+ }
+
+ private static void configure_label (string? key_name, ref Label label)
+ {
+ if (key_name == "Up")
{
- move_up_label.get_style_context ().add_class ("arrow");
- move_up_label.set_label ("↑");
+ label.get_style_context ().add_class ("arrow");
+ label.set_text ("↑");
}
- else
- move_up_label.set_label (@"$(upper_key)");
-
- upper_key = Gdk.keyval_name (worm_props.down).up ();
- if (upper_key == "DOWN")
+ else if (key_name == "Down")
{
- move_down_label.get_style_context ().add_class ("arrow");
- move_down_label.set_label ("↓");
+ label.get_style_context ().add_class ("arrow");
+ label.set_text ("↓");
}
- else
- move_down_label.set_label (@"$(upper_key)");
-
- upper_key = Gdk.keyval_name (worm_props.left).up ();
- if (upper_key == "LEFT")
+ else if (key_name == "Left")
{
- move_left_label.get_style_context ().add_class ("arrow");
- move_left_label.set_label ("←");
+ label.get_style_context ().add_class ("arrow");
+ label.set_text ("←");
}
- else
- move_left_label.set_label (@"$(upper_key)");
-
- upper_key = Gdk.keyval_name (worm_props.right).up ();
- if (upper_key == "RIGHT")
+ else if (key_name == "Right")
{
- move_right_label.get_style_context ().add_class ("arrow");
- move_right_label.set_label ("→");
+ label.get_style_context ().add_class ("arrow");
+ label.set_text ("→");
}
+ else if (key_name == null || key_name == "")
+ label.set_text ("");
else
- move_right_label.set_label (@"$(upper_key)");
+ label.set_text (@"$(key_name.up ())");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]