From eca365c60f14037b08c4b365a3664598a3eb2982 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Thu, 8 Feb 2024 07:04:36 +0100 Subject: [PATCH] AndroidLayout: set minimum sizes correctly This is needed for GtkScrolledWindow, which we still use for implementing ScrollView --- src/api-impl-jni/views/AndroidLayout.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/api-impl-jni/views/AndroidLayout.c b/src/api-impl-jni/views/AndroidLayout.c index 0e39d9f0..c54e7f36 100644 --- a/src/api-impl-jni/views/AndroidLayout.c +++ b/src/api-impl-jni/views/AndroidLayout.c @@ -20,12 +20,14 @@ static int make_measure_spec(int layout_size, int for_size) static void android_layout_measure(GtkLayoutManager *layout_manager, GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum, int *natural, int *minimum_baseline, int *natural_baseline) { + int widthMeasureSpec = 0; + int heightMeasureSpec = 0; AndroidLayout *layout = ATL_ANDROID_LAYOUT(layout_manager); JNIEnv *env = get_jni_env(); if (layout->width || layout->height) { - int widthMeasureSpec = make_measure_spec(layout->width, orientation == GTK_ORIENTATION_VERTICAL ? for_size : -1); - int heightMeasureSpec = make_measure_spec(layout->height, orientation == GTK_ORIENTATION_HORIZONTAL ? for_size : -1); + widthMeasureSpec = make_measure_spec(layout->width, orientation == GTK_ORIENTATION_VERTICAL ? for_size : -1); + heightMeasureSpec = make_measure_spec(layout->height, orientation == GTK_ORIENTATION_HORIZONTAL ? for_size : -1); // if layout params say match_parent, but GTK doesnt specify the dimension, fallback to old specification if available if (widthMeasureSpec == -1) @@ -42,12 +44,14 @@ static void android_layout_measure(GtkLayoutManager *layout_manager, GtkWidget * } if (orientation == GTK_ORIENTATION_HORIZONTAL) { - *minimum = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumWidth); *natural = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getMeasuredWidth); + *minimum = heightMeasureSpec && !widthMeasureSpec ? *natural + : (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumWidth); } if (orientation == GTK_ORIENTATION_VERTICAL) { - *minimum = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumHeight); *natural = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getMeasuredHeight); + *minimum = widthMeasureSpec && !heightMeasureSpec ? *natural + :(*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumHeight); } if (*natural < *minimum) *natural = *minimum;