views/week: Cleanup line rendering code

Remove copied style context calls, pass less arguments.
This commit is contained in:
Georges Basile Stavracas Neto
2025-03-19 19:23:58 -03:00
parent 60c2bd2138
commit f9ad1c2e7e
5 changed files with 13 additions and 40 deletions
+3 -16
View File
@@ -618,35 +618,22 @@ gcal_week_grid_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
g_autoptr (GPtrArray) widgets = NULL;
GtkStyleContext *context;
GcalWeekGrid *self;
GtkBorder padding;
GdkRGBA color;
guint i;
gint width, height;
self = GCAL_WEEK_GRID (widget);
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, &color);
gtk_style_context_get_padding (context, &padding);
width = gtk_widget_get_width (widget);
height = gtk_widget_get_height (widget);
gcal_week_view_common_snapshot_hour_lines (widget, snapshot, GTK_ORIENTATION_HORIZONTAL, &color, width, height);
gcal_week_view_common_snapshot_hour_lines (widget, snapshot, GTK_ORIENTATION_VERTICAL, &color, width, height);
gtk_style_context_restore (context);
gcal_week_view_common_snapshot_hour_lines (widget, snapshot, GTK_ORIENTATION_HORIZONTAL, width, height);
gcal_week_view_common_snapshot_hour_lines (widget, snapshot, GTK_ORIENTATION_VERTICAL, width, height);
/* First, draw the selection */
gtk_widget_snapshot_child (widget, self->selection.widget, snapshot);
gtk_widget_snapshot_child (widget, self->dnd.widget, snapshot);
widgets = gcal_range_tree_get_all_data (self->events);
for (i = 0; i < widgets->len; i++)
for (guint i = 0; i < widgets->len; i++)
{
ChildData *child_data = g_ptr_array_index (widgets, i);
+1 -7
View File
@@ -1324,7 +1324,6 @@ gcal_week_header_snapshot (GtkWidget *widget,
GtkStyleContext *context;
GcalWeekHeader *self;
GtkStateFlags state;
GdkRGBA color;
int alloc_width;
int alloc_height;
GDateTime *week_start, *week_end;
@@ -1421,14 +1420,9 @@ gcal_week_header_snapshot (GtkWidget *widget,
width = gtk_widget_get_width (widget) - start_x;
height = gtk_widget_get_height (widget) - start_y;
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, &color);
gtk_style_context_restore (context);
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
gcal_week_view_common_snapshot_hour_lines (widget, snapshot, GTK_ORIENTATION_HORIZONTAL, &color, width, height);
gcal_week_view_common_snapshot_hour_lines (widget, snapshot, GTK_ORIENTATION_HORIZONTAL, width, height);
gtk_snapshot_restore (snapshot);
GTK_WIDGET_CLASS (gcal_week_header_parent_class)->snapshot (widget, snapshot);
+1 -13
View File
@@ -65,25 +65,13 @@ static void
gcal_week_hour_bar_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
GtkStyleContext *context;
GtkWidget *child;
GdkRGBA color;
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, &color);
gtk_style_context_restore (context);
gcal_week_view_common_snapshot_hour_lines (widget,
snapshot,
GTK_ORIENTATION_VERTICAL,
&color,
gtk_widget_get_width (widget),
gtk_widget_get_height (widget));
for (child = gtk_widget_get_first_child (widget);
for (GtkWidget *child = gtk_widget_get_first_child (widget);
child;
child = gtk_widget_get_next_sibling (child))
{
+8 -3
View File
@@ -25,17 +25,22 @@ void
gcal_week_view_common_snapshot_hour_lines (GtkWidget *widget,
GtkSnapshot *snapshot,
GtkOrientation orientation,
const GdkRGBA *line_color,
gint width,
gint height)
{
GtkStyleContext *context;
GdkRGBA color;
gboolean ltr;
gdouble column_width;
guint i;
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
color = *line_color;
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, &color);
gtk_style_context_restore (context);
column_width = width / 7.0;
@@ -63,7 +68,7 @@ gcal_week_view_common_snapshot_hour_lines (GtkWidget *widget,
for (i = 1; i < 24; i++)
{
gtk_snapshot_append_color (snapshot,
line_color,
&color,
&GRAPHENE_RECT_INIT (0.f,
ALIGNED ((height / 24.0) * i),
width,
-1
View File
@@ -27,7 +27,6 @@ G_BEGIN_DECLS
void gcal_week_view_common_snapshot_hour_lines (GtkWidget *widget,
GtkSnapshot *snapshot,
GtkOrientation orientation,
const GdkRGBA *line_color,
gint width,
gint height);