Skip to content

Commit fcdf53a

Browse files
committed
Set correct text size for text in preedit window
1 parent 4bbb5cb commit fcdf53a

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

core/src/input_method.rs

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

44
use std::ops::Range;
55

@@ -34,15 +34,20 @@ pub struct Preedit<T = String> {
3434
pub content: T,
3535
/// The selected range of the content.
3636
pub selection: Option<Range<usize>>,
37+
/// The text size of the content.
38+
pub text_size: Option<Pixels>,
3739
}
3840

3941
impl<T> Preedit<T> {
4042
/// Creates a new empty [`Preedit`].
41-
pub fn new() -> Self
43+
pub fn new(text_size: Option<impl Into<Pixels>>) -> Self
4244
where
4345
T: Default,
4446
{
45-
Self::default()
47+
Self {
48+
text_size: text_size.map(Into::into),
49+
..Default::default()
50+
}
4651
}
4752

4853
/// Turns a [`Preedit`] into its owned version.
@@ -53,6 +58,7 @@ impl<T> Preedit<T> {
5358
Preedit {
5459
content: self.content.as_ref().to_owned(),
5560
selection: self.selection.clone(),
61+
text_size: self.text_size,
5662
}
5763
}
5864
}
@@ -63,6 +69,7 @@ impl Preedit {
6369
Preedit {
6470
content: &self.content,
6571
selection: self.selection.clone(),
72+
text_size: self.text_size,
6673
}
6774
}
6875
}
@@ -90,13 +97,13 @@ impl InputMethod {
9097
/// let open = InputMethod::Open {
9198
/// position: Point::ORIGIN,
9299
/// purpose: Purpose::Normal,
93-
/// preedit: Some(Preedit { content: "1".to_owned(), selection: None }),
100+
/// preedit: Some(Preedit { content: "1".to_owned(), selection: None, text_size: None }),
94101
/// };
95102
///
96103
/// let open_2 = InputMethod::Open {
97104
/// position: Point::ORIGIN,
98105
/// purpose: Purpose::Secure,
99-
/// preedit: Some(Preedit { content: "2".to_owned(), selection: None }),
106+
/// preedit: Some(Preedit { content: "2".to_owned(), selection: None, text_size: None }),
100107
/// };
101108
///
102109
/// let mut ime = InputMethod::Disabled;

widget/src/text_editor.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,14 +753,18 @@ where
753753
}
754754
Update::InputMethod(update) => match update {
755755
Ime::Toggle(is_open) => {
756-
state.preedit =
757-
is_open.then(input_method::Preedit::new);
756+
state.preedit = is_open.then(|| {
757+
input_method::Preedit::new(self.text_size)
758+
});
758759

759760
shell.request_redraw();
760761
}
761762
Ime::Preedit { content, selection } => {
762-
state.preedit =
763-
Some(input_method::Preedit { content, selection });
763+
state.preedit = Some(input_method::Preedit {
764+
content,
765+
selection,
766+
text_size: self.text_size,
767+
});
764768

765769
shell.request_redraw();
766770
}

widget/src/text_input.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ where
12621262

12631263
state.is_ime_open =
12641264
matches!(event, input_method::Event::Opened)
1265-
.then(input_method::Preedit::new);
1265+
.then(|| input_method::Preedit::new(self.size));
12661266

12671267
shell.request_redraw();
12681268
}
@@ -1273,6 +1273,7 @@ where
12731273
state.is_ime_open = Some(input_method::Preedit {
12741274
content: content.to_owned(),
12751275
selection: selection.clone(),
1276+
text_size: self.size,
12761277
});
12771278

12781279
shell.request_redraw();

winit/src/program/window_manager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ where
322322
self.content = Renderer::Paragraph::with_spans(Text {
323323
content: &spans,
324324
bounds: Size::INFINITY,
325-
size: renderer.default_size(),
325+
size: preedit
326+
.text_size
327+
.unwrap_or_else(|| renderer.default_size()),
326328
line_height: text::LineHeight::default(),
327329
font: renderer.default_font(),
328330
horizontal_alignment: alignment::Horizontal::Left,

0 commit comments

Comments
 (0)