From 95be96d27efe655d7e73cc4f48a5fb1b54df3c94 Mon Sep 17 00:00:00 2001 From: MoonlightWave-12 <135532-MoonlightWave-12@users.noreply.gitlab.gnome.org> Date: Wed, 25 Sep 2024 15:03:43 +0200 Subject: [PATCH] scaling: Keep proportions of labels and icons when stretching layouts Before this change, the labels and icons were stretched along with the layout. Part-of: --- eek/eek-renderer.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index 57f582d7..7acd4022 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -56,13 +56,20 @@ render_outline (cairo_t *cr, position.x, position.y, position.width, position.height); } -float get_scale(cairo_t *cr) { +double get_scale_width(cairo_t *cr) { double width = 1; double height = 1; cairo_user_to_device_distance (cr, &width, &height); return width; } +double get_scale_height(cairo_t *cr) { + double width = 1; + double height = 1; + cairo_user_to_device_distance (cr, &width, &height); + return height; +} + /// Rust interface void eek_render_button_in_context(uint32_t scale_factor, cairo_t *cr, @@ -79,11 +86,15 @@ void eek_render_button_in_context(uint32_t scale_factor, /* render icon (if any) */ if (icon_name) { - int context_scale = ceil (get_scale (cr)); + int context_scale = ceil (get_scale_width (cr)); + + double scale_x = get_scale_width (cr); + double scale_y = get_scale_height (cr); + cairo_surface_t *icon_surface = eek_renderer_get_icon_surface (icon_name, 16, scale_factor * context_scale); if (icon_surface) { - double width = cairo_image_surface_get_width (icon_surface); + double width = cairo_image_surface_get_width (icon_surface) * scale_y / scale_x ; double height = cairo_image_surface_get_height (icon_surface); cairo_save (cr); @@ -96,6 +107,9 @@ void eek_render_button_in_context(uint32_t scale_factor, GdkRGBA color = {0}; gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &color); + // Unstretch icons, when the layout is stretched. + cairo_scale (cr, scale_y / scale_x, 1.0); + cairo_set_source_rgba (cr, color.red, color.green, color.blue, @@ -190,6 +204,13 @@ render_button_label (cairo_t *cr, GdkRGBA color = {0}; gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &color); + double scale_x = get_scale_width (cr); + double scale_y = get_scale_height (cr); + + // Unstretch labels, when the layout is stretched. + cairo_scale (cr, scale_y / scale_x, 1.0); + pango_cairo_update_layout (cr, layout); + cairo_set_source_rgba (cr, color.red, color.green,