[gnome-chess/arnaudb/wip/gtk4: 8/21] Adapt size_allocate().
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/arnaudb/wip/gtk4: 8/21] Adapt size_allocate().
- Date: Wed, 8 Apr 2020 18:06:36 +0000 (UTC)
commit 709106c5ae9f26cff703bce7a3a1971662e2d235
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Apr 7 10:08:48 2020 +0200
Adapt size_allocate().
src/chess-view.vala | 8 ++++----
src/gnome-chess.vala | 19 +++++++------------
2 files changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/src/chess-view.vala b/src/chess-view.vala
index 806ecac..ad685b5 100644
--- a/src/chess-view.vala
+++ b/src/chess-view.vala
@@ -42,20 +42,20 @@ public class ChessView : Gtk.DrawingArea
{
add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK);
+ size_allocate.connect (on_size_allocate);
+
init_mouse ();
}
- public override bool configure_event (Gdk.EventConfigure event)
+ private inline void on_size_allocate (int width, int height)
{
- int short_edge = int.min (get_allocated_width (), get_allocated_height ());
+ int short_edge = int.min (width, height); // TODO width or get_size() result?
square_size = (int) Math.floor ((short_edge - 2 * border) / 9.0);
var extra = square_size * 0.1;
if (extra < 3)
extra = 3;
selected_square_size = square_size + 2 * (int) (extra + 0.5);
-
- return true;
}
private void render_piece (Cairo.Context c1, Cairo.Context c2, string name, int offset)
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 75dbfef..15f52dc 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -159,9 +159,8 @@ Copyright © 2015–2016 Sahil Sareen""";
window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
if (settings.get_boolean ("maximized"))
window.maximize ();
- window.size_allocate.connect (size_allocate_cb);
+ window.size_allocate.connect (on_size_allocate);
window.map.connect (init_state_watcher);
- window.configure_event.connect (configure_event_cb);
info_bar = (InfoBar) builder.get_object ("info_bar");
pause_resume_button = (Button) builder.get_object ("pause_button");
@@ -280,8 +279,13 @@ Copyright © 2015–2016 Sahil Sareen""";
navigation_box.set_orientation ((layout_mode == LayoutMode.NORMAL) ? Orientation.HORIZONTAL :
Orientation.VERTICAL);
}
- private void size_allocate_cb (Allocation allocation)
+ private inline void on_size_allocate (int width, int height)
{
+ if (width <= 500 && layout_mode == LayoutMode.NORMAL) // TODO width or get_size() result?
+ set_layout_mode (LayoutMode.NARROW);
+ else if (width > 500 && layout_mode == LayoutMode.NARROW)
+ set_layout_mode (LayoutMode.NORMAL);
+
if (window_is_maximized || window_is_tiled || window_is_fullscreen)
return;
window.get_size (out window_width, out window_height);
@@ -315,15 +319,6 @@ Copyright © 2015–2016 Sahil Sareen""";
window_is_tiled = (state & tiled_state) != 0;
}
- 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 ()
{
Builder promotion_type_selector_builder = new 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]