support layout margins

This makes the menu in Gravity Defied not get behind the keyboard.
Also makes the TabLayout in NewPipe not get behing the titlebar.
This commit is contained in:
Julian Winkler
2023-11-08 22:41:46 +01:00
parent 72a8b3a047
commit 36d7a1cc44
4 changed files with 45 additions and 9 deletions

View File

@@ -174,7 +174,8 @@ JNIEXPORT jint JNICALL Java_android_view_View_getHeight(JNIEnv *env, jobject thi
#define MATCH_PARENT (-1)
JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *env, jobject this, jlong widget_ptr, jint width, jint height, jint gravity, jfloat weight)
JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *env, jobject this, jlong widget_ptr, jint width, jint height, jint gravity, jfloat weight,
jint leftMargin, jint topMargin, jint rightMargin, jint bottomMargin)
{
GtkWidget *widget = gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr)));
@@ -234,6 +235,15 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *en
if(height > 0)
g_object_set(G_OBJECT(widget), "height-request", height, NULL);
GtkWidget *parent = gtk_widget_get_parent(widget);
// if parent is Java widget, it will handle the margins by itself
if (parent && !ATL_IS_ANDROID_LAYOUT(gtk_widget_get_layout_manager(parent))) {
gtk_widget_set_margin_start(widget, leftMargin);
gtk_widget_set_margin_top(widget, topMargin);
gtk_widget_set_margin_end(widget, rightMargin);
gtk_widget_set_margin_bottom(widget, bottomMargin);
}
GtkLayoutManager *layout_manager = gtk_widget_get_layout_manager(WRAPPER_WIDGET(widget)->child);
if (ATL_IS_ANDROID_LAYOUT(layout_manager))
android_layout_set_params(ATL_ANDROID_LAYOUT(layout_manager), width, height);