Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Frame::allow_ime method #3313

Closed
wants to merge 4 commits into from
Closed

Implement Frame::allow_ime method #3313

wants to merge 4 commits into from

Conversation

Barugon
Copy link
Contributor

@Barugon Barugon commented Sep 6, 2023

Blindly enabling IME is problematic for Phosh (and probably other Linux desktops that use touch) as it brings up the on-screen keyboard when the app starts. A better solution would be to enable IME when a text edit gains focus and disable IME when it looses focus (which actually shows and hides the on-screen keyboard nicely in Phosh). In order to facilitate this, I have added an allow_ime method to Frame.

I also added an allow_ime member to NativeOptions in order to enable IME at startup.

@@ -455,6 +455,9 @@ pub struct NativeOptions {
/// }
/// ```
pub app_id: Option<String>,

/// Enable/disable IME at startup.
pub allow_ime: bool,
Copy link
Owner

Choose a reason for hiding this comment

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

Please describe this a bit more.

If true, will an on-screen-keyboard usually be shown for touch-screens on start? Will it hide once the user stops editing text?

If false, will it still show up when you start editing text? Will it hide once you stop editing the text?

Copy link
Contributor Author

@Barugon Barugon Sep 6, 2023

Choose a reason for hiding this comment

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

If true, will an on-screen-keyboard usually be shown for touch-screens on start? Will it hide once the user stops editing text?

The keyboard will be shown on startup (Phosh) and you have to manually hide it on.

If false, will it still show up when you start editing text? Will it hide once you stop editing the text?

It will not automatically show the keyboard when you enter a text edit. You have to manually show it.

Adding this to my code will automatically show/hide the keyboard on Phosh:

          let response = ui.text_edit_singleline(&mut self.text);
          if response.gained_focus() {
            frame.allow_ime(true);
          } else if response.lost_focus() {
            frame.allow_ime(false);
          }

I added allow_ime to NativeOptions in case someone wants to keep the previous behavior.

Copy link
Contributor Author

@Barugon Barugon Sep 14, 2023

Choose a reason for hiding this comment

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

I may be that enabling and disabling IME shows and hides the keyboard for other OS/desktops but I really don't have a way to test that.

Copy link
Owner

Choose a reason for hiding this comment

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

It seems to me the desirable behavior is to have one flag that controls wether or not the on-screen-keyboard shows on startup (with false being a reasonable default).

And then, regardless of that flag, always show the on-screen-keyboard when the user clicks a text field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's my ultimate goal but egui is rather disconnected from the windowing system, so this was the best that I could come up with.

Copy link
Owner

Choose a reason for hiding this comment

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

egui is disconnected yes, but communicates the necessary information to the backend.
egui-winit already reads PlatformOutput::text_cursor_pos to check if the user is editing text

@emilk
Copy link
Owner

emilk commented Sep 18, 2023

@Barugon
Copy link
Contributor Author

Barugon commented Sep 19, 2023

Closing in favor of #3362.

@Barugon Barugon closed this Sep 19, 2023
@Barugon Barugon deleted the allow_ime branch September 19, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants