[gnome-chess/mcatanzaro/gtk4] progress
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/mcatanzaro/gtk4] progress
- Date: Wed, 23 Dec 2020 23:23:39 +0000 (UTC)
commit db44047ed26278642d0e5b455cf6610b54b804e3
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Wed Dec 23 17:23:57 2020 -0600
progress
src/gnome-chess.vala | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 1eacd5d..69fdc63 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1723,9 +1723,58 @@ Copyright © 2015–2016 Sahil Sareen""";
return "∶\xE2\x80\x8E%02d".printf (time);
}
+ /* Compute the largest possible size the timer label might ever want to take.
+ * The size of the characters may vary by font, but one digit will always
+ * be the largest.
+ */
+ private int compute_time_label_width_request (Cairo.Context c)
+ ensures (result > 0)
+ {
+ Cairo.TextExtents extents;
+ double max = 0;
+
+ c.text_extents ("000∶00", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("111∶11", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("222∶22", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("333∶33", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("444∶44", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("555∶55", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("666∶66", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("777∶77", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("888∶88", out extents);
+ max = (max > extents.width ? max : extents.width);
+ c.text_extents ("999∶99", out extents);
+ max = (max > extents.width ? max : extents.width);
+
+ /* Leave a little bit of room to the sides. */
+ return (int) Math.ceil (max) + 6;
+ }
+
private void draw_time (Widget widget, Cairo.Context c, int width, int height, string text, double[] fg,
double[] bg)
{
- c.scale (width, height);
+ /* We need to draw text on our cairo context to properly compute our
+ * required size. But the only place we are able to access the cairo
+ * context is here, the draw function. And we are not allowed to set our
+ * size inside the draw function. So the best we can do is schedule the
+ * size computation and queue draw again when that's done.
+ */
+ if (widget.width_request == -1)
+ {
+ Idle.add(() => {
+ widget.set_size_request (compute_time_label_width_request (c), -1);
+ widget.queue_draw ();
+ return Source.REMOVE;
+ });
+ return;
+ }
double alpha = 1.0;
if ((widget.get_state_flags () & StateFlags.INSENSITIVE) != 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]