summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-01-12 06:45:40 +0100
committerLibravatar GitHub <noreply@github.com>2024-01-12 06:45:40 +0100
commita5ae442819227b3cd55116028e6d6c96caa6fda9 (patch)
tree111e7b424a2c7044f8d98612015540282bf2ca8a /graphics
parent89fc4f54bdbf62a29fcd06bc2e77926180143413 (diff)
parent603832e66c710ea39a95009ddc905de20c6856bd (diff)
downloadiced-a5ae442819227b3cd55116028e6d6c96caa6fda9.tar.gz
iced-a5ae442819227b3cd55116028e6d6c96caa6fda9.tar.bz2
iced-a5ae442819227b3cd55116028e6d6c96caa6fda9.zip
Merge pull request #2158 from iced-rs/feature/raw-text-primitive
Introduce `RawText` to `Primitive` in `iced_graphics`
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/damage.rs5
-rw-r--r--graphics/src/primitive.rs2
-rw-r--r--graphics/src/text.rs27
3 files changed, 32 insertions, 2 deletions
diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs
index 595cc274..59e9f5b4 100644
--- a/graphics/src/damage.rs
+++ b/graphics/src/damage.rs
@@ -73,6 +73,11 @@ impl<T: Damage> Damage for Primitive<T> {
bounds.expand(1.5)
}
+ Self::RawText(raw) => {
+ // TODO: Add `size` field to `raw` to compute more accurate
+ // damage bounds (?)
+ raw.clip_bounds.expand(1.5)
+ }
Self::Quad { bounds, .. }
| Self::Image { bounds, .. }
| Self::Svg { bounds, .. } => bounds.expand(1.0),
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs
index ed75776c..20affaaf 100644
--- a/graphics/src/primitive.rs
+++ b/graphics/src/primitive.rs
@@ -57,6 +57,8 @@ pub enum Primitive<T> {
/// The clip bounds of the editor.
clip_bounds: Rectangle,
},
+ /// A raw `cosmic-text` primitive
+ RawText(crate::text::Raw),
/// A quad primitive
Quad {
/// The bounds of the quad
diff --git a/graphics/src/text.rs b/graphics/src/text.rs
index fc7694c2..8fd037fe 100644
--- a/graphics/src/text.rs
+++ b/graphics/src/text.rs
@@ -12,11 +12,11 @@ pub use cosmic_text;
use crate::color;
use crate::core::font::{self, Font};
use crate::core::text::Shaping;
-use crate::core::{Color, Size};
+use crate::core::{Color, Point, Rectangle, Size};
use once_cell::sync::OnceCell;
use std::borrow::Cow;
-use std::sync::{Arc, RwLock};
+use std::sync::{Arc, RwLock, Weak};
/// Returns the global [`FontSystem`].
pub fn font_system() -> &'static RwLock<FontSystem> {
@@ -68,6 +68,29 @@ impl FontSystem {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Version(u32);
+/// A weak reference to a [`cosmic-text::Buffer`] that can be drawn.
+#[derive(Debug, Clone)]
+pub struct Raw {
+ /// A weak reference to a [`cosmic_text::Buffer`].
+ pub buffer: Weak<cosmic_text::Buffer>,
+ /// The position of the text.
+ pub position: Point,
+ /// The color of the text.
+ pub color: Color,
+ /// The clip bounds of the text.
+ pub clip_bounds: Rectangle,
+}
+
+impl PartialEq for Raw {
+ fn eq(&self, _other: &Self) -> bool {
+ // TODO: There is no proper way to compare raw buffers
+ // For now, no two instances of `Raw` text will be equal.
+ // This should be fine, but could trigger unnecessary redraws
+ // in the future.
+ false
+ }
+}
+
/// Measures the dimensions of the given [`cosmic_text::Buffer`].
pub fn measure(buffer: &cosmic_text::Buffer) -> Size {
let (width, total_lines) = buffer