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

Add PlainEditor method to get IME cursor area #224

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

tomcur
Copy link
Member

@tomcur tomcur commented Dec 10, 2024

The area reported is the area of text the user is currently editing. It is usually used by platforms to place a candidate box for IME near it, while ensuring it is not obscured.

The implementation here ensures the area is usually near the focus, that the area contains at least some surrounding context (in case the platform places something to the side of the area, instead of above or under), and that the IME candidate box usually does not need to jump around when the IME starts or continues composing.

The area reported is the area of text the user is currently editing. It
is usually used by platforms to place a candidate box for IME near it,
while ensuring it is not obscured.

The implementation here ensures the area is usually near the focus, that
the area contains at least some surrounding context (in case the
platform places something to the side of the area, instead of above or
under), and that the IME candidate box usually does not need to jump
around when the IME starts or continues composing.
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Looks good. I've not tested it

@@ -340,6 +358,7 @@ fn main() -> Result<()> {
scene: Scene::new(),
editor: text::Editor::new(text::LOREM),
last_drawn_generation: Default::default(),
last_sent_ime_cursor_area: None,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be an arbitrary definitely invalid rect? E.g. 0x0 at (0, 0) or similar

Copy link
Member Author

Choose a reason for hiding this comment

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

It's now flattened and splatted with NaN, which should definitely never be returned.

// until https://github.com/rust-windowing/winit/pull/3966 is in the Winit release
// used by this example.
render_state.window.set_ime_cursor_area(
PhysicalPosition::new(
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is physical right here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is, but I haven't tested it with a non-1 display scale. The editor gets its width set as the physical width in

WindowEvent::Resized(size) => {
self.context
.resize_surface(&mut render_state.surface, size.width, size.height);
let editor = self.editor.editor();
editor.set_scale(1.0);
editor.set_width(Some(size.width as f32 - 2f32 * text::INSET));
render_state.window.request_redraw();
}

@tomcur tomcur enabled auto-merge December 10, 2024 16:42
@tomcur tomcur added this pull request to the merge queue Dec 10, 2024
Merged via the queue into linebender:main with commit 1a8740d Dec 10, 2024
20 checks passed
@tomcur tomcur deleted the ime-area branch December 10, 2024 17:07
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