[planner: 16/32] charts: Port font width factor updating to GtkStyleContext
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 16/32] charts: Port font width factor updating to GtkStyleContext
- Date: Sun, 20 Jun 2021 18:13:51 +0000 (UTC)
commit 5de6777104cf85f1773e467932a8978fb6e357a2
Author: Mart Raudsepp <leio gentoo org>
Date: Mon May 31 00:17:56 2021 +0300
charts: Port font width factor updating to GtkStyleContext
In the process be more verbose with the static variable name and sync the
different chart code with eachother, adding missing re-layout in one case,
and measuring the correct canvas font in the other case.
src/planner-gantt-chart.c | 31 ++++++++++++-------------------
src/planner-usage-chart.c | 41 +++++++++++++++++++----------------------
2 files changed, 31 insertions(+), 41 deletions(-)
---
diff --git a/src/planner-gantt-chart.c b/src/planner-gantt-chart.c
index 36a12f77..2d69d9b0 100644
--- a/src/planner-gantt-chart.c
+++ b/src/planner-gantt-chart.c
@@ -47,11 +47,11 @@
#define ZOOM_OUT_LIMIT 0
#define DEFAULT_ZOOM_LEVEL 7
-#define SCALE(n) (f*pow(2,(n)-19))
-#define ZOOM(x) (log((x)/f)/log(2)+19)
+#define SCALE(n) (font_width_factor*pow(2,(n)-19))
+#define ZOOM(x) (log((x)/font_width_factor)/log(2)+19)
/* Font width factor. */
-static gdouble f = 1.0;
+static gdouble font_width_factor = 1.0;
#define CRITICAL_PATH_KEY "highlight-critical-path"
#define NOSTDDAYS_PATH_KEY "display-nonstandard-days"
@@ -151,8 +151,7 @@ static void gantt_chart_get_property (GObject *obj
GValue *value,
GParamSpec *pspec);
static void gantt_chart_destroy (GtkWidget *widget);
-static void gantt_chart_style_set (GtkWidget *widget,
- GtkStyle *prev_style);
+static void gantt_chart_style_updated (GtkWidget *widget);
static void gantt_chart_realize (GtkWidget *widget);
static void gantt_chart_unrealize (GtkWidget *widget);
static void gantt_chart_map (GtkWidget *widget);
@@ -277,7 +276,7 @@ gantt_chart_class_init (PlannerGanttChartClass *class)
o_class->finalize = gantt_chart_finalize;
widget_class->destroy = gantt_chart_destroy;
- widget_class->style_set = gantt_chart_style_set;
+ widget_class->style_updated = gantt_chart_style_updated;
widget_class->realize = gantt_chart_realize;
widget_class->map = gantt_chart_map;
widget_class->unrealize = gantt_chart_unrealize;
@@ -537,36 +536,30 @@ gantt_chart_destroy (GtkWidget *widget)
}
static void
-gantt_chart_style_set (GtkWidget *widget,
- GtkStyle *prev_style)
+gantt_chart_style_updated (GtkWidget *widget)
{
PlannerGanttChart *chart;
- PlannerGanttChartPriv *priv;
PangoContext *context;
PangoFontMetrics *metrics;
g_return_if_fail (PLANNER_IS_GANTT_CHART (widget));
- if (GTK_WIDGET_CLASS (parent_class)->style_set) {
- GTK_WIDGET_CLASS (parent_class)->style_set (widget,
- prev_style);
+ if (GTK_WIDGET_CLASS (parent_class)->style_updated) {
+ GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
}
chart = PLANNER_GANTT_CHART (widget);
- priv = chart->priv;
- context = gtk_widget_get_pango_context (widget);
+ context = gtk_widget_get_pango_context (GTK_WIDGET (chart->priv->canvas));
- metrics = pango_context_get_metrics (context,
- gtk_widget_get_style (widget)->font_desc,
- NULL);
+ metrics = pango_context_get_metrics (context, NULL, NULL);
- f = 0.2 * pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
+ font_width_factor = 0.2 * pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
pango_font_metrics_unref(metrics);
/* Re-layout with the new factor. */
- gantt_chart_set_zoom (PLANNER_GANTT_CHART (widget), priv->zoom);
+ gantt_chart_set_zoom (PLANNER_GANTT_CHART (widget), chart->priv->zoom);
}
static void
diff --git a/src/planner-usage-chart.c b/src/planner-usage-chart.c
index 32e3c06d..d88e549c 100644
--- a/src/planner-usage-chart.c
+++ b/src/planner-usage-chart.c
@@ -48,11 +48,11 @@
#define ZOOM_OUT_LIMIT 0
#define DEFAULT_ZOOM_LEVEL 7
-#define SCALE(n) (f*pow(2,(n)-19))
-#define ZOOM(x) (log((x)/f)/log(2)+19)
+#define SCALE(n) (font_width_factor*pow(2,(n)-19))
+#define ZOOM(x) (log((x)/font_width_factor)/log(2)+19)
/* Font width factor. */
-static gdouble f = 1.0;
+static gdouble font_width_factor = 1.0;
typedef struct _TreeNode TreeNode;
typedef void (*TreeFunc) (TreeNode *node, gpointer data);
@@ -130,8 +130,7 @@ static void usage_chart_get_property (GObject *obj
static void usage_chart_set_zoom (PlannerUsageChart *chart,
gdouble level);
static void usage_chart_destroy (GtkWidget *widget);
-static void usage_chart_style_set (GtkWidget *widget,
- GtkStyle *prev_style);
+static void usage_chart_style_updated (GtkWidget *widget);
static void usage_chart_realize (GtkWidget *widget);
static void usage_chart_map (GtkWidget *widget);
static void usage_chart_unrealize (GtkWidget *widget);
@@ -258,7 +257,7 @@ usage_chart_class_init (PlannerUsageChartClass * class)
o_class->finalize = usage_chart_finalize;
widget_class->destroy = usage_chart_destroy;
- widget_class->style_set = usage_chart_style_set;
+ widget_class->style_updated = usage_chart_style_updated;
widget_class->realize = usage_chart_realize;
widget_class->map = usage_chart_map;
widget_class->unrealize = usage_chart_unrealize;
@@ -652,30 +651,28 @@ usage_chart_destroy (GtkWidget *widget)
}
static void
-usage_chart_style_set (GtkWidget *widget, GtkStyle *prev_style)
+usage_chart_style_updated (GtkWidget *widget)
{
- PlannerUsageChart *chart;
- PlannerUsageChartPriv *priv;
- GtkWidget *canvas;
- PangoContext *context;
- PangoFontMetrics *metrics;
+ PlannerUsageChart *chart;
+ PangoContext *context;
+ PangoFontMetrics *metrics;
- if (GTK_WIDGET_CLASS (parent_class)->style_set) {
- GTK_WIDGET_CLASS (parent_class)->style_set (widget,
- prev_style);
+ if (GTK_WIDGET_CLASS (parent_class)->style_updated) {
+ GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
}
chart = PLANNER_USAGE_CHART (widget);
- priv = chart->priv;
- canvas = GTK_WIDGET (priv->canvas);
+ context = gtk_widget_get_pango_context (GTK_WIDGET (chart->priv->canvas));
+
+ metrics = pango_context_get_metrics (context, NULL, NULL);
+
+ font_width_factor = 0.2 * pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
- context = gtk_widget_get_pango_context (canvas);
- metrics = pango_context_get_metrics (context,
- gtk_widget_get_style (canvas)->font_desc, NULL);
- f = 0.2 * pango_font_metrics_get_approximate_char_width (metrics) /
- PANGO_SCALE;
pango_font_metrics_unref(metrics);
+
+ /* Re-layout with the new factor. */
+ usage_chart_set_zoom (PLANNER_USAGE_CHART (widget), chart->priv->zoom);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]