Make iced_tiny_skia optional with a tiny-skia feature

This commit is contained in:
Héctor Ramón Jiménez 2024-03-22 05:27:31 +01:00
parent bbafeed13d
commit 1f13a91361
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
20 changed files with 157 additions and 91 deletions

View file

@ -95,7 +95,7 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
///
/// ```no_run
/// # mod iced {
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, iced_core::renderer::Null>;
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, ()>;
/// #
/// # pub mod widget {
/// # pub fn row<'a, Message>(iter: impl IntoIterator<Item = super::Element<'a, Message>>) -> super::Element<'a, Message> {
@ -109,7 +109,7 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
/// # pub enum Message {}
/// # pub struct Counter;
/// #
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, iced_core::renderer::Null>;
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, ()>;
/// #
/// # impl Counter {
/// # pub fn view(&self) -> Element<Message> {

View file

@ -1,10 +1,6 @@
//! Write your own renderer.
#[cfg(debug_assertions)]
mod null;
#[cfg(debug_assertions)]
pub use null::Null;
use crate::{
Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector,
};

View file

@ -1,4 +1,5 @@
use crate::alignment;
use crate::image;
use crate::renderer::{self, Renderer};
use crate::text::{self, Text};
use crate::{
@ -7,20 +8,7 @@ use crate::{
use std::borrow::Cow;
/// A renderer that does nothing.
///
/// It can be useful if you are writing tests!
#[derive(Debug, Clone, Copy, Default)]
pub struct Null;
impl Null {
/// Creates a new [`Null`] renderer.
pub fn new() -> Null {
Null
}
}
impl Renderer for Null {
impl Renderer for () {
fn start_layer(&mut self) {}
fn end_layer(&mut self, _bounds: Rectangle) {}
@ -39,7 +27,7 @@ impl Renderer for Null {
}
}
impl text::Renderer for Null {
impl text::Renderer for () {
type Font = Font;
type Paragraph = ();
type Editor = ();
@ -173,3 +161,19 @@ impl text::Editor for () {
) {
}
}
impl image::Renderer for () {
type Handle = ();
fn measure_image(&self, _handle: &Self::Handle) -> Size<u32> {
Size::default()
}
fn draw_image(
&mut self,
_handle: Self::Handle,
_filter_method: image::FilterMethod,
_bounds: Rectangle,
) {
}
}

View file

@ -1,7 +1,7 @@
use crate::Vector;
/// An amount of space in 2 dimensions.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Size<T = f32> {
/// The width.
pub width: T,