[gnome-chess] Switch between narrow and normal views.
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Switch between narrow and normal views.
- Date: Wed, 25 Sep 2019 19:13:53 +0000 (UTC)
commit 8e1095bb551ff1636406c4f2dc95b7941f325673
Author: Brian Daniels <brianddaniels gmail com>
Date: Sun Sep 8 12:27:59 2019 -0500
Switch between narrow and normal views.
At 500px window width, the bottom controlls will split into two rows.
src/gnome-chess.vala | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 9d4095c..35d3cd4 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -13,6 +13,12 @@
public class ChessApplication : Gtk.Application
{
+ private enum LayoutMode {
+ NORMAL,
+ NARROW
+ }
+ private LayoutMode layout_mode;
+
private bool is_tiled;
private bool is_maximized;
private int window_width;
@@ -25,6 +31,7 @@ public class ChessApplication : Gtk.Application
private ChessScene scene;
private ChessView view;
private Gtk.Button pause_resume_button;
+ private Gtk.Box navigation_box;
private Gtk.Widget first_move_button;
private Gtk.Widget prev_move_button;
private Gtk.Widget next_move_button;
@@ -150,9 +157,11 @@ Copyright © 2015–2016 Sahil Sareen""";
window.maximize ();
window.size_allocate.connect (size_allocate_cb);
window.window_state_event.connect (window_state_event_cb);
+ window.configure_event.connect (configure_event_cb);
info_bar = (Gtk.InfoBar) builder.get_object ("info_bar");
pause_resume_button = (Gtk.Button) builder.get_object ("pause_button");
+ navigation_box = (Gtk.Box) builder.get_object ("navigation_box");
first_move_button = (Gtk.Widget) builder.get_object ("first_move_button");
prev_move_button = (Gtk.Widget) builder.get_object ("prev_move_button");
next_move_button = (Gtk.Widget) builder.get_object ("next_move_button");
@@ -256,6 +265,22 @@ Copyright © 2015–2016 Sahil Sareen""";
settings.set_boolean ("maximized", is_maximized);
}
+ private void set_layout_mode(LayoutMode new_layout_mode)
+ {
+ if (layout_mode == new_layout_mode)
+ return;
+ layout_mode = new_layout_mode;
+
+ Gtk.Orientation orientation;
+
+ if (layout_mode == LayoutMode.NORMAL)
+ orientation = Gtk.Orientation.HORIZONTAL;
+ else
+ orientation = Gtk.Orientation.VERTICAL;
+
+ navigation_box.set_orientation(orientation);
+ }
+
private void size_allocate_cb (Gtk.Allocation allocation)
{
if (is_maximized || is_tiled)
@@ -273,6 +298,15 @@ Copyright © 2015–2016 Sahil Sareen""";
return false;
}
+ private bool configure_event_cb (Gdk.EventConfigure event)
+ {
+ if (event.width <= 500 && layout_mode == LayoutMode.NORMAL)
+ set_layout_mode(LayoutMode.NARROW);
+ else if (event.width > 500 && layout_mode == LayoutMode.NARROW)
+ set_layout_mode(LayoutMode.NORMAL);
+ return Gdk.EVENT_PROPAGATE;
+ }
+
public PieceType? show_promotion_type_selector ()
{
Gtk.Builder promotion_type_selector_builder = new Gtk.Builder.from_resource
("/org/gnome/Chess/ui/promotion-type-selector.ui");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]