use AndroidLayout class also in View implementation

drop the onMeasure hack from WrapperWidget
This commit is contained in:
Julian Winkler
2023-10-31 23:02:11 +01:00
committed by Julian Winkler
parent 3c03223085
commit 0a8b8a3874
4 changed files with 17 additions and 30 deletions

View File

@@ -77,25 +77,6 @@ void wrapper_widget_set_child(WrapperWidget *parent, GtkWidget *child) // TODO:
parent->child = child;
}
#define MEASURE_SPEC_EXACTLY (1 << 30)
static void on_mapped(GtkWidget* self, gpointer data)
{
WrapperWidget *wrapper = WRAPPER_WIDGET(self);
if (wrapper->jvm) {
JNIEnv *env;
(*wrapper->jvm)->GetEnv(wrapper->jvm, (void**)&env, JNI_VERSION_1_6);
(*env)->CallVoidMethod(env, wrapper->jobj, wrapper->measure_method, MEASURE_SPEC_EXACTLY | gtk_widget_get_width(self), MEASURE_SPEC_EXACTLY | gtk_widget_get_height(self));
int width = (*env)->CallIntMethod(env, wrapper->jobj, handle_cache.view.getMeasuredWidth);
if (width > 0)
g_object_set(G_OBJECT(self), "width-request", width, NULL);
int height = (*env)->CallIntMethod(env, wrapper->jobj, handle_cache.view.getMeasuredHeight);
if (height > 0)
g_object_set(G_OBJECT(self), "height-request", height, NULL);
}
}
static guint sk_area_queue_queue_redraw(GtkWidget *sk_area)
{
gtk_widget_queue_draw(sk_area);
@@ -133,13 +114,6 @@ void wrapper_widget_set_jobject(WrapperWidget *wrapper, JNIEnv *env, jobject job
// gtk_widget_add_tick_callback(sk_area, tick_callback, NULL, NULL);
}
jmethodID measure_method = _METHOD(_CLASS(jobj), "onMeasure", "(II)V");
if (measure_method != handle_cache.view.onMeasure) {
wrapper->measure_method = measure_method;
// add a callback for when the widget is mapped, which will call onMeasure to figure out what size the widget wants to be
g_signal_connect(wrapper, "map", G_CALLBACK(on_mapped), NULL);
}
jmethodID ontouchevent_method = _METHOD(_CLASS(jobj), "onTouchEvent", "(Landroid/view/MotionEvent;)Z");
if (ontouchevent_method != handle_cache.view.onTouchEvent) {
/* use wrapper->child since the jobject may not have the "widget" variable set yet */