Implement explicit text caching in the widget state tree

This commit is contained in:
Héctor Ramón Jiménez 2023-08-30 04:31:21 +02:00
parent c9bd48704d
commit ed3454301e
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
79 changed files with 1910 additions and 1705 deletions

View file

@ -16,7 +16,10 @@ pub use geometry::Geometry;
use crate::core::renderer;
use crate::core::text::{self, Text};
use crate::core::{Background, Font, Point, Rectangle, Size, Vector};
use crate::core::{
Background, Color, Font, Pixels, Point, Rectangle, Size, Vector,
};
use crate::graphics::text::Paragraph;
use crate::graphics::Mesh;
use std::borrow::Cow;
@ -142,6 +145,7 @@ impl<T> core::Renderer for Renderer<T> {
impl<T> text::Renderer for Renderer<T> {
type Font = Font;
type Paragraph = Paragraph;
const ICON_FONT: Font = iced_tiny_skia::Renderer::<T>::ICON_FONT;
const CHECKMARK_ICON: char = iced_tiny_skia::Renderer::<T>::CHECKMARK_ICON;
@ -152,59 +156,50 @@ impl<T> text::Renderer for Renderer<T> {
delegate!(self, renderer, renderer.default_font())
}
fn default_size(&self) -> f32 {
fn default_size(&self) -> Pixels {
delegate!(self, renderer, renderer.default_size())
}
fn measure(
&self,
content: &str,
size: f32,
line_height: text::LineHeight,
font: Font,
bounds: Size,
shaping: text::Shaping,
) -> Size {
delegate!(
self,
renderer,
renderer.measure(content, size, line_height, font, bounds, shaping)
)
fn create_paragraph(&self, text: Text<'_, Self::Font>) -> Self::Paragraph {
delegate!(self, renderer, renderer.create_paragraph(text))
}
fn hit_test(
fn resize_paragraph(
&self,
content: &str,
size: f32,
line_height: text::LineHeight,
font: Font,
bounds: Size,
shaping: text::Shaping,
point: Point,
nearest_only: bool,
) -> Option<text::Hit> {
paragraph: &mut Self::Paragraph,
new_bounds: Size,
) {
delegate!(
self,
renderer,
renderer.hit_test(
content,
size,
line_height,
font,
bounds,
shaping,
point,
nearest_only
)
)
renderer.resize_paragraph(paragraph, new_bounds)
);
}
fn load_font(&mut self, bytes: Cow<'static, [u8]>) {
delegate!(self, renderer, renderer.load_font(bytes));
}
fn fill_text(&mut self, text: Text<'_, Self::Font>) {
delegate!(self, renderer, renderer.fill_text(text));
fn fill_paragraph(
&mut self,
text: &Self::Paragraph,
position: Point,
color: Color,
) {
delegate!(
self,
renderer,
renderer.fill_paragraph(text, position, color)
);
}
fn fill_text(
&mut self,
text: Text<'_, Self::Font>,
position: Point,
color: Color,
) {
delegate!(self, renderer, renderer.fill_text(text, position, color));
}
}