Implement explicit text caching in the widget state tree
This commit is contained in:
parent
c9bd48704d
commit
ed3454301e
79 changed files with 1910 additions and 1705 deletions
|
|
@ -1,8 +1,8 @@
|
|||
//! Write a graphics backend.
|
||||
use iced_core::image;
|
||||
use iced_core::svg;
|
||||
use iced_core::text;
|
||||
use iced_core::{Font, Point, Size};
|
||||
use crate::core::image;
|
||||
use crate::core::svg;
|
||||
use crate::core::Size;
|
||||
use crate::text;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
|
@ -12,70 +12,15 @@ use std::borrow::Cow;
|
|||
pub trait Backend {
|
||||
/// The custom kind of primitives this [`Backend`] supports.
|
||||
type Primitive;
|
||||
|
||||
/// Trims the measurements cache.
|
||||
///
|
||||
/// This method is currently necessary to properly trim the text cache in
|
||||
/// `iced_wgpu` and `iced_glow` because of limitations in the text rendering
|
||||
/// pipeline. It will be removed in the future.
|
||||
fn trim_measurements(&mut self) {}
|
||||
}
|
||||
|
||||
/// A graphics backend that supports text rendering.
|
||||
pub trait Text {
|
||||
/// The icon font of the backend.
|
||||
const ICON_FONT: Font;
|
||||
|
||||
/// The `char` representing a ✔ icon in the [`ICON_FONT`].
|
||||
///
|
||||
/// [`ICON_FONT`]: Self::ICON_FONT
|
||||
const CHECKMARK_ICON: char;
|
||||
|
||||
/// The `char` representing a ▼ icon in the built-in [`ICON_FONT`].
|
||||
///
|
||||
/// [`ICON_FONT`]: Self::ICON_FONT
|
||||
const ARROW_DOWN_ICON: char;
|
||||
|
||||
/// Returns the default [`Font`].
|
||||
fn default_font(&self) -> Font;
|
||||
|
||||
/// Returns the default size of text.
|
||||
fn default_size(&self) -> f32;
|
||||
|
||||
/// Measures the text contents with the given size and font,
|
||||
/// returning the size of a laid out paragraph that fits in the provided
|
||||
/// bounds.
|
||||
fn measure(
|
||||
&self,
|
||||
contents: &str,
|
||||
size: f32,
|
||||
line_height: text::LineHeight,
|
||||
font: Font,
|
||||
bounds: Size,
|
||||
shaping: text::Shaping,
|
||||
) -> Size;
|
||||
|
||||
/// Tests whether the provided point is within the boundaries of [`Text`]
|
||||
/// laid out with the given parameters, returning information about
|
||||
/// the nearest character.
|
||||
///
|
||||
/// If nearest_only is true, the hit test does not consider whether the
|
||||
/// the point is interior to any glyph bounds, returning only the character
|
||||
/// with the nearest centeroid.
|
||||
fn hit_test(
|
||||
&self,
|
||||
contents: &str,
|
||||
size: f32,
|
||||
line_height: text::LineHeight,
|
||||
font: Font,
|
||||
bounds: Size,
|
||||
shaping: text::Shaping,
|
||||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> Option<text::Hit>;
|
||||
|
||||
/// Loads a [`Font`] from its bytes.
|
||||
fn load_font(&mut self, font: Cow<'static, [u8]>);
|
||||
|
||||
/// Returns the [`cosmic_text::FontSystem`] of the [`Backend`].
|
||||
fn font_system(&self) -> &text::FontSystem;
|
||||
}
|
||||
|
||||
/// A graphics backend that supports image rendering.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue