From a7a94e945416747bc30cf31500b0e3f2f0e24baf Mon Sep 17 00:00:00 2001 From: dim-ghub <59436063+dim-ghub@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:08:26 -0600 Subject: [PATCH 1/2] fix(input): handle padded NativeTextBoxInfo constructor Roblox's UseUIPaddingInNativeInputs4 flag switches NativeTextBoxInfo to the 19-argument constructor (FFFFFZIIIIIIZZZFFFF)V, appending paddingLeft, paddingTop, paddingRight and paddingBottom. The JNI VM only recognized the 14- and 15-argument overloads, leaving all fields zero (geometry=0,0 0x0) and hiding typed text while input still reached Roblox. Recognize the padded overload (and future trailing-argument overloads), propagate the UIPadding floats through the TextBox snapshot/editor pipeline, and apply them as clamped inner clip insets in the text overlay rasterizer. Fixes #153 --- CHANGELOG.md | 2 + include/jnivm/jnivm.h | 4 + .../roblox_native_text_box_info_reader.h | 4 + include/runtime/roblox_text_display_state.h | 4 + include/runtime/roblox_text_editor.h | 12 +++ src/jnivm/jnivm.cc | 61 +++++++++++-- .../roblox_native_text_box_info_reader.cc | 31 +++++++ src/runtime/roblox_text_display_state.cc | 16 ++++ src/runtime/roblox_text_editor.cc | 8 ++ src/runtime/roblox_text_input_jni_bridge.cc | 22 ++++- src/runtime/roblox_text_surface_overlay.cc | 20 ++-- tests/jnivm_native_text_box_info_test.cc | 91 +++++++++++++++++++ ...roblox_native_text_box_info_reader_test.cc | 35 +++++++ tests/roblox_text_display_state_test.cc | 43 +++++++++ 14 files changed, 335 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31b60bd55..7b2ec3634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ Release notes on GitHub are taken from the matching section here. ### Fixed +- Text typed into Roblox's search bar and other TextBoxes is no longer invisible when Roblox enables + `UseUIPaddingInNativeInputs4` (the 19-argument `NativeTextBoxInfo` constructor with UI padding). - Blocking and unblocking players works when Nightcap has no saved `RBXEventTrackerV2` cookie. Roblox refused those requests with "BrowserTrackerID is missing or invalid"; Nightcap now sends its browser tracker. - Games that size their UI by screen size, such as Racket Rivals, no longer show a tiny phone layout. Nightcap diff --git a/include/jnivm/jnivm.h b/include/jnivm/jnivm.h index b90bf87f5..26ab8f568 100644 --- a/include/jnivm/jnivm.h +++ b/include/jnivm/jnivm.h @@ -179,6 +179,10 @@ struct RobloxTextBoxInfo { int return_key_type = 0; bool manual_focus_release = false; bool text_wrapped = false; + float padding_left = 0.0f; + float padding_top = 0.0f; + float padding_right = 0.0f; + float padding_bottom = 0.0f; }; struct RobloxTextInputShowRequest { diff --git a/include/runtime/roblox_native_text_box_info_reader.h b/include/runtime/roblox_native_text_box_info_reader.h index 5950b1606..b44787e1d 100644 --- a/include/runtime/roblox_native_text_box_info_reader.h +++ b/include/runtime/roblox_native_text_box_info_reader.h @@ -24,6 +24,10 @@ struct RobloxNativeTextBoxInfoSnapshot { int return_key_type = 0; bool manual_focus_release = false; bool text_wrapped = false; + float padding_left = 0.0F; + float padding_top = 0.0F; + float padding_right = 0.0F; + float padding_bottom = 0.0F; }; struct RobloxNativeTextBoxInfoQueryResult { diff --git a/include/runtime/roblox_text_display_state.h b/include/runtime/roblox_text_display_state.h index 59381c9ae..0ffeb0770 100644 --- a/include/runtime/roblox_text_display_state.h +++ b/include/runtime/roblox_text_display_state.h @@ -71,6 +71,10 @@ struct RobloxTextOverlayPresentation { int32_t font = 0; int32_t text_input_type = 0; bool text_wrapped = false; + int32_t padding_left = 0; + int32_t padding_top = 0; + int32_t padding_right = 0; + int32_t padding_bottom = 0; std::string display_utf8; std::size_t caret_utf8_byte = 0; std::size_t selection_begin_utf8_byte = 0; diff --git a/include/runtime/roblox_text_editor.h b/include/runtime/roblox_text_editor.h index a620170e3..6371285f0 100644 --- a/include/runtime/roblox_text_editor.h +++ b/include/runtime/roblox_text_editor.h @@ -32,6 +32,10 @@ struct RobloxTextFocusSession { int32_t text_input_type = 0; int32_t return_key_type = 0; bool text_wrapped = false; + int32_t padding_left = 0; + int32_t padding_top = 0; + int32_t padding_right = 0; + int32_t padding_bottom = 0; }; // Non-text properties returned by NativeGLInterface.nativeGetTextBoxInfo. @@ -53,6 +57,10 @@ struct RobloxTextFocusProperties { int32_t text_input_type = 0; int32_t return_key_type = 0; bool text_wrapped = false; + int32_t padding_left = 0; + int32_t padding_top = 0; + int32_t padding_right = 0; + int32_t padding_bottom = 0; }; enum class RobloxTextDisplayEvent { kShow, kUpdate, kHide }; @@ -74,6 +82,10 @@ struct RobloxTextDisplayUpdate { int32_t font = 0; int32_t text_input_type = 0; bool text_wrapped = false; + int32_t padding_left = 0; + int32_t padding_top = 0; + int32_t padding_right = 0; + int32_t padding_bottom = 0; const char* utf8 = nullptr; std::size_t utf8_size = 0; int32_t cursor_utf16 = 0; diff --git a/src/jnivm/jnivm.cc b/src/jnivm/jnivm.cc index d87b45363..c1a9c069a 100644 --- a/src/jnivm/jnivm.cc +++ b/src/jnivm/jnivm.cc @@ -1752,6 +1752,10 @@ jobject MakeNativeTextBoxInfoObject() { SetBooleanFieldRaw(object, "secureTextEntry", JNI_FALSE); SetBooleanFieldRaw(object, "showKeyboard", JNI_FALSE); SetBooleanFieldRaw(object, "editable", JNI_FALSE); + SetFloatFieldRaw(object, "paddingLeft", 0.0f); + SetFloatFieldRaw(object, "paddingTop", 0.0f); + SetFloatFieldRaw(object, "paddingRight", 0.0f); + SetFloatFieldRaw(object, "paddingBottom", 0.0f); return object; } @@ -2452,21 +2456,36 @@ constexpr char kRobloxNativeHelperClass[] = "com/roblox/client/startup/NativeHelper"; constexpr char kRobloxShowKeyboardSignature[] = "(JZ[BLcom/roblox/engine/jni/model/NativeTextBoxInfo;)V"; -constexpr char kRobloxLegacyTextBoxInfoConstructor[] = "(FFFFFZIIIIIIZZ)V"; -constexpr char kRobloxTextBoxInfoConstructor[] = "(FFFFFZIIIIIIZZZ)V"; +constexpr char kRobloxTextBoxInfoBasePrefix[] = "(FFFFFZIIIIIIZZ"; +constexpr std::size_t kRobloxTextBoxInfoBasePrefixLength = + sizeof(kRobloxTextBoxInfoBasePrefix) - 1; bool IsRobloxTextBoxInfoConstructor(jmethodID method_id) { if (MethodOf(method_id) != JniMethod::kConstructor) { return false; } const char* signature = MethodSignature(method_id); - return std::strcmp(signature, kRobloxLegacyTextBoxInfoConstructor) == 0 || - std::strcmp(signature, kRobloxTextBoxInfoConstructor) == 0; + const std::size_t length = std::strlen(signature); + // Matches legacy (FFFFFZIIIIIIZZ)V, editable (FFFFFZIIIIIIZZZ)V, + // UIPadding (FFFFFZIIIIIIZZZFFFF)V, and any future overload that only + // appends trailing fields after the 14 base arguments. + return length >= kRobloxTextBoxInfoBasePrefixLength + 2 && + std::strncmp(signature, kRobloxTextBoxInfoBasePrefix, + kRobloxTextBoxInfoBasePrefixLength) == 0 && + signature[length - 2] == ')' && signature[length - 1] == 'V'; } bool HasRobloxTextBoxEditableArgument(jmethodID method_id) { - return std::strcmp(MethodSignature(method_id), - kRobloxTextBoxInfoConstructor) == 0; + const char* signature = MethodSignature(method_id); + return IsRobloxTextBoxInfoConstructor(method_id) && + signature[kRobloxTextBoxInfoBasePrefixLength] == 'Z'; +} + +bool HasRobloxTextBoxPaddingArguments(jmethodID method_id) { + const char* signature = MethodSignature(method_id); + return IsRobloxTextBoxInfoConstructor(method_id) && + std::strncmp(signature + kRobloxTextBoxInfoBasePrefixLength, "ZFFFF", + 5) == 0; } void ClearSensitiveString(std::string* value) { @@ -2565,6 +2584,10 @@ bool SnapshotRobloxTextInputShow(jlong text_box, jboolean show_native_input, snapshot.info.manual_focus_release = BooleanFieldValue(info_object, "manualFocusRelease"); snapshot.info.text_wrapped = BooleanFieldValue(info_object, "textWrapped"); + snapshot.info.padding_left = FloatFieldValue(info_object, "paddingLeft"); + snapshot.info.padding_top = FloatFieldValue(info_object, "paddingTop"); + snapshot.info.padding_right = FloatFieldValue(info_object, "paddingRight"); + snapshot.info.padding_bottom = FloatFieldValue(info_object, "paddingBottom"); *request = std::move(snapshot); return true; } @@ -4174,6 +4197,16 @@ jobject ConstructObjectV(jclass clazz, jmethodID methodID, va_list args) { SetBooleanFieldRaw(object, "editable", static_cast(va_arg(args, jint))); } + if (HasRobloxTextBoxPaddingArguments(methodID)) { + SetFloatFieldRaw(object, "paddingLeft", + static_cast(va_arg(args, double))); + SetFloatFieldRaw(object, "paddingTop", + static_cast(va_arg(args, double))); + SetFloatFieldRaw(object, "paddingRight", + static_cast(va_arg(args, double))); + SetFloatFieldRaw(object, "paddingBottom", + static_cast(va_arg(args, double))); + } } else if (object_class->GetName() == "com/roblox/engine/jni/model/NativeTextBoxInfo" && MethodOf(methodID) == JniMethod::kConstructor && @@ -4181,8 +4214,9 @@ jobject ConstructObjectV(jclass clazz, jmethodID methodID, va_list args) { MethodSignature(methodID), "(Lcom/roblox/engine/jni/model/NativeTextBoxInfo;)V") == 0) { const jobject source = va_arg(args, jobject); - constexpr const char *kFloatFields[] = {"x", "y", "width", "height", - "fontSize"}; + constexpr const char *kFloatFields[] = { + "x", "y", "width", "height", "fontSize", + "paddingLeft", "paddingTop", "paddingRight", "paddingBottom"}; for (const char *field : kFloatFields) { SetFloatFieldRaw(object, field, FloatFieldValue(source, field)); } @@ -4256,6 +4290,12 @@ jobject ConstructObjectA(jclass clazz, jmethodID methodID, const jvalue *args) { if (HasRobloxTextBoxEditableArgument(methodID)) { SetBooleanFieldRaw(object, "editable", args[14].z); } + if (HasRobloxTextBoxPaddingArguments(methodID)) { + SetFloatFieldRaw(object, "paddingLeft", args[15].f); + SetFloatFieldRaw(object, "paddingTop", args[16].f); + SetFloatFieldRaw(object, "paddingRight", args[17].f); + SetFloatFieldRaw(object, "paddingBottom", args[18].f); + } } else if (object_class->GetName() == "com/roblox/engine/jni/model/NativeTextBoxInfo" && MethodOf(methodID) == JniMethod::kConstructor && @@ -4263,8 +4303,9 @@ jobject ConstructObjectA(jclass clazz, jmethodID methodID, const jvalue *args) { MethodSignature(methodID), "(Lcom/roblox/engine/jni/model/NativeTextBoxInfo;)V") == 0) { const jobject source = args[0].l; - constexpr const char *kFloatFields[] = {"x", "y", "width", "height", - "fontSize"}; + constexpr const char *kFloatFields[] = { + "x", "y", "width", "height", "fontSize", + "paddingLeft", "paddingTop", "paddingRight", "paddingBottom"}; for (const char *field : kFloatFields) { SetFloatFieldRaw(object, field, FloatFieldValue(source, field)); } diff --git a/src/runtime/roblox_native_text_box_info_reader.cc b/src/runtime/roblox_native_text_box_info_reader.cc index 0f6f28410..54099246c 100644 --- a/src/runtime/roblox_native_text_box_info_reader.cc +++ b/src/runtime/roblox_native_text_box_info_reader.cc @@ -50,6 +50,21 @@ Status ReadFloat(JNIEnv* env, jclass info_class, jobject info, const char* name, return CheckJni(env, name); } +Status ReadOptionalFloat(JNIEnv* env, jclass info_class, jobject info, + const char* name, float* value) { + jfieldID field = env->GetFieldID(info_class, name, "F"); + Status status = CheckJni(env, name); + if (!status.ok()) { + return status; + } + if (field == nullptr) { + *value = 0.0F; + return Status::Ok(); + } + *value = env->GetFloatField(info, field); + return CheckJni(env, name); +} + Status ReadInt(JNIEnv* env, jclass info_class, jobject info, const char* name, int* value) { jfieldID field = nullptr; @@ -134,6 +149,22 @@ Status Snapshot(JNIEnv* env, jobject info, status = ReadBoolean(env, info_class, info, "textWrapped", &candidate.text_wrapped); } + if (status.ok()) { + status = ReadOptionalFloat(env, info_class, info, "paddingLeft", + &candidate.padding_left); + } + if (status.ok()) { + status = ReadOptionalFloat(env, info_class, info, "paddingTop", + &candidate.padding_top); + } + if (status.ok()) { + status = ReadOptionalFloat(env, info_class, info, "paddingRight", + &candidate.padding_right); + } + if (status.ok()) { + status = ReadOptionalFloat(env, info_class, info, "paddingBottom", + &candidate.padding_bottom); + } env->DeleteLocalRef(info_class); const Status delete_status = CheckJni(env, "DeleteLocalRef(class)"); diff --git a/src/runtime/roblox_text_display_state.cc b/src/runtime/roblox_text_display_state.cc index 1fdf96622..c1cd7ba8c 100644 --- a/src/runtime/roblox_text_display_state.cc +++ b/src/runtime/roblox_text_display_state.cc @@ -125,6 +125,10 @@ RobloxTextOverlayPresentation::RobloxTextOverlayPresentation( font(other.font), text_input_type(other.text_input_type), text_wrapped(other.text_wrapped), + padding_left(other.padding_left), + padding_top(other.padding_top), + padding_right(other.padding_right), + padding_bottom(other.padding_bottom), display_utf8(other.display_utf8), caret_utf8_byte(other.caret_utf8_byte), selection_begin_utf8_byte(other.selection_begin_utf8_byte), @@ -149,6 +153,10 @@ RobloxTextOverlayPresentation& RobloxTextOverlayPresentation::operator=( font = other.font; text_input_type = other.text_input_type; text_wrapped = other.text_wrapped; + padding_left = other.padding_left; + padding_top = other.padding_top; + padding_right = other.padding_right; + padding_bottom = other.padding_bottom; display_utf8 = other.display_utf8; caret_utf8_byte = other.caret_utf8_byte; selection_begin_utf8_byte = other.selection_begin_utf8_byte; @@ -170,6 +178,10 @@ void RobloxTextOverlayPresentation::ClearSensitive() { font = 0; text_input_type = 0; text_wrapped = false; + padding_left = 0; + padding_top = 0; + padding_right = 0; + padding_bottom = 0; caret_utf8_byte = 0; selection_begin_utf8_byte = 0; selection_end_utf8_byte = 0; @@ -236,6 +248,10 @@ Status BuildRobloxTextOverlayPresentation( candidate.font = update.font; candidate.text_input_type = update.text_input_type; candidate.text_wrapped = update.text_wrapped; + candidate.padding_left = std::max(0, update.padding_left); + candidate.padding_top = std::max(0, update.padding_top); + candidate.padding_right = std::max(0, update.padding_right); + candidate.padding_bottom = std::max(0, update.padding_bottom); std::size_t codepoints_before_cursor = 0; const std::size_t caret_source_byte = Utf8ByteForUtf16Cursor( diff --git a/src/runtime/roblox_text_editor.cc b/src/runtime/roblox_text_editor.cc index 5025c7881..a4bee318e 100644 --- a/src/runtime/roblox_text_editor.cc +++ b/src/runtime/roblox_text_editor.cc @@ -301,6 +301,10 @@ Status RobloxTextEditor::UpdateFocusProperties( session_.text_input_type = properties.text_input_type; session_.return_key_type = properties.return_key_type; session_.text_wrapped = properties.text_wrapped; + session_.padding_left = properties.padding_left; + session_.padding_top = properties.padding_top; + session_.padding_right = properties.padding_right; + session_.padding_bottom = properties.padding_bottom; PublishDisplayLocked(RobloxTextDisplayEvent::kUpdate); return Status::Ok(); } @@ -755,6 +759,10 @@ void RobloxTextEditor::PublishDisplayLocked(RobloxTextDisplayEvent event) { update.font = session_.font; update.text_input_type = session_.text_input_type; update.text_wrapped = session_.text_wrapped; + update.padding_left = session_.padding_left; + update.padding_top = session_.padding_top; + update.padding_right = session_.padding_right; + update.padding_bottom = session_.padding_bottom; if (event != RobloxTextDisplayEvent::kHide) { update.utf8 = text_.data(); update.utf8_size = text_.size(); diff --git a/src/runtime/roblox_text_input_jni_bridge.cc b/src/runtime/roblox_text_input_jni_bridge.cc index 07c6fd7e6..d5e59a360 100644 --- a/src/runtime/roblox_text_input_jni_bridge.cc +++ b/src/runtime/roblox_text_input_jni_bridge.cc @@ -61,7 +61,11 @@ bool SameTextBoxInfo(const jnivm::RobloxTextBoxInfo& left, left.text_input_type == right.text_input_type && left.return_key_type == right.return_key_type && left.manual_focus_release == right.manual_focus_release && - left.text_wrapped == right.text_wrapped; + left.text_wrapped == right.text_wrapped && + left.padding_left == right.padding_left && + left.padding_top == right.padding_top && + left.padding_right == right.padding_right && + left.padding_bottom == right.padding_bottom; } void PreserveGeometry(const jnivm::RobloxTextBoxInfo& source, @@ -73,6 +77,10 @@ void PreserveGeometry(const jnivm::RobloxTextBoxInfo& source, destination->y = source.y; destination->width = source.width; destination->height = source.height; + destination->padding_left = source.padding_left; + destination->padding_top = source.padding_top; + destination->padding_right = source.padding_right; + destination->padding_bottom = source.padding_bottom; } jnivm::RobloxTextBoxInfo ToTextBoxInfo( @@ -92,6 +100,10 @@ jnivm::RobloxTextBoxInfo ToTextBoxInfo( info.return_key_type = snapshot.return_key_type; info.manual_focus_release = snapshot.manual_focus_release; info.text_wrapped = snapshot.text_wrapped; + info.padding_left = snapshot.padding_left; + info.padding_top = snapshot.padding_top; + info.padding_right = snapshot.padding_right; + info.padding_bottom = snapshot.padding_bottom; return info; } @@ -112,6 +124,10 @@ RobloxTextFocusProperties ToFocusProperties( properties.text_input_type = info.text_input_type; properties.return_key_type = info.return_key_type; properties.text_wrapped = info.text_wrapped; + properties.padding_left = RoundedCoordinate(info.padding_left); + properties.padding_top = RoundedCoordinate(info.padding_top); + properties.padding_right = RoundedCoordinate(info.padding_right); + properties.padding_bottom = RoundedCoordinate(info.padding_bottom); return properties; } @@ -657,6 +673,10 @@ struct RobloxTextInputJniBridge::State { session.text_input_type = command.info.text_input_type; session.return_key_type = command.info.return_key_type; session.text_wrapped = command.info.text_wrapped; + session.padding_left = RoundedCoordinate(command.info.padding_left); + session.padding_top = RoundedCoordinate(command.info.padding_top); + session.padding_right = RoundedCoordinate(command.info.padding_right); + session.padding_bottom = RoundedCoordinate(command.info.padding_bottom); status = backend->BeginTextFocusSession(std::move(session)); const window::TextInputOptions options{command.info.text_input_type, command.info.multiline}; diff --git a/src/runtime/roblox_text_surface_overlay.cc b/src/runtime/roblox_text_surface_overlay.cc index 3faaa229b..2bdff46d4 100644 --- a/src/runtime/roblox_text_surface_overlay.cc +++ b/src/runtime/roblox_text_surface_overlay.cc @@ -513,12 +513,17 @@ Status RobloxTextSurfaceOverlay::RasterizeLocked() { static_cast(width * height * 4), 0); const int frame_width = static_cast(width); const int frame_height = static_cast(height); - // Use Roblox's text bounds directly. Extra padding shifts the native text - // origin, scrolls long lines too early and clips compact chat fields. - const int clip_left = 0; - const int clip_right = frame_width; - const int clip_top = 0; - const int clip_bottom = frame_height; + // Apply only the UIPadding Roblox reports in NativeTextBoxInfo; when unset + // (0), use Roblox's text bounds directly. Clamp so padding can never invert + // or collapse the drawable clip box. + const int clip_left = + std::clamp(presentation.padding_left, 0, std::max(0, frame_width - 1)); + const int clip_right = std::clamp(frame_width - presentation.padding_right, + clip_left + 1, frame_width); + const int clip_top = + std::clamp(presentation.padding_top, 0, std::max(0, frame_height - 1)); + const int clip_bottom = std::clamp(frame_height - presentation.padding_bottom, + clip_top + 1, frame_height); const int available_width = std::max(1, clip_right - clip_left); const bool wrapped_layout = presentation.multiline || presentation.text_wrapped; @@ -612,7 +617,8 @@ Status RobloxTextSurfaceOverlay::RasterizeLocked() { } int text_y = clip_top; if (presentation.y_alignment == 1) { - text_y = std::max(clip_top, (frame_height - text_height) / 2); + text_y = std::max( + clip_top, clip_top + ((clip_bottom - clip_top) - text_height) / 2); } else if (presentation.y_alignment == 2) { text_y = std::max(clip_top, clip_bottom - text_height); } diff --git a/tests/jnivm_native_text_box_info_test.cc b/tests/jnivm_native_text_box_info_test.cc index ca30a6935..88210886d 100644 --- a/tests/jnivm_native_text_box_info_test.cc +++ b/tests/jnivm_native_text_box_info_test.cc @@ -10,6 +10,7 @@ namespace { constexpr char kInfoClass[] = "com/roblox/engine/jni/model/NativeTextBoxInfo"; constexpr char kInfoConstructor[] = "(FFFFFZIIIIIIZZZ)V"; +constexpr char kPaddedInfoConstructor[] = "(FFFFFZIIIIIIZZZFFFF)V"; struct ShowProbe { int calls = 0; @@ -158,5 +159,95 @@ TEST(JniVmNativeTextBoxInfoTest, ShowKeyboardSnapshotsNonzeroGeometry) { EXPECT_TRUE(probe->request.info.manual_focus_release); } +TEST(JniVmNativeTextBoxInfoTest, PaddedConstructorsAndCopyPreserveGeometry) { + VM vm; + JNIEnv* env = vm.GetJNIEnv(); + jclass cls = env->FindClass(kInfoClass); + ASSERT_NE(cls, nullptr); + jmethodID constructor = + env->GetMethodID(cls, "", kPaddedInfoConstructor); + ASSERT_NE(constructor, nullptr); + + auto expect_padding = [&](jobject info) { + ExpectGeometry(env, cls, info); + EXPECT_FLOAT_EQ( + env->GetFloatField(info, Field(env, cls, "paddingLeft", "F")), 12.0F); + EXPECT_FLOAT_EQ( + env->GetFloatField(info, Field(env, cls, "paddingTop", "F")), 4.0F); + EXPECT_FLOAT_EQ( + env->GetFloatField(info, Field(env, cls, "paddingRight", "F")), 16.0F); + EXPECT_FLOAT_EQ( + env->GetFloatField(info, Field(env, cls, "paddingBottom", "F")), 6.0F); + }; + + jobject direct = env->NewObject( + cls, constructor, 11.5, 22.5, 333.0, 44.0, 18.0, JNI_TRUE, 1, 2, 0x123456, + 4, 6, 7, JNI_TRUE, JNI_FALSE, JNI_TRUE, 12.0, 4.0, 16.0, 6.0); + ASSERT_NE(direct, nullptr); + expect_padding(direct); + + jvalue args[19]{}; + FillArguments(args); + args[15].f = 12.0F; + args[16].f = 4.0F; + args[17].f = 16.0F; + args[18].f = 6.0F; + jobject array = env->NewObjectA(cls, constructor, args); + ASSERT_NE(array, nullptr); + expect_padding(array); + + jmethodID copy_constructor = env->GetMethodID( + cls, "", + "(Lcom/roblox/engine/jni/model/NativeTextBoxInfo;)V"); + jobject copied = env->NewObject(cls, copy_constructor, array); + ASSERT_NE(copied, nullptr); + expect_padding(copied); + + // A future overload that appends another trailing argument still populates + // the known geometry and padding fields instead of leaving them zero. + jmethodID extended = + env->GetMethodID(cls, "", "(FFFFFZIIIIIIZZZFFFFZ)V"); + jobject future = env->NewObject( + cls, extended, 11.5, 22.5, 333.0, 44.0, 18.0, JNI_TRUE, 1, 2, 0x123456, 4, + 6, 7, JNI_TRUE, JNI_FALSE, JNI_TRUE, 12.0, 4.0, 16.0, 6.0, JNI_TRUE); + ASSERT_NE(future, nullptr); + expect_padding(future); +} + +TEST(JniVmNativeTextBoxInfoTest, ShowKeyboardSnapshotsPaddedGeometry) { + VM vm; + JNIEnv* env = vm.GetJNIEnv(); + auto probe = std::make_shared(); + vm.SetRobloxTextInputCallbacks(probe, ShowCallbacks()); + + jclass info_class = env->FindClass(kInfoClass); + jmethodID constructor = + env->GetMethodID(info_class, "", kPaddedInfoConstructor); + jobject info = env->NewObject( + info_class, constructor, 11.5, 22.5, 333.0, 44.0, 18.0, JNI_TRUE, 1, 2, + 0x123456, 4, 6, 7, JNI_TRUE, JNI_FALSE, JNI_TRUE, 12.0, 4.0, 16.0, 6.0); + const jbyte text_bytes[] = {'h', 'i'}; + jbyteArray text = env->NewByteArray(2); + env->SetByteArrayRegion(text, 0, 2, text_bytes); + + jclass interface_class = env->FindClass( + "com/roblox/engine/jni/NativeGLJavaInterface"); + jmethodID show = env->GetStaticMethodID( + interface_class, "showKeyboard", + "(JZ[BLcom/roblox/engine/jni/model/NativeTextBoxInfo;)V"); + env->CallStaticVoidMethod(interface_class, show, static_cast(101), + JNI_TRUE, text, info); + + ASSERT_EQ(probe->calls, 1); + EXPECT_FLOAT_EQ(probe->request.info.x, 11.5F); + EXPECT_FLOAT_EQ(probe->request.info.y, 22.5F); + EXPECT_FLOAT_EQ(probe->request.info.width, 333.0F); + EXPECT_FLOAT_EQ(probe->request.info.height, 44.0F); + EXPECT_FLOAT_EQ(probe->request.info.padding_left, 12.0F); + EXPECT_FLOAT_EQ(probe->request.info.padding_top, 4.0F); + EXPECT_FLOAT_EQ(probe->request.info.padding_right, 16.0F); + EXPECT_FLOAT_EQ(probe->request.info.padding_bottom, 6.0F); +} + } // namespace } // namespace jnivm diff --git a/tests/roblox_native_text_box_info_reader_test.cc b/tests/roblox_native_text_box_info_reader_test.cc index a129c789f..66dd80960 100644 --- a/tests/roblox_native_text_box_info_reader_test.cc +++ b/tests/roblox_native_text_box_info_reader_test.cc @@ -68,6 +68,41 @@ TEST(RobloxNativeTextBoxInfoReaderTest, CopiesEveryTypedField) { EXPECT_EQ(result.info.return_key_type, 7); EXPECT_TRUE(result.info.manual_focus_release); EXPECT_FALSE(result.info.text_wrapped); + EXPECT_FLOAT_EQ(result.info.padding_left, 0.0F); + EXPECT_FLOAT_EQ(result.info.padding_top, 0.0F); + EXPECT_FLOAT_EQ(result.info.padding_right, 0.0F); + EXPECT_FLOAT_EQ(result.info.padding_bottom, 0.0F); + g_query_result = nullptr; +} + +TEST(RobloxNativeTextBoxInfoReaderTest, CopiesPaddedConstructorFields) { + jnivm::VM vm; + JNIEnv* env = vm.GetJNIEnv(); + jclass native_gl_class = + env->FindClass("com/roblox/engine/jni/NativeGLInterface"); + jclass info_class = + env->FindClass("com/roblox/engine/jni/model/NativeTextBoxInfo"); + jmethodID constructor = + env->GetMethodID(info_class, "", "(FFFFFZIIIIIIZZZFFFF)V"); + g_query_result = env->NewObject( + info_class, constructor, 10.5, 20.25, 360.0, 42.0, 18.0, JNI_TRUE, 1, 2, + 0x123456, 4, 6, 7, JNI_TRUE, JNI_FALSE, JNI_TRUE, 14.0, 3.0, 8.0, 5.0); + g_query_calls = 0; + RobloxNativeTextBoxInfoQueryResult result; + + const Status status = QueryRobloxNativeTextBoxInfo(env, native_gl_class, + &QueryFixture, &result); + + ASSERT_TRUE(status.ok()) << status.message(); + ASSERT_TRUE(result.available); + EXPECT_FLOAT_EQ(result.info.x, 10.5F); + EXPECT_FLOAT_EQ(result.info.y, 20.25F); + EXPECT_FLOAT_EQ(result.info.width, 360.0F); + EXPECT_FLOAT_EQ(result.info.height, 42.0F); + EXPECT_FLOAT_EQ(result.info.padding_left, 14.0F); + EXPECT_FLOAT_EQ(result.info.padding_top, 3.0F); + EXPECT_FLOAT_EQ(result.info.padding_right, 8.0F); + EXPECT_FLOAT_EQ(result.info.padding_bottom, 5.0F); g_query_result = nullptr; } diff --git a/tests/roblox_text_display_state_test.cc b/tests/roblox_text_display_state_test.cc index 6c5d48092..c973ebf69 100644 --- a/tests/roblox_text_display_state_test.cc +++ b/tests/roblox_text_display_state_test.cc @@ -37,6 +37,8 @@ RobloxTextDisplayUpdate Show(uint64_t generation, const std::string& text, struct AlphaBounds { int minimum_x = std::numeric_limits::max(); int maximum_x = -1; + int minimum_y = std::numeric_limits::max(); + int maximum_y = -1; bool valid() const { return maximum_x >= minimum_x; } }; @@ -51,6 +53,8 @@ AlphaBounds FindAlphaBounds(const MocktailTextOverlayFrameInfo& frame, if (alpha < rgba.size() && rgba[alpha] != 0) { bounds.minimum_x = std::min(bounds.minimum_x, static_cast(x)); bounds.maximum_x = std::max(bounds.maximum_x, static_cast(x)); + bounds.minimum_y = std::min(bounds.minimum_y, static_cast(y)); + bounds.maximum_y = std::max(bounds.maximum_y, static_cast(y)); } } } @@ -718,6 +722,45 @@ TEST(RobloxTextDisplayStateTest, ReopensFontsAfterPointSizeChange) { EXPECT_TRUE(overlay.Shutdown().ok()); } +TEST(RobloxTextDisplayStateTest, AppliesUiPaddingInsideTextBounds) { + RobloxTextSurfaceOverlay overlay; + ASSERT_TRUE(overlay.Initialize({800, 600}).ok()); + RobloxTextDisplaySink sink = overlay.sink(); + const auto render = [&](int32_t padding_left, int32_t padding_top, + int32_t padding_right, int32_t padding_bottom, + RobloxTextDisplayEvent event) { + RobloxTextDisplayUpdate update = Show(1, "hi", 2); + update.event = event; + update.font_size = 18.0F; + update.area_width = 240; + update.area_height = 48; + update.y_alignment = 0; + update.padding_left = padding_left; + update.padding_top = padding_top; + update.padding_right = padding_right; + update.padding_bottom = padding_bottom; + sink.update(sink.context, update); + MocktailTextOverlayFrameInfo frame; + EXPECT_TRUE(overlay.QueryFrame(&frame)); + std::vector rgba(frame.rgba_bytes); + EXPECT_TRUE(overlay.CopyFrame(frame.revision, rgba.data(), rgba.size())); + return FindAlphaBounds(frame, rgba); + }; + + const AlphaBounds plain = render(0, 0, 0, 0, RobloxTextDisplayEvent::kShow); + const AlphaBounds padded = + render(24, 10, 12, 6, RobloxTextDisplayEvent::kUpdate); + const AlphaBounds clamped = + render(500, 500, 500, 500, RobloxTextDisplayEvent::kUpdate); + + ASSERT_TRUE(plain.valid()); + ASSERT_TRUE(padded.valid()); + EXPECT_GE(padded.minimum_x, plain.minimum_x + 20); + EXPECT_GE(padded.minimum_y, plain.minimum_y + 8); + EXPECT_TRUE(clamped.valid()); + EXPECT_TRUE(overlay.Shutdown().ok()); +} + } // namespace } // namespace runtime From 66e1b89b8d513ed9d72ee0aa7af48723335b47fb Mon Sep 17 00:00:00 2001 From: vii Date: Mon, 30 Nov 2026 23:21:31 -0600 Subject: [PATCH 2/2] test(input): keep the padding test's text alive past Show --- tests/roblox_text_display_state_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/roblox_text_display_state_test.cc b/tests/roblox_text_display_state_test.cc index c973ebf69..d35f553aa 100644 --- a/tests/roblox_text_display_state_test.cc +++ b/tests/roblox_text_display_state_test.cc @@ -726,10 +726,11 @@ TEST(RobloxTextDisplayStateTest, AppliesUiPaddingInsideTextBounds) { RobloxTextSurfaceOverlay overlay; ASSERT_TRUE(overlay.Initialize({800, 600}).ok()); RobloxTextDisplaySink sink = overlay.sink(); + const std::string text = "hi"; const auto render = [&](int32_t padding_left, int32_t padding_top, int32_t padding_right, int32_t padding_bottom, RobloxTextDisplayEvent event) { - RobloxTextDisplayUpdate update = Show(1, "hi", 2); + RobloxTextDisplayUpdate update = Show(1, text, 2); update.event = event; update.font_size = 18.0F; update.area_width = 240;