Create iced_widget subcrate and re-organize the whole codebase

This commit is contained in:
Héctor Ramón Jiménez 2023-03-04 05:37:11 +01:00
parent c54409d171
commit 3a0d34c024
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
209 changed files with 1959 additions and 2183 deletions

View file

@ -39,13 +39,9 @@ bitflags = "1.2"
version = "1.4"
features = ["derive"]
[dependencies.iced_native]
version = "0.9"
path = "../native"
[dependencies.iced_style]
version = "0.7"
path = "../style"
[dependencies.iced_core]
version = "0.8"
path = "../core"
[dependencies.tiny-skia]
version = "0.8"

View file

@ -1,8 +1,8 @@
//! Write a graphics backend.
use iced_native::image;
use iced_native::svg;
use iced_native::text;
use iced_native::{Font, Point, Size};
use iced_core::image;
use iced_core::svg;
use iced_core::text;
use iced_core::{Font, Point, Size};
use std::borrow::Cow;

View file

@ -1,6 +1,8 @@
//! A compositor is responsible for initializing a renderer and managing window
//! surfaces.
use crate::{Color, Error, Viewport};
use crate::{Error, Viewport};
use iced_core::Color;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use thiserror::Error;
@ -11,7 +13,7 @@ pub trait Compositor: Sized {
type Settings: Default;
/// The iced renderer of the backend.
type Renderer: iced_native::Renderer;
type Renderer: iced_core::Renderer;
/// The surface of the backend.
type Surface;

View file

@ -16,7 +16,7 @@ pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
pub use style::Style;
pub use text::Text;
pub use iced_native::gradient::{self, Gradient};
pub use iced_core::gradient::{self, Gradient};
use crate::Primitive;
@ -29,7 +29,7 @@ impl From<Geometry> for Primitive {
}
}
pub trait Renderer: iced_native::Renderer {
pub trait Renderer: iced_core::Renderer {
type Geometry;
fn draw(&mut self, geometry: Vec<Self::Geometry>);

View file

@ -1,5 +1,5 @@
//! Fill [crate::widget::canvas::Geometry] with a certain style.
use crate::{Color, Gradient};
use iced_core::{Color, Gradient};
pub use crate::geometry::Style;

View file

@ -9,7 +9,7 @@ pub use builder::Builder;
pub use lyon_path;
use crate::{Point, Size};
use iced_core::{Point, Size};
/// An immutable set of points that may or may not be connected.
///

View file

@ -1,5 +1,5 @@
//! Build and draw curves.
use crate::{Point, Vector};
use iced_core::{Point, Vector};
/// A segment of a differentiable curve.
#[derive(Debug, Clone, Copy)]

View file

@ -1,5 +1,6 @@
use crate::geometry::path::{arc, Arc, Path};
use crate::{Point, Size};
use iced_core::{Point, Size};
use lyon_path::builder::{self, SvgPathBuilder};
use lyon_path::geom;

View file

@ -1,7 +1,7 @@
//! Create lines from a [crate::widget::canvas::Path] and assigns them various attributes/styles.
pub use crate::geometry::Style;
use crate::Color;
use iced_core::Color;
/// The style of a stroke.
#[derive(Debug, Clone)]

View file

@ -1,4 +1,4 @@
use crate::{Color, Gradient};
use iced_core::{Color, Gradient};
/// The coloring style of some drawing.
#[derive(Debug, Clone, PartialEq)]

View file

@ -1,5 +1,5 @@
use crate::alignment;
use crate::{Color, Font, Point};
use iced_core::alignment;
use iced_core::{Color, Font, Point};
/// A bunch of text that can be drawn to a canvas
#[derive(Debug, Clone)]

View file

@ -1,8 +1,8 @@
//! Raster image loading and caching.
use crate::image::Storage;
use crate::Size;
use iced_native::image;
use iced_core::image;
use iced_core::Size;
use bitflags::bitflags;
use std::collections::{HashMap, HashSet};

View file

@ -1,5 +1,5 @@
//! Store images.
use crate::Size;
use iced_core::Size;
use std::fmt::Debug;

View file

@ -1,9 +1,8 @@
//! Vector image loading and caching
use crate::image::Storage;
use crate::Color;
use iced_native::svg;
use iced_native::Size;
use iced_core::svg;
use iced_core::{Color, Size};
use resvg::tiny_skia;
use resvg::usvg;

View file

@ -27,17 +27,17 @@ mod transformation;
mod viewport;
pub mod backend;
pub mod compositor;
pub mod image;
pub mod overlay;
pub mod primitive;
pub mod renderer;
pub mod window;
#[cfg(feature = "geometry")]
pub mod geometry;
pub use antialiasing::Antialiasing;
pub use backend::Backend;
pub use compositor::Compositor;
pub use error::Error;
pub use primitive::Primitive;
pub use renderer::Renderer;
@ -47,9 +47,4 @@ pub use viewport::Viewport;
#[cfg(feature = "geometry")]
pub use geometry::Geometry;
pub use iced_native::alignment;
pub use iced_native::text;
pub use iced_native::{
Alignment, Background, Color, Font, Gradient, Point, Rectangle, Size,
Vector,
};
pub use iced_core as core;

View file

@ -1,2 +0,0 @@
//! Display interactive elements on top of other widgets.
pub mod menu;

View file

@ -1,3 +0,0 @@
//! Build and show dropdown menus.
pub use iced_style::menu::{Appearance, StyleSheet};

View file

@ -1,8 +1,7 @@
use crate::alignment;
use iced_native::image;
use iced_native::svg;
use iced_native::{Background, Color, Font, Gradient, Rectangle, Size, Vector};
use iced_core::alignment;
use iced_core::image;
use iced_core::svg;
use iced_core::{Background, Color, Font, Gradient, Rectangle, Size, Vector};
use bytemuck::{Pod, Zeroable};
use std::sync::Arc;

View file

@ -1,15 +1,15 @@
//! Create a renderer from a [`Backend`].
use crate::backend::{self, Backend};
use crate::{Primitive, Vector};
use crate::Primitive;
use iced_native::image;
use iced_native::layout;
use iced_native::renderer;
use iced_native::svg;
use iced_native::text::{self, Text};
use iced_native::{Background, Color, Element, Font, Point, Rectangle, Size};
pub use iced_native::renderer::Style;
use iced_core::image;
use iced_core::layout;
use iced_core::renderer;
use iced_core::svg;
use iced_core::text::{self, Text};
use iced_core::{
Background, Color, Element, Font, Point, Rectangle, Size, Vector,
};
use std::borrow::Cow;
use std::marker::PhantomData;
@ -52,7 +52,7 @@ impl<B: Backend, T> Renderer<B, T> {
}
}
impl<B, T> iced_native::Renderer for Renderer<B, T>
impl<B, T> iced_core::Renderer for Renderer<B, T>
where
B: Backend,
{

View file

@ -1,4 +1,6 @@
use crate::{Size, Transformation};
use crate::Transformation;
use iced_core::Size;
/// A viewing region for displaying computer graphics.
#[derive(Debug, Clone)]

View file

@ -1,10 +0,0 @@
//! Draw graphics to window surfaces.
pub mod compositor;
#[cfg(feature = "opengl")]
pub mod gl_compositor;
pub use compositor::Compositor;
#[cfg(feature = "opengl")]
pub use gl_compositor::GLCompositor;

View file

@ -1,71 +0,0 @@
//! A compositor is responsible for initializing a renderer and managing window
//! surfaces.
use crate::window::compositor::Information;
use crate::{Color, Error, Size, Viewport};
use core::ffi::c_void;
/// A basic OpenGL compositor.
///
/// A compositor is responsible for initializing a renderer and managing window
/// surfaces.
///
/// For now, this compositor only deals with a single global surface
/// for drawing. However, the trait will most likely change in the near future
/// to handle multiple surfaces at once.
///
/// If you implement an OpenGL renderer, you can implement this trait to ease
/// integration with existing windowing shells, like `iced_glutin`.
pub trait GLCompositor: Sized {
/// The renderer of the [`GLCompositor`].
///
/// This should point to your renderer type, which could be a type alias
/// of the [`Renderer`] provided in this crate with with a specific
/// [`Backend`].
///
/// [`Renderer`]: crate::Renderer
/// [`Backend`]: crate::Backend
type Renderer: iced_native::Renderer;
/// The settings of the [`GLCompositor`].
///
/// It's up to you to decide the configuration supported by your renderer!
type Settings: Default;
/// Creates a new [`GLCompositor`] and [`Renderer`] with the given
/// [`Settings`] and an OpenGL address loader function.
///
/// # Safety
/// The `loader_function` should resolve to valid OpenGL bindings.
///
/// [`Renderer`]: crate::Renderer
/// [`Backend`]: crate::Backend
/// [`Settings`]: Self::Settings
#[allow(unsafe_code)]
unsafe fn new(
settings: Self::Settings,
loader_function: impl FnMut(&str) -> *const c_void,
) -> Result<(Self, Self::Renderer), Error>;
/// Returns the amount of samples that should be used when configuring
/// an OpenGL context for this [`GLCompositor`].
fn sample_count(settings: &Self::Settings) -> u32;
/// Resizes the viewport of the [`GLCompositor`].
fn resize_viewport(&mut self, physical_size: Size<u32>);
/// Returns [`Information`] used by this [`GLCompositor`].
fn fetch_information(&self) -> Information;
/// Presents the primitives of the [`Renderer`] to the next frame of the
/// [`GLCompositor`].
///
/// [`Renderer`]: crate::Renderer
fn present<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
);
}