views/month-view-row: Calculate spacings in code
Visually, this comes with the benefit of not having the first and last visible event widgets take additional margins, as spacing is only applied between event widgets. This will also allow us to make use of gtk_widget_pick() without having to rely on hardcoding 1 on the y axis. The current approach has a one pixel margin at the top and bottom of each event widget, which offsets the vertical position of every event widget by one pixel. In order to pick the first event widget, we'd want to call gcal_month_cell_get_header_height() because this is where the first event widget is placed. If we were to invoke gtk_widget_pick() with (x, 0), where x is half the width of the month cell, the returned value would be NULL because gtk_widget_pick() does not account for margins, so it would need to be (x, 1), with 1 hardcoded. Since this patch removes that offset, we can simply use (x, 0) without having to hardcode 1. Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/813>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#define SEPARATOR_OFFSET -1
|
||||
#define EVENT_VERTICAL_GAP 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -595,10 +596,12 @@ prepare_layout_blocks (GcalMonthViewRow *self,
|
||||
for (guint j = 0; j < block->length; j++)
|
||||
{
|
||||
guint cell = block->cell + j;
|
||||
int spacing;
|
||||
|
||||
g_ptr_array_add (blocks_per_day[cell], block);
|
||||
spacing = (blocks_per_day[cell]->len - 1) * EVENT_VERTICAL_GAP;
|
||||
weekday_heights[cell] += block->height;
|
||||
cell_will_overflow[cell] |= weekday_heights[cell] > combined_height[cell];
|
||||
cell_will_overflow[cell] |= weekday_heights[cell] + spacing > combined_height[cell];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -621,7 +624,7 @@ prepare_layout_blocks (GcalMonthViewRow *self,
|
||||
gint available_height;
|
||||
|
||||
if (cell_will_overflow[block_cell])
|
||||
available_height = content_height[block_cell];
|
||||
available_height = content_height[block_cell] - block_cell * EVENT_VERTICAL_GAP;
|
||||
else
|
||||
available_height = combined_height[block_cell];
|
||||
|
||||
@@ -1144,15 +1147,17 @@ gcal_month_view_row_size_allocate (GtkWidget *widget,
|
||||
gint header_height;
|
||||
gint start_cell;
|
||||
gint end_cell;
|
||||
gint spacing;
|
||||
|
||||
block = g_ptr_array_index (blocks, block_index);
|
||||
|
||||
start_cell = is_ltr ? block->cell : N_WEEKDAYS - block->cell - block->length;
|
||||
end_cell = start_cell + block->length;
|
||||
header_height = gcal_month_cell_get_header_height (GCAL_MONTH_CELL (self->day_cells[block->cell]));
|
||||
spacing = (cell_y[block->cell] / block->height - 1) * EVENT_VERTICAL_GAP;
|
||||
|
||||
allocation.x = round (start_cell * cell_width - (is_ltr ? 0 : SEPARATOR_OFFSET));
|
||||
allocation.y = cell_y[block->cell] + header_height;
|
||||
allocation.y = cell_y[block->cell] + header_height + spacing;
|
||||
allocation.width = round (end_cell * cell_width) - allocation.x + (is_ltr ? SEPARATOR_OFFSET : 0);
|
||||
allocation.height = block->height;
|
||||
|
||||
|
||||
@@ -49,3 +49,7 @@ event.slanted-start widget.edge {
|
||||
weekgrid event {
|
||||
margin: 1px;
|
||||
}
|
||||
|
||||
calendar-view.month-view event {
|
||||
margin: 0 1px 0 1px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user