summaryrefslogtreecommitdiffstats
path: root/wgpu/src/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-12-05 02:19:17 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-12-05 02:19:17 +0100
commit603832e66c710ea39a95009ddc905de20c6856bd (patch)
tree9682de5108d8102b25c109c0388556c7c49794ec /wgpu/src/text.rs
parentfc285d3e461626408c56bbc1605fcf0c974b2f69 (diff)
downloadiced-603832e66c710ea39a95009ddc905de20c6856bd.tar.gz
iced-603832e66c710ea39a95009ddc905de20c6856bd.tar.bz2
iced-603832e66c710ea39a95009ddc905de20c6856bd.zip
Introduce `RawText` to `Primitive` in `iced_graphics`
This should allow users to directly render a `cosmic_text::Buffer`.
Diffstat (limited to 'wgpu/src/text.rs')
-rw-r--r--wgpu/src/text.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 888b1924..dca09cb8 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -7,6 +7,7 @@ use crate::layer::Text;
use std::borrow::Cow;
use std::cell::RefCell;
+use std::sync::Arc;
#[allow(missing_debug_implementations)]
pub struct Pipeline {
@@ -76,6 +77,7 @@ impl Pipeline {
Paragraph(Paragraph),
Editor(Editor),
Cache(cache::KeyHash),
+ Raw(Arc<glyphon::Buffer>),
}
let allocations: Vec<_> = sections
@@ -107,6 +109,7 @@ impl Pipeline {
Some(Allocation::Cache(key))
}
+ Text::Raw(text) => text.buffer.upgrade().map(Allocation::Raw),
})
.collect();
@@ -185,6 +188,25 @@ impl Pipeline {
text.clip_bounds,
)
}
+ Text::Raw(text) => {
+ let Some(Allocation::Raw(buffer)) = allocation else {
+ return None;
+ };
+
+ let (width, height) = buffer.size();
+
+ (
+ buffer.as_ref(),
+ Rectangle::new(
+ text.position,
+ Size::new(width, height),
+ ),
+ alignment::Horizontal::Left,
+ alignment::Vertical::Top,
+ text.color,
+ text.clip_bounds,
+ )
+ }
};
let bounds = bounds * scale_factor;