Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1388,30 +1388,45 @@ static class ShowTextInputTask implements Runnable {
* the bottom edge of the input region and the top edge of an input
* method (soft keyboard)
*/
static final int HEIGHT_PADDING = 15;
static int getPanPadding() {
/* The hint is in window coordinates. Convert to pixels by
* multiplying by density. */
int defaultPadding = 10;
try {
String hint = nativeGetHint("SDL_IME_PAN_PADDING");
if (hint != null) {
defaultPadding = Integer.parseInt(hint);
}
} catch (NumberFormatException ignored) {
}
float density = getContext().getResources().getDisplayMetrics().density;
return (int)(defaultPadding * density);
}

public int input_type;
public int x, y, w, h;
private final int panPadding;

public ShowTextInputTask(int input_type, int x, int y, int w, int h) {
this.input_type = input_type;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.panPadding = getPanPadding();

/* Minimum size of 1 pixel, so it takes focus. */
if (this.w <= 0) {
this.w = 1;
}
if (this.h + HEIGHT_PADDING <= 0) {
this.h = 1 - HEIGHT_PADDING;
if (this.h + panPadding <= 0) {
this.h = 1 - panPadding;
}
}

@Override
public void run() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h + HEIGHT_PADDING);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h + panPadding);
params.leftMargin = x;
params.topMargin = y;

Expand Down
19 changes: 19 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,25 @@ extern "C" {
*/
#define SDL_HINT_IME_IMPLEMENTED_UI "SDL_IME_IMPLEMENTED_UI"

/**
* A variable controlling the padding in pixels added above the on-screen
* keyboard to keep the text input area visible.
*
* This padding is used on platforms with on-screen keyboards (iOS, Android)
* to ensure there is extra breathing room between the text input area and
* the top of the keyboard when panning the view.
*
* The variable can be set to a number representing the padding in window
* coordinates.
*
* The default value is "10".
*
* This hint can be set anytime.
*
* \since This hint is available since SDL 3.6.0.
*/
#define SDL_HINT_IME_PAN_PADDING "SDL_IME_PAN_PADDING"

/**
* A variable controlling whether the home indicator bar on iPhone X and later
* should be hidden.
Expand Down
5 changes: 4 additions & 1 deletion src/video/uikit/SDL_uikitviewcontroller.m
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,10 @@ - (void)updateKeyboard
#endif

if (self.keyboardHeight && self.textInputRect.h) {
int rectbottom = (int)(self.textInputRect.y + self.textInputRect.h);
/// Get the pan padding from the hint (in window coordinates).
const char *hint = SDL_GetHint(SDL_HINT_IME_PAN_PADDING);
int padding = (hint && *hint) ? SDL_atoi(hint) : 10;
int rectbottom = (int)(self.textInputRect.y + self.textInputRect.h + padding);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous padding value was 0, so we need to subtract 15, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong about the automatic padding on iOS, so 0 in int panPadding = (hint && *hint) ? SDL_atoi(hint) : 0; was actually setting it to no padding by default and now 15 is adding the new default.
I have no idea why I saw a padding and now don't see it with padding set to 0. Probably too many windows open with too many branches.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it look consistent with the Android version with 15 points of padding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the division it looks consistent.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so what you want to do is set the hint in testime, and use the same conversion to window coordinates calculation on the hint value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slouken is this correct now? I'm really struggling with window coordinates, points and pixels, but window coordinates equals points, so no conversion for iOS. And is the conversion to pixels correct (window coordinates * density)?
It looks almost equal with different paddings while on Android the padding looks just a tiny bit more. Probably would need visual help in TestIME to really tell :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points == pixels on Android, so no conversion is needed there either. Basically, no conversion is necessary in SDL code for either platform. You're so close! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But... I don't understand this then.
If I don't apply any conversion, the padding on either platform is visibly far from the same.
Applying the Android conversion makes it close but not quite the same (the higher the padding the more it drifts apart). I'm really at a loss at how to do this properly.

TestIME padding of 50, and as a visual guide I've added the setting_icon a couple of times (input at 250.0f, both show 5 + something setting icons underneath without the IME).
No conversion iOS (and incidentally my conversion attempt shows the same):
image

No conversion Android: Conversion Android:
image image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll go ahead and merge this and clean it up afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looking forward to see/learn what is the right way.

int keybottom = (int)(self.view.bounds.size.height - self.keyboardHeight);
if (keybottom < rectbottom) {
offset.y = keybottom - rectbottom;
Expand Down
Loading