summaryrefslogtreecommitdiffstats
path: root/src/gs-review-bar.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:18:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:18:46 +0000
commit56294d30a82ec2da6f9ce399740c1ef65a9ddef4 (patch)
treebbe3823e41495d026ba8edc6eeaef166edb7e2a2 /src/gs-review-bar.c
parentInitial commit. (diff)
downloadgnome-software-56294d30a82ec2da6f9ce399740c1ef65a9ddef4.tar.xz
gnome-software-56294d30a82ec2da6f9ce399740c1ef65a9ddef4.zip
Adding upstream version 3.38.1.upstream/3.38.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/gs-review-bar.c')
-rw-r--r--src/gs-review-bar.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/gs-review-bar.c b/src/gs-review-bar.c
new file mode 100644
index 0000000..4f58c83
--- /dev/null
+++ b/src/gs-review-bar.c
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2016 Canonical Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "gs-review-bar.h"
+
+struct _GsReviewBar
+{
+ GtkBin parent_instance;
+ gdouble fraction;
+};
+
+G_DEFINE_TYPE (GsReviewBar, gs_review_bar, GTK_TYPE_BIN)
+
+void
+gs_review_bar_set_fraction (GsReviewBar *bar, gdouble fraction)
+{
+ g_return_if_fail (GS_IS_REVIEW_BAR (bar));
+ bar->fraction = fraction;
+}
+
+static void
+gs_review_bar_init (GsReviewBar *bar)
+{
+}
+
+static gboolean
+gs_review_bar_draw (GtkWidget *widget, cairo_t *cr)
+{
+ GtkStyleContext *context;
+ gdouble y_offset, bar_height;
+ GdkRGBA color;
+
+ context = gtk_widget_get_style_context (widget);
+
+ /* don't fill the complete height (too heavy beside GtkLabel of that height) */
+ y_offset = floor (0.15 * gtk_widget_get_allocated_height (widget));
+ bar_height = gtk_widget_get_allocated_height (widget) - (y_offset * 2);
+
+ gtk_render_background (context, cr,
+ 0, y_offset,
+ gtk_widget_get_allocated_width (widget),
+ bar_height);
+
+ cairo_rectangle (cr,
+ 0, y_offset,
+ round (GS_REVIEW_BAR (widget)->fraction * gtk_widget_get_allocated_width (widget)),
+ bar_height);
+ gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color);
+ cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
+ cairo_fill (cr);
+
+ return GTK_WIDGET_CLASS (gs_review_bar_parent_class)->draw (widget, cr);
+}
+
+static void
+gs_review_bar_class_init (GsReviewBarClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ widget_class->draw = gs_review_bar_draw;
+}
+
+GtkWidget *
+gs_review_bar_new (void)
+{
+ GsReviewBar *bar;
+ bar = g_object_new (GS_TYPE_REVIEW_BAR, NULL);
+ return GTK_WIDGET (bar);
+}