diff --git a/core/src/input_method.rs b/core/src/input_method.rs index 4e8c383b7d..9c83b083ca 100644 --- a/core/src/input_method.rs +++ b/core/src/input_method.rs @@ -1,5 +1,5 @@ //! Listen to input method events. -use crate::Point; +use crate::{Pixels, Point}; use std::ops::Range; @@ -34,6 +34,8 @@ pub struct Preedit { pub content: T, /// The selected range of the content. pub selection: Option>, + /// The text size of the content. + pub text_size: Option, } impl Preedit { @@ -53,6 +55,7 @@ impl Preedit { Preedit { content: self.content.as_ref().to_owned(), selection: self.selection.clone(), + text_size: self.text_size, } } } @@ -63,6 +66,7 @@ impl Preedit { Preedit { content: &self.content, selection: self.selection.clone(), + text_size: self.text_size, } } } @@ -90,13 +94,13 @@ impl InputMethod { /// let open = InputMethod::Open { /// position: Point::ORIGIN, /// purpose: Purpose::Normal, - /// preedit: Some(Preedit { content: "1".to_owned(), selection: None }), + /// preedit: Some(Preedit { content: "1".to_owned(), selection: None, text_size: None }), /// }; /// /// let open_2 = InputMethod::Open { /// position: Point::ORIGIN, /// purpose: Purpose::Secure, - /// preedit: Some(Preedit { content: "2".to_owned(), selection: None }), + /// preedit: Some(Preedit { content: "2".to_owned(), selection: None, text_size: None }), /// }; /// /// let mut ime = InputMethod::Disabled; diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index e685256bff..ce5da9efd2 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -759,8 +759,11 @@ where shell.request_redraw(); } Ime::Preedit { content, selection } => { - state.preedit = - Some(input_method::Preedit { content, selection }); + state.preedit = Some(input_method::Preedit { + content, + selection, + text_size: self.text_size, + }); shell.request_redraw(); } diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 7be5bbd918..37691e735a 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -1273,6 +1273,7 @@ where state.is_ime_open = Some(input_method::Preedit { content: content.to_owned(), selection: selection.clone(), + text_size: self.size, }); shell.request_redraw(); diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs index ae214e7cfd..d5b334df1d 100644 --- a/winit/src/program/window_manager.rs +++ b/winit/src/program/window_manager.rs @@ -322,7 +322,9 @@ where self.content = Renderer::Paragraph::with_spans(Text { content: &spans, bounds: Size::INFINITY, - size: renderer.default_size(), + size: preedit + .text_size + .unwrap_or_else(|| renderer.default_size()), line_height: text::LineHeight::default(), font: renderer.default_font(), horizontal_alignment: alignment::Horizontal::Left,