You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
refactor View.native_measure()
It now respects gtk_widget_get_request_mode() when not specified otherwise
This commit is contained in:
@@ -342,34 +342,40 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1destructor(JNIEnv *env, jo
|
|||||||
#define MEASURE_SPEC_MASK (0x3 << 30)
|
#define MEASURE_SPEC_MASK (0x3 << 30)
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_android_view_View_native_1measure(JNIEnv *env, jobject this, jlong widget_ptr, jint width_spec, jint height_spec, jboolean is_complex) {
|
JNIEXPORT void JNICALL Java_android_view_View_native_1measure(JNIEnv *env, jobject this, jlong widget_ptr, jint width_spec, jint height_spec, jboolean is_complex) {
|
||||||
int width;
|
int width = -1;
|
||||||
int height;
|
int height = -1;
|
||||||
int for_size;
|
|
||||||
GtkWidget *widget = gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr)));
|
GtkWidget *widget = gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr)));
|
||||||
int width_spec_size = width_spec & ~MEASURE_SPEC_MASK;
|
int width_spec_size = width_spec & ~MEASURE_SPEC_MASK;
|
||||||
int height_spec_size = height_spec & ~MEASURE_SPEC_MASK;
|
int height_spec_size = height_spec & ~MEASURE_SPEC_MASK;
|
||||||
int width_spec_mode = width_spec & MEASURE_SPEC_MASK;
|
int width_spec_mode = width_spec & MEASURE_SPEC_MASK;
|
||||||
int height_spec_mode = height_spec & MEASURE_SPEC_MASK;
|
int height_spec_mode = height_spec & MEASURE_SPEC_MASK;
|
||||||
|
GtkSizeRequestMode request_mode;
|
||||||
|
|
||||||
if (width_spec_mode == MEASURE_SPEC_EXACTLY || (!is_complex && width_spec_mode == MEASURE_SPEC_AT_MOST)) {
|
if (width_spec_mode == MEASURE_SPEC_EXACTLY || (!is_complex && width_spec_mode == MEASURE_SPEC_AT_MOST)) {
|
||||||
width = width_spec_size;
|
width = width_spec_size;
|
||||||
} else {
|
request_mode = GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
||||||
for_size = (height_spec_mode == MEASURE_SPEC_EXACTLY) ? height_spec_size : -1;
|
|
||||||
gtk_widget_measure(widget, GTK_ORIENTATION_HORIZONTAL, for_size, NULL, &width, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
if (width_spec_mode == MEASURE_SPEC_AT_MOST && width > width_spec_size) {
|
|
||||||
width = width_spec_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (height_spec_mode == MEASURE_SPEC_EXACTLY || (!is_complex && height_spec_mode == MEASURE_SPEC_AT_MOST)) {
|
if (height_spec_mode == MEASURE_SPEC_EXACTLY || (!is_complex && height_spec_mode == MEASURE_SPEC_AT_MOST)) {
|
||||||
height = height_spec_size;
|
height = height_spec_size;
|
||||||
} else {
|
request_mode = GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
|
||||||
for_size = (width_spec_mode == MEASURE_SPEC_EXACTLY) ? width_spec_size : -1;
|
|
||||||
gtk_widget_measure(widget, GTK_ORIENTATION_VERTICAL, for_size, NULL, &height, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
if (height_spec_mode == MEASURE_SPEC_AT_MOST && height > height_spec_size) {
|
if (width == -1 && height == -1)
|
||||||
|
request_mode = gtk_widget_get_request_mode(widget);
|
||||||
|
if (width == -1 && request_mode == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) {
|
||||||
|
gtk_widget_measure(widget, GTK_ORIENTATION_HORIZONTAL, height, NULL, &width, NULL, NULL);
|
||||||
|
if (width_spec_mode == MEASURE_SPEC_AT_MOST && width > width_spec_size)
|
||||||
|
width = width_spec_size;
|
||||||
|
}
|
||||||
|
if (height == -1) {
|
||||||
|
gtk_widget_measure(widget, GTK_ORIENTATION_VERTICAL, width, NULL, &height, NULL, NULL);
|
||||||
|
if (height_spec_mode == MEASURE_SPEC_AT_MOST && height > height_spec_size)
|
||||||
height = height_spec_size;
|
height = height_spec_size;
|
||||||
}
|
}
|
||||||
|
if (width == -1) {
|
||||||
|
gtk_widget_measure(widget, GTK_ORIENTATION_HORIZONTAL, height, NULL, &width, NULL, NULL);
|
||||||
|
if (width_spec_mode == MEASURE_SPEC_AT_MOST && width > width_spec_size)
|
||||||
|
width = width_spec_size;
|
||||||
|
}
|
||||||
|
|
||||||
(*env)->CallVoidMethod(env, this, handle_cache.view.setMeasuredDimension, width, height);
|
(*env)->CallVoidMethod(env, this, handle_cache.view.setMeasuredDimension, width, height);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user