Skip to content

Commit 98fe31b

Browse files
author
dcz
committed
Report cursor size to input method
1 parent c4b7665 commit 98fe31b

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

core/src/input_method.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Listen to input method events.
2-
use crate::{Pixels, Point};
2+
use crate::{Pixels, Rectangle};
33

44
use std::ops::Range;
55

@@ -11,7 +11,7 @@ pub enum InputMethod<T = String> {
1111
/// Input method is enabled.
1212
Enabled {
1313
/// The position at which the input method dialog should be placed.
14-
position: Point,
14+
cursor_position: Rectangle,
1515
/// The [`Purpose`] of the input method.
1616
purpose: Purpose,
1717
/// The preedit to overlay on top of the input method dialog, if needed.
@@ -130,11 +130,11 @@ impl<T> InputMethod<T> {
130130
match self {
131131
Self::Disabled => InputMethod::Disabled,
132132
Self::Enabled {
133-
position,
133+
cursor_position,
134134
purpose,
135135
preedit,
136136
} => InputMethod::Enabled {
137-
position: *position,
137+
cursor_position: *cursor_position,
138138
purpose: *purpose,
139139
preedit: preedit.as_ref().map(Preedit::to_owned),
140140
},

widget/src/scrollable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,10 @@ where
750750
);
751751

752752
if !had_input_method {
753-
if let InputMethod::Enabled { position, .. } =
753+
if let InputMethod::Enabled { cursor_position, .. } =
754754
shell.input_method_mut()
755755
{
756-
*position = *position - translation;
756+
*cursor_position = *cursor_position - translation;
757757
}
758758
}
759759
};

widget/src/text_editor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,10 @@ where
356356
self.text_size.unwrap_or_else(|| renderer.default_size()),
357357
);
358358

359-
let position =
360-
cursor + translation + Vector::new(0.0, f32::from(line_height));
359+
let position = cursor + translation;
361360

362361
InputMethod::Enabled {
363-
position,
362+
cursor_position: Rectangle::new(position, Size::new(0.0, f32::from(line_height))),
364363
purpose: input_method::Purpose::Normal,
365364
preedit: state.preedit.as_ref().map(input_method::Preedit::as_ref),
366365
}

widget/src/text_input.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,10 @@ where
430430
+ alignment_offset;
431431

432432
InputMethod::Enabled {
433-
position: Point::new(x, text_bounds.y + text_bounds.height),
433+
cursor_position: Rectangle::new(
434+
Point::new(x, text_bounds.y),
435+
Size::new(0.0, text_bounds.height),
436+
),
434437
purpose: if self.is_secure {
435438
input_method::Purpose::Secure
436439
} else {

winit/src/window.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ where
172172
pub renderer: P::Renderer,
173173
pub redraw_at: Option<Instant>,
174174
preedit: Option<Preedit<P::Renderer>>,
175-
ime_state: Option<(Point, input_method::Purpose)>,
175+
ime_state: Option<(Rectangle, input_method::Purpose)>,
176176
}
177177

178178
impl<P, C> Window<P, C>
@@ -217,11 +217,11 @@ where
217217
self.disable_ime();
218218
}
219219
InputMethod::Enabled {
220-
position,
220+
cursor_position,
221221
purpose,
222222
preedit,
223223
} => {
224-
self.enable_ime(position, purpose);
224+
self.enable_ime(cursor_position, purpose);
225225

226226
if let Some(preedit) = preedit {
227227
if preedit.content.is_empty() {
@@ -231,7 +231,7 @@ where
231231
self.preedit.take().unwrap_or_else(Preedit::new);
232232

233233
overlay.update(
234-
position,
234+
cursor_position.position(),
235235
&preedit,
236236
self.state.background_color(),
237237
&self.renderer,
@@ -260,19 +260,19 @@ where
260260
}
261261
}
262262

263-
fn enable_ime(&mut self, position: Point, purpose: input_method::Purpose) {
263+
fn enable_ime(&mut self, cursor: Rectangle, purpose: input_method::Purpose) {
264264
if self.ime_state.is_none() {
265265
self.raw.set_ime_allowed(true);
266266
}
267267

268-
if self.ime_state != Some((position, purpose)) {
268+
if self.ime_state != Some((cursor, purpose)) {
269269
self.raw.set_ime_cursor_area(
270-
LogicalPosition::new(position.x, position.y),
271-
LogicalSize::new(10, 10), // TODO?
270+
LogicalPosition::new(cursor.x, cursor.y),
271+
LogicalSize::new(cursor.width, cursor.height),
272272
);
273273
self.raw.set_ime_purpose(conversion::ime_purpose(purpose));
274274

275-
self.ime_state = Some((position, purpose));
275+
self.ime_state = Some((cursor, purpose));
276276
}
277277
}
278278

0 commit comments

Comments
 (0)