2020-05-28 01:37:59 +02:00
|
|
|
//! Write a graphics backend.
|
2023-03-04 05:37:11 +01:00
|
|
|
use iced_core::image;
|
|
|
|
|
use iced_core::svg;
|
|
|
|
|
use iced_core::text;
|
|
|
|
|
use iced_core::{Font, Point, Size};
|
2020-05-19 17:15:44 +02:00
|
|
|
|
2023-02-04 11:12:15 +01:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
2020-05-28 01:37:59 +02:00
|
|
|
/// The graphics backend of a [`Renderer`].
|
|
|
|
|
///
|
2020-11-25 07:11:27 +01:00
|
|
|
/// [`Renderer`]: crate::Renderer
|
2020-05-19 17:15:44 +02:00
|
|
|
pub trait Backend {
|
2020-05-28 01:37:59 +02:00
|
|
|
/// 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.
|
2020-05-19 17:15:44 +02:00
|
|
|
fn trim_measurements(&mut self) {}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 01:37:59 +02:00
|
|
|
/// A graphics backend that supports text rendering.
|
2020-05-19 17:15:44 +02:00
|
|
|
pub trait Text {
|
2020-05-28 01:37:59 +02:00
|
|
|
/// The icon font of the backend.
|
2020-05-19 17:15:44 +02:00
|
|
|
const ICON_FONT: Font;
|
2020-05-28 01:37:59 +02:00
|
|
|
|
|
|
|
|
/// The `char` representing a ✔ icon in the [`ICON_FONT`].
|
|
|
|
|
///
|
2020-11-25 05:26:03 +01:00
|
|
|
/// [`ICON_FONT`]: Self::ICON_FONT
|
2020-05-19 17:15:44 +02:00
|
|
|
const CHECKMARK_ICON: char;
|
|
|
|
|
|
2020-11-25 05:26:03 +01:00
|
|
|
/// The `char` representing a ▼ icon in the built-in [`ICON_FONT`].
|
2020-04-18 19:53:27 +02:00
|
|
|
///
|
2020-11-25 05:26:03 +01:00
|
|
|
/// [`ICON_FONT`]: Self::ICON_FONT
|
2020-04-18 19:53:27 +02:00
|
|
|
const ARROW_DOWN_ICON: char;
|
|
|
|
|
|
2023-02-04 07:33:33 +01:00
|
|
|
/// Returns the default [`Font`].
|
|
|
|
|
fn default_font(&self) -> Font;
|
|
|
|
|
|
2020-06-19 00:08:28 +02:00
|
|
|
/// Returns the default size of text.
|
2023-02-04 16:41:18 +01:00
|
|
|
fn default_size(&self) -> f32;
|
2020-06-19 00:08:28 +02:00
|
|
|
|
2020-05-28 01:37:59 +02:00
|
|
|
/// Measures the text contents with the given size and font,
|
|
|
|
|
/// returning the size of a laid out paragraph that fits in the provided
|
|
|
|
|
/// bounds.
|
2020-05-19 17:15:44 +02:00
|
|
|
fn measure(
|
|
|
|
|
&self,
|
|
|
|
|
contents: &str,
|
|
|
|
|
size: f32,
|
2023-05-04 13:00:16 +02:00
|
|
|
line_height: text::LineHeight,
|
2020-05-19 17:15:44 +02:00
|
|
|
font: Font,
|
|
|
|
|
bounds: Size,
|
2023-04-19 02:00:45 +02:00
|
|
|
shaping: text::Shaping,
|
2020-05-19 17:15:44 +02:00
|
|
|
) -> (f32, f32);
|
2021-08-21 10:31:26 -07:00
|
|
|
|
|
|
|
|
/// 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,
|
2023-05-04 13:00:16 +02:00
|
|
|
line_height: text::LineHeight,
|
2021-08-21 10:31:26 -07:00
|
|
|
font: Font,
|
|
|
|
|
bounds: Size,
|
2023-04-19 02:00:45 +02:00
|
|
|
shaping: text::Shaping,
|
2021-08-21 10:31:26 -07:00
|
|
|
point: Point,
|
|
|
|
|
nearest_only: bool,
|
2021-09-15 14:49:13 +07:00
|
|
|
) -> Option<text::Hit>;
|
2023-02-04 11:12:15 +01:00
|
|
|
|
|
|
|
|
/// Loads a [`Font`] from its bytes.
|
|
|
|
|
fn load_font(&mut self, font: Cow<'static, [u8]>);
|
2020-05-19 17:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 01:37:59 +02:00
|
|
|
/// A graphics backend that supports image rendering.
|
2020-05-19 17:15:44 +02:00
|
|
|
pub trait Image {
|
2020-05-28 01:37:59 +02:00
|
|
|
/// Returns the dimensions of the provided image.
|
2022-11-05 03:13:04 +01:00
|
|
|
fn dimensions(&self, handle: &image::Handle) -> Size<u32>;
|
2020-05-19 17:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 01:37:59 +02:00
|
|
|
/// A graphics backend that supports SVG rendering.
|
2020-05-19 17:15:44 +02:00
|
|
|
pub trait Svg {
|
2020-05-28 01:37:59 +02:00
|
|
|
/// Returns the viewport dimensions of the provided SVG.
|
2022-11-05 03:13:04 +01:00
|
|
|
fn viewport_dimensions(&self, handle: &svg::Handle) -> Size<u32>;
|
2020-05-19 17:15:44 +02:00
|
|
|
}
|