From 99899d49cc93cdec3832f7b5ecad867fdd421e07 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Dec 2023 15:04:08 +0100 Subject: Clamp `text::measure` to `Buffer::size` --- graphics/src/text.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'graphics/src') diff --git a/graphics/src/text.rs b/graphics/src/text.rs index 7261900e..fc7694c2 100644 --- a/graphics/src/text.rs +++ b/graphics/src/text.rs @@ -76,7 +76,12 @@ pub fn measure(buffer: &cosmic_text::Buffer) -> Size { (run.line_w.max(width), total_lines + 1) }); - Size::new(width, total_lines as f32 * buffer.metrics().line_height) + let (max_width, max_height) = buffer.size(); + + Size::new( + width.min(max_width), + (total_lines as f32 * buffer.metrics().line_height).min(max_height), + ) } /// Returns the attributes of the given [`Font`]. -- cgit From 936d480267578d7e80675e78ec1880aaaaab72d6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Dec 2023 16:04:27 +0100 Subject: Clip text to `viewport` bounds instead of layout bounds --- graphics/src/primitive.rs | 26 ++++++++++++++++---------- graphics/src/renderer.rs | 6 ++++++ 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'graphics/src') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 4ed512c1..837eb77a 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -14,24 +14,26 @@ use std::sync::Arc; pub enum Primitive { /// A text primitive Text { - /// The contents of the text + /// The contents of the text. content: String, - /// The bounds of the text + /// The bounds of the text. bounds: Rectangle, - /// The color of the text + /// The color of the text. color: Color, - /// The size of the text in logical pixels + /// The size of the text in logical pixels. size: Pixels, - /// The line height of the text + /// The line height of the text. line_height: text::LineHeight, - /// The font of the text + /// The font of the text. font: Font, - /// The horizontal alignment of the text + /// The horizontal alignment of the text. horizontal_alignment: alignment::Horizontal, - /// The vertical alignment of the text + /// The vertical alignment of the text. vertical_alignment: alignment::Vertical, /// The shaping strategy of the text. shaping: text::Shaping, + /// The viewport of the text. + viewport: Rectangle, }, /// A paragraph primitive Paragraph { @@ -41,15 +43,19 @@ pub enum Primitive { position: Point, /// The color of the paragraph. color: Color, + /// The viewport of the paragraph. + viewport: Rectangle, }, /// An editor primitive Editor { /// The [`editor::Weak`] reference. editor: editor::Weak, - /// The position of the paragraph. + /// The position of the editor. position: Point, - /// The color of the paragraph. + /// The color of the editor. color: Color, + /// The viewport of the editor. + viewport: Rectangle, }, /// A quad primitive Quad { diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index d7613e36..0d3b11a7 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -164,11 +164,13 @@ where paragraph: &Self::Paragraph, position: Point, color: Color, + viewport: Rectangle, ) { self.primitives.push(Primitive::Paragraph { paragraph: paragraph.downgrade(), position, color, + viewport, }); } @@ -177,11 +179,13 @@ where editor: &Self::Editor, position: Point, color: Color, + viewport: Rectangle, ) { self.primitives.push(Primitive::Editor { editor: editor.downgrade(), position, color, + viewport, }); } @@ -190,6 +194,7 @@ where text: Text<'_, Self::Font>, position: Point, color: Color, + viewport: Rectangle, ) { self.primitives.push(Primitive::Text { content: text.content.to_string(), @@ -201,6 +206,7 @@ where horizontal_alignment: text.horizontal_alignment, vertical_alignment: text.vertical_alignment, shaping: text.shaping, + viewport, }); } } -- cgit From b526ce4958b28208395276dd4078ffe0d780e1d7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 2 Dec 2023 15:53:02 +0100 Subject: Rename `viewport` to `clip_bounds` --- graphics/src/primitive.rs | 12 ++++++------ graphics/src/renderer.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'graphics/src') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 837eb77a..ed75776c 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -32,8 +32,8 @@ pub enum Primitive { vertical_alignment: alignment::Vertical, /// The shaping strategy of the text. shaping: text::Shaping, - /// The viewport of the text. - viewport: Rectangle, + /// The clip bounds of the text. + clip_bounds: Rectangle, }, /// A paragraph primitive Paragraph { @@ -43,8 +43,8 @@ pub enum Primitive { position: Point, /// The color of the paragraph. color: Color, - /// The viewport of the paragraph. - viewport: Rectangle, + /// The clip bounds of the paragraph. + clip_bounds: Rectangle, }, /// An editor primitive Editor { @@ -54,8 +54,8 @@ pub enum Primitive { position: Point, /// The color of the editor. color: Color, - /// The viewport of the editor. - viewport: Rectangle, + /// The clip bounds of the editor. + clip_bounds: Rectangle, }, /// A quad primitive Quad { diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index 0d3b11a7..1b0f5c5b 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -164,13 +164,13 @@ where paragraph: &Self::Paragraph, position: Point, color: Color, - viewport: Rectangle, + clip_bounds: Rectangle, ) { self.primitives.push(Primitive::Paragraph { paragraph: paragraph.downgrade(), position, color, - viewport, + clip_bounds, }); } @@ -179,13 +179,13 @@ where editor: &Self::Editor, position: Point, color: Color, - viewport: Rectangle, + clip_bounds: Rectangle, ) { self.primitives.push(Primitive::Editor { editor: editor.downgrade(), position, color, - viewport, + clip_bounds, }); } @@ -194,7 +194,7 @@ where text: Text<'_, Self::Font>, position: Point, color: Color, - viewport: Rectangle, + clip_bounds: Rectangle, ) { self.primitives.push(Primitive::Text { content: text.content.to_string(), @@ -206,7 +206,7 @@ where horizontal_alignment: text.horizontal_alignment, vertical_alignment: text.vertical_alignment, shaping: text.shaping, - viewport, + clip_bounds, }); } } -- cgit