Clamp pre-edit inside viewport bounds
This commit is contained in:
parent
d28af5739b
commit
3a35fd6249
2 changed files with 37 additions and 14 deletions
|
|
@ -413,8 +413,7 @@ where
|
||||||
let secure_value = self.is_secure.then(|| value.secure());
|
let secure_value = self.is_secure.then(|| value.secure());
|
||||||
let value = secure_value.as_ref().unwrap_or(value);
|
let value = secure_value.as_ref().unwrap_or(value);
|
||||||
|
|
||||||
let mut children_layout = layout.children();
|
let text_bounds = layout.children().next().unwrap().bounds();
|
||||||
let text_bounds = children_layout.next().unwrap().bounds();
|
|
||||||
|
|
||||||
let caret_index = match state.cursor.state(value) {
|
let caret_index = match state.cursor.state(value) {
|
||||||
cursor::State::Index(position) => position,
|
cursor::State::Index(position) => position,
|
||||||
|
|
@ -435,7 +434,7 @@ where
|
||||||
+ alignment_offset;
|
+ alignment_offset;
|
||||||
|
|
||||||
InputMethod::Open {
|
InputMethod::Open {
|
||||||
position: Point::new(x, text_bounds.y),
|
position: Point::new(x, text_bounds.y + text_bounds.height),
|
||||||
purpose: if self.is_secure {
|
purpose: if self.is_secure {
|
||||||
input_method::Purpose::Secure
|
input_method::Purpose::Secure
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -221,17 +221,19 @@ where
|
||||||
{
|
{
|
||||||
self.raw.set_ime_cursor_area(
|
self.raw.set_ime_cursor_area(
|
||||||
LogicalPosition::new(position.x, position.y),
|
LogicalPosition::new(position.x, position.y),
|
||||||
LogicalSize::new(10, 10),
|
LogicalSize::new(10, 10), // TODO?
|
||||||
);
|
);
|
||||||
|
|
||||||
self.raw.set_ime_purpose(conversion::ime_purpose(purpose));
|
self.raw.set_ime_purpose(conversion::ime_purpose(purpose));
|
||||||
|
|
||||||
if let Some(content) = preedit {
|
if let Some(content) = preedit {
|
||||||
if let Some(preedit) = &mut self.preedit {
|
if content.is_empty() {
|
||||||
preedit.update(&content, &self.renderer);
|
self.preedit = None;
|
||||||
|
} else if let Some(preedit) = &mut self.preedit {
|
||||||
|
preedit.update(position, &content, &self.renderer);
|
||||||
} else {
|
} else {
|
||||||
let mut preedit = Preedit::new();
|
let mut preedit = Preedit::new();
|
||||||
preedit.update(&content, &self.renderer);
|
preedit.update(position, &content, &self.renderer);
|
||||||
|
|
||||||
self.preedit = Some(preedit);
|
self.preedit = Some(preedit);
|
||||||
}
|
}
|
||||||
|
|
@ -247,6 +249,10 @@ where
|
||||||
&mut self.renderer,
|
&mut self.renderer,
|
||||||
self.state.text_color(),
|
self.state.text_color(),
|
||||||
self.state.background_color(),
|
self.state.background_color(),
|
||||||
|
&Rectangle::new(
|
||||||
|
Point::ORIGIN,
|
||||||
|
self.state.viewport().logical_size(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +277,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, text: &str, renderer: &Renderer) {
|
fn update(&mut self, position: Point, text: &str, renderer: &Renderer) {
|
||||||
|
self.position = position;
|
||||||
|
|
||||||
self.content.update(Text {
|
self.content.update(Text {
|
||||||
content: text,
|
content: text,
|
||||||
bounds: Size::INFINITY,
|
bounds: Size::INFINITY,
|
||||||
|
|
@ -279,21 +287,37 @@ where
|
||||||
line_height: text::LineHeight::default(),
|
line_height: text::LineHeight::default(),
|
||||||
font: renderer.default_font(),
|
font: renderer.default_font(),
|
||||||
horizontal_alignment: alignment::Horizontal::Left,
|
horizontal_alignment: alignment::Horizontal::Left,
|
||||||
vertical_alignment: alignment::Vertical::Top, //Bottom,
|
vertical_alignment: alignment::Vertical::Top,
|
||||||
shaping: text::Shaping::Advanced,
|
shaping: text::Shaping::Advanced,
|
||||||
wrapping: text::Wrapping::None,
|
wrapping: text::Wrapping::None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, renderer: &mut Renderer, color: Color, background: Color) {
|
fn draw(
|
||||||
|
&self,
|
||||||
|
renderer: &mut Renderer,
|
||||||
|
color: Color,
|
||||||
|
background: Color,
|
||||||
|
viewport: &Rectangle,
|
||||||
|
) {
|
||||||
if self.content.min_width() < 1.0 {
|
if self.content.min_width() < 1.0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let top_left =
|
let mut bounds = Rectangle::new(
|
||||||
self.position - Vector::new(0.0, self.content.min_height());
|
self.position - Vector::new(0.0, self.content.min_height()),
|
||||||
|
self.content.min_bounds(),
|
||||||
|
);
|
||||||
|
|
||||||
let bounds = Rectangle::new(top_left, self.content.min_bounds());
|
bounds.x = bounds
|
||||||
|
.x
|
||||||
|
.max(viewport.x)
|
||||||
|
.min(viewport.x + viewport.width - bounds.width);
|
||||||
|
|
||||||
|
bounds.y = bounds
|
||||||
|
.y
|
||||||
|
.max(viewport.y)
|
||||||
|
.min(viewport.y + viewport.height - bounds.height);
|
||||||
|
|
||||||
renderer.with_layer(bounds, |renderer| {
|
renderer.with_layer(bounds, |renderer| {
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
|
|
@ -306,7 +330,7 @@ where
|
||||||
|
|
||||||
renderer.fill_paragraph(
|
renderer.fill_paragraph(
|
||||||
self.content.raw(),
|
self.content.raw(),
|
||||||
top_left,
|
bounds.position(),
|
||||||
color,
|
color,
|
||||||
bounds,
|
bounds,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue