aboutsummaryrefslogtreecommitdiff
path: root/src/idoscalemenuitem.c
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-04-08 12:01:15 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-04-08 12:01:15 +0200
commitde33725f77591fac4988789a6409bb9c25667be1 (patch)
tree4dfe693056ddd5cd7bd9a1dfee57c445ed29e88c /src/idoscalemenuitem.c
parent13402a2cc4616b4b5f4244413599e635fcfc1401 (diff)
parent451a9efbccc57c46122c3349abeea423ab1e576c (diff)
downloadayatana-ido-de33725f77591fac4988789a6409bb9c25667be1.tar.gz
ayatana-ido-de33725f77591fac4988789a6409bb9c25667be1.tar.bz2
ayatana-ido-de33725f77591fac4988789a6409bb9c25667be1.zip
Merge branch 'tari01-pr/expand-scale'
Attributes GH PR #69: https://github.com/AyatanaIndicators/ayatana-ido/pull/69
Diffstat (limited to 'src/idoscalemenuitem.c')
-rw-r--r--src/idoscalemenuitem.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c
index 37a9385..c6cf877 100644
--- a/src/idoscalemenuitem.c
+++ b/src/idoscalemenuitem.c
@@ -1,6 +1,6 @@
/*
* Copyright 2010 Canonical, Ltd.
- * Copyright 2021 Robert Tari
+ * Copyright 2021-2024 Robert Tari
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
@@ -26,6 +26,7 @@
*/
#include <gtk/gtk.h>
+#include <math.h>
#include "idorange.h"
#include "idoscalemenuitem.h"
#include "idotypebuiltins.h"
@@ -701,7 +702,7 @@ ido_scale_menu_item_new_with_range (const gchar *label,
gdouble max,
gdouble step)
{
- GObject *adjustment = G_OBJECT (gtk_adjustment_new (value, min, max, step, 10 * step, 0));
+ GObject *adjustment = G_OBJECT (gtk_adjustment_new (value, min, max, step, step, 0));
return GTK_WIDGET (g_object_new (IDO_TYPE_SCALE_MENU_ITEM,
"label", label,
@@ -1048,6 +1049,13 @@ menu_item_get_icon (GMenuItem *menuitem,
return value ? g_icon_deserialize (value) : NULL;
}
+static gchar* onFormatValue (GtkScale *pScale, gdouble fValue)
+{
+ gint nValue = fValue * 100;
+ gchar *sValue = g_strdup_printf ("%i%%", nValue);
+
+ return sValue;
+}
/**
* ido_scale_menu_item_new_from_model:
*
@@ -1089,6 +1097,31 @@ ido_scale_menu_item_new_from_model (GMenuItem *menuitem,
g_free (action);
}
+ IdoScaleMenuItemPrivate *pPrivate = ido_scale_menu_item_get_instance_private (IDO_SCALE_MENU_ITEM (item));
+ guchar nDigits = 0;
+ gboolean bFound = g_menu_item_get_attribute (menuitem, "digits", "y", &nDigits);
+
+ if (bFound)
+ {
+ gtk_scale_set_digits (GTK_SCALE (pPrivate->scale), nDigits);
+ gtk_range_set_round_digits (GTK_RANGE (pPrivate->scale), nDigits);
+ }
+
+ gboolean bMarks = FALSE;
+ bFound = g_menu_item_get_attribute (menuitem, "marks", "b", &bMarks);
+
+ if (bFound)
+ {
+ gtk_scale_set_draw_value (GTK_SCALE (pPrivate->scale), TRUE);
+
+ for (gdouble fValue = min; fValue < (max + step); fValue += step)
+ {
+ gtk_scale_add_mark (GTK_SCALE (pPrivate->scale), round (fValue * 10) / 10, GTK_POS_BOTTOM, NULL);
+ }
+
+ g_signal_connect (pPrivate->scale, "format-value", G_CALLBACK (onFormatValue), NULL);
+ }
+
min_icon = menu_item_get_icon (menuitem, "min-icon");
max_icon = menu_item_get_icon (menuitem, "max-icon");
ido_scale_menu_item_set_icons (IDO_SCALE_MENU_ITEM (item), min_icon, max_icon);