summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-03 01:30:41 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-03 01:30:41 +0100
commit3a35fd6249eeb324379d3a14b020ccc48ec16fb4 (patch)
treee7db03dadb660818082db2d0fc6180a9a1f2cfd0 /winit
parentd28af5739bfaafa141dc8071a0c910e8693f3b3c (diff)
downloadiced-3a35fd6249eeb324379d3a14b020ccc48ec16fb4.tar.gz
iced-3a35fd6249eeb324379d3a14b020ccc48ec16fb4.tar.bz2
iced-3a35fd6249eeb324379d3a14b020ccc48ec16fb4.zip
Clamp pre-edit inside viewport bounds
Diffstat (limited to 'winit')
-rw-r--r--winit/src/program/window_manager.rs46
1 files changed, 35 insertions, 11 deletions
diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs
index 08d19d16..35a8d7dc 100644
--- a/winit/src/program/window_manager.rs
+++ b/winit/src/program/window_manager.rs
@@ -221,17 +221,19 @@ where
{
self.raw.set_ime_cursor_area(
LogicalPosition::new(position.x, position.y),
- LogicalSize::new(10, 10),
+ LogicalSize::new(10, 10), // TODO?
);
self.raw.set_ime_purpose(conversion::ime_purpose(purpose));
if let Some(content) = preedit {
- if let Some(preedit) = &mut self.preedit {
- preedit.update(&content, &self.renderer);
+ if content.is_empty() {
+ self.preedit = None;
+ } else if let Some(preedit) = &mut self.preedit {
+ preedit.update(position, &content, &self.renderer);
} else {
let mut preedit = Preedit::new();
- preedit.update(&content, &self.renderer);
+ preedit.update(position, &content, &self.renderer);
self.preedit = Some(preedit);
}
@@ -247,6 +249,10 @@ where
&mut self.renderer,
self.state.text_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 {
content: text,
bounds: Size::INFINITY,
@@ -279,21 +287,37 @@ where
line_height: text::LineHeight::default(),
font: renderer.default_font(),
horizontal_alignment: alignment::Horizontal::Left,
- vertical_alignment: alignment::Vertical::Top, //Bottom,
+ vertical_alignment: alignment::Vertical::Top,
shaping: text::Shaping::Advanced,
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 {
return;
}
- let top_left =
- self.position - Vector::new(0.0, self.content.min_height());
+ let mut bounds = Rectangle::new(
+ self.position - Vector::new(0.0, self.content.min_height()),
+ self.content.min_bounds(),
+ );
+
+ bounds.x = bounds
+ .x
+ .max(viewport.x)
+ .min(viewport.x + viewport.width - bounds.width);
- let bounds = Rectangle::new(top_left, self.content.min_bounds());
+ bounds.y = bounds
+ .y
+ .max(viewport.y)
+ .min(viewport.y + viewport.height - bounds.height);
renderer.with_layer(bounds, |renderer| {
renderer.fill_quad(
@@ -306,7 +330,7 @@ where
renderer.fill_paragraph(
self.content.raw(),
- top_left,
+ bounds.position(),
color,
bounds,
);