Introduce RawText to Primitive in iced_graphics
This should allow users to directly render a `cosmic_text::Buffer`.
This commit is contained in:
parent
fc285d3e46
commit
603832e66c
8 changed files with 131 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue