Skip to content

Commit

Permalink
compact view: Improve text and selection highlight alignment.
Browse files Browse the repository at this point in the history
The smallest zoom level with text is slightly off still due to
rounding error and the fact that the text is at that point taller
than the icon, but this would take quite a bit more refactoring
to fully address.

Fixes #3276
  • Loading branch information
mtwebster committed Jul 26, 2023
1 parent 1ae5a6d commit 90cf6c6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions libnemo-private/nemo-icon-canvas-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ compute_text_rectangle (const NemoIconCanvasItem *item,
} else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM) {
real_text_height = text_height_for_entire_text;
} else if (usage == BOUNDS_USAGE_FOR_DISPLAY) {
real_text_height = text_height;
real_text_height = text_height_for_layout;
} else {
g_assert_not_reached ();
}
Expand Down Expand Up @@ -982,14 +982,18 @@ measure_label_text (NemoIconCanvasItem *item)

/* add some extra space for highlighting even when we don't highlight so things won't move */

/* extra slop for nicer highlighting */
details->text_height += TEXT_BACK_PADDING_Y*2;
details->text_height_for_layout += TEXT_BACK_PADDING_Y*2;
details->text_height_for_entire_text += TEXT_BACK_PADDING_Y*2;
details->editable_text_height += TEXT_BACK_PADDING_Y*2;

/* extra to make it look nicer */
details->text_width += TEXT_BACK_PADDING_X*2;
if (IS_COMPACT_VIEW (container)) {
details->text_width += TEXT_BACK_PADDING_X;
details->text_height_for_layout += TEXT_BACK_PADDING_Y*2;
} else {
/* extra slop for nicer highlighting */
details->text_height += TEXT_BACK_PADDING_Y*2;
details->text_height_for_layout += TEXT_BACK_PADDING_Y*2;
details->text_height_for_entire_text += TEXT_BACK_PADDING_Y*2;
details->editable_text_height += TEXT_BACK_PADDING_Y*2;
/* extra to make it look nicer */
details->text_width += TEXT_BACK_PADDING_X*2;
}

if (editable_layout) {
g_object_unref (editable_layout);
Expand All @@ -1014,7 +1018,7 @@ draw_label_text (NemoIconCanvasItem *item,
gboolean have_editable, have_additional;
gboolean needs_highlight, prelight_label, is_rtl_label_beside;
EelIRect text_rect;
int x;
int x, y;
int max_text_width;
gdouble frame_w, frame_h, frame_x, frame_y;
gboolean draw_frame = TRUE;
Expand Down Expand Up @@ -1096,8 +1100,10 @@ draw_label_text (NemoIconCanvasItem *item,

if (container->details->label_position == NEMO_ICON_LABEL_POSITION_BESIDE) {
x = text_rect.x0 + 2;
y = text_rect.y0;
} else {
x = text_rect.x0 + ((text_rect.x1 - text_rect.x0) - max_text_width) / 2;
y = text_rect.y0 + TEXT_TOP_GAP;
}

if (have_editable &&
Expand All @@ -1119,7 +1125,7 @@ draw_label_text (NemoIconCanvasItem *item,
gtk_style_context_set_state (context, state);

gtk_render_layout (context, cr,
x, text_rect.y0 + TEXT_TOP_GAP,
x, y,
editable_layout);

gtk_style_context_restore (context);
Expand All @@ -1141,7 +1147,7 @@ draw_label_text (NemoIconCanvasItem *item,
gtk_style_context_add_class (context, "dim-label");

gtk_render_layout (context, cr,
x, text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_TOP_GAP,
x, y + details->editable_text_height + LABEL_LINE_SPACING,
additional_layout);
gtk_style_context_restore (context);
}
Expand Down

0 comments on commit 90cf6c6

Please sign in to comment.