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

@ -13,13 +13,15 @@ categories = ["gui"]
[features] [features]
# Enables the `Image` widget # Enables the `Image` widget
image = ["iced_renderer/image", "image_rs"] image = ["iced_widget/image", "image_rs"]
# Enables the `Svg` widget # Enables the `Svg` widget
svg = ["iced_renderer/svg"] svg = ["iced_widget/svg"]
# Enables the `Canvas` widget # Enables the `Canvas` widget
canvas = ["iced_renderer/geometry"] canvas = ["iced_widget/canvas"]
# Enables the `QRCode` widget # Enables the `QRCode` widget
qr_code = ["canvas", "qrcode"] qr_code = ["iced_widget/qr_code"]
# Enables lazy widgets
lazy = ["iced_widget/lazy"]
# Enables a debug view in native platforms (press F12) # Enables a debug view in native platforms (press F12)
debug = ["iced_winit/debug"] debug = ["iced_winit/debug"]
# Enables `tokio` as the `executor::Default` on native platforms # Enables `tokio` as the `executor::Default` on native platforms
@ -32,11 +34,8 @@ smol = ["iced_futures/smol"]
palette = ["iced_core/palette"] palette = ["iced_core/palette"]
# Enables querying system information # Enables querying system information
system = ["iced_winit/system"] system = ["iced_winit/system"]
# Enables chrome traces # Enables the advanced module
chrome-trace = [ advanced = []
"iced_winit/chrome-trace",
"iced_renderer/tracing",
]
[badges] [badges]
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
@ -46,12 +45,12 @@ members = [
"core", "core",
"futures", "futures",
"graphics", "graphics",
"lazy",
"native", "native",
"renderer", "renderer",
"style", "style",
"tiny_skia", "tiny_skia",
"wgpu", "wgpu",
"widget",
"winit", "winit",
"examples/*", "examples/*",
] ]
@ -59,21 +58,15 @@ members = [
[dependencies] [dependencies]
iced_core = { version = "0.8", path = "core" } iced_core = { version = "0.8", path = "core" }
iced_futures = { version = "0.6", path = "futures" } iced_futures = { version = "0.6", path = "futures" }
iced_native = { version = "0.9", path = "native" } iced_widget = { version = "0.1", path = "widget" }
iced_renderer = { version = "0.1", path = "renderer" }
iced_winit = { version = "0.8", path = "winit", features = ["application"] } iced_winit = { version = "0.8", path = "winit", features = ["application"] }
thiserror = "1.0" thiserror = "1"
[dependencies.image_rs] [dependencies.image_rs]
version = "0.24" version = "0.24"
package = "image" package = "image"
optional = true optional = true
[dependencies.qrcode]
version = "0.12"
optional = true
default-features = false
[package.metadata.docs.rs] [package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs"]
features = ["image", "svg", "canvas", "qr_code"] features = ["image", "svg", "canvas", "qr_code"]

View file

@ -10,6 +10,7 @@ repository = "https://github.com/iced-rs/iced"
[dependencies] [dependencies]
bitflags = "1.2" bitflags = "1.2"
thiserror = "1" thiserror = "1"
twox-hash = { version = "1.5", default-features = false }
[dependencies.palette] [dependencies.palette]
version = "0.6" version = "0.6"

23
core/src/clipboard.rs Normal file
View file

@ -0,0 +1,23 @@
//! Access the clipboard.
/// A buffer for short-term storage and transfer within and between
/// applications.
pub trait Clipboard {
/// Reads the current content of the [`Clipboard`] as text.
fn read(&self) -> Option<String>;
/// Writes the given text contents to the [`Clipboard`].
fn write(&mut self, contents: String);
}
/// A null implementation of the [`Clipboard`] trait.
#[derive(Debug, Clone, Copy)]
pub struct Null;
impl Clipboard for Null {
fn read(&self) -> Option<String> {
None
}
fn write(&mut self, _contents: String) {}
}

View file

@ -90,41 +90,65 @@ impl<'a, Message, Renderer> Element<'a, Message, Renderer> {
/// We compose the previous __messages__ with the index of the counter /// We compose the previous __messages__ with the index of the counter
/// producing them. Let's implement our __view logic__ now: /// producing them. Let's implement our __view logic__ now:
/// ///
/// ``` /// ```no_run
/// # mod counter { /// # mod counter {
/// # type Text<'a> = iced_native::widget::Text<'a, iced_native::renderer::Null>;
/// #
/// # #[derive(Debug, Clone, Copy)] /// # #[derive(Debug, Clone, Copy)]
/// # pub enum Message {} /// # pub enum Message {}
/// # pub struct Counter; /// # pub struct Counter;
/// # /// #
/// # impl Counter { /// # impl Counter {
/// # pub fn view(&mut self) -> Text { /// # pub fn view(
/// # Text::new("") /// # &self,
/// # ) -> iced_core::Element<Message, iced_core::renderer::Null> {
/// # unimplemented!()
/// # } /// # }
/// # } /// # }
/// # } /// # }
/// # /// #
/// # mod iced_wgpu { /// # mod iced {
/// # pub use iced_native::renderer::Null as Renderer; /// # pub use iced_core::renderer::Null as Renderer;
/// # pub use iced_core::Element;
/// #
/// # pub mod widget {
/// # pub struct Row<Message> {
/// # _t: std::marker::PhantomData<Message>,
/// # }
/// #
/// # impl<Message> Row<Message> {
/// # pub fn new() -> Self {
/// # unimplemented!()
/// # }
/// #
/// # pub fn spacing(mut self, _: u32) -> Self {
/// # unimplemented!()
/// # }
/// #
/// # pub fn push(
/// # mut self,
/// # _: iced_core::Element<Message, iced_core::renderer::Null>,
/// # ) -> Self {
/// # unimplemented!()
/// # }
/// # }
/// # }
/// # } /// # }
/// # /// #
/// # use counter::Counter; /// use counter::Counter;
/// # ///
/// # struct ManyCounters { /// use iced::widget::Row;
/// # counters: Vec<Counter>, /// use iced::{Element, Renderer};
/// # } ///
/// # /// struct ManyCounters {
/// # #[derive(Debug, Clone, Copy)] /// counters: Vec<Counter>,
/// # pub enum Message { /// }
/// # Counter(usize, counter::Message) ///
/// # } /// #[derive(Debug, Clone, Copy)]
/// use iced_native::Element; /// pub enum Message {
/// use iced_native::widget::Row; /// Counter(usize, counter::Message),
/// use iced_wgpu::Renderer; /// }
/// ///
/// impl ManyCounters { /// impl ManyCounters {
/// pub fn view(&mut self) -> Row<Message, Renderer> { /// pub fn view(&mut self) -> Row<Message> {
/// // We can quickly populate a `Row` by folding over our counters /// // We can quickly populate a `Row` by folding over our counters
/// self.counters.iter_mut().enumerate().fold( /// self.counters.iter_mut().enumerate().fold(
/// Row::new().spacing(20), /// Row::new().spacing(20),
@ -137,9 +161,10 @@ impl<'a, Message, Renderer> Element<'a, Message, Renderer> {
/// // Here we turn our `Element<counter::Message>` into /// // Here we turn our `Element<counter::Message>` into
/// // an `Element<Message>` by combining the `index` and the /// // an `Element<Message>` by combining the `index` and the
/// // message of the `element`. /// // message of the `element`.
/// element.map(move |message| Message::Counter(index, message)) /// element
/// .map(move |message| Message::Counter(index, message)),
/// ) /// )
/// } /// },
/// ) /// )
/// } /// }
/// } /// }

View file

@ -62,7 +62,7 @@ impl Status {
/// `Captured` takes precedence over `Ignored`: /// `Captured` takes precedence over `Ignored`:
/// ///
/// ``` /// ```
/// use iced_native::event::Status; /// use iced_core::event::Status;
/// ///
/// assert_eq!(Status::Ignored.merge(Status::Ignored), Status::Ignored); /// assert_eq!(Status::Ignored.merge(Status::Ignored), Status::Ignored);
/// assert_eq!(Status::Ignored.merge(Status::Captured), Status::Captured); /// assert_eq!(Status::Ignored.merge(Status::Captured), Status::Captured);

View file

@ -25,33 +25,57 @@
#![forbid(unsafe_code, rust_2018_idioms)] #![forbid(unsafe_code, rust_2018_idioms)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![allow(clippy::inherent_to_string, clippy::type_complexity)]
pub mod alignment; pub mod alignment;
pub mod clipboard;
pub mod event;
pub mod font; pub mod font;
pub mod gradient; pub mod gradient;
pub mod image;
pub mod keyboard; pub mod keyboard;
pub mod layout;
pub mod mouse; pub mod mouse;
pub mod overlay;
pub mod renderer;
pub mod svg;
pub mod text;
pub mod time; pub mod time;
pub mod touch;
pub mod widget;
pub mod window;
mod background; mod background;
mod color; mod color;
mod content_fit; mod content_fit;
mod element;
mod hasher;
mod length; mod length;
mod padding; mod padding;
mod pixels; mod pixels;
mod point; mod point;
mod rectangle; mod rectangle;
mod shell;
mod size; mod size;
mod vector; mod vector;
pub use alignment::Alignment; pub use alignment::Alignment;
pub use background::Background; pub use background::Background;
pub use clipboard::Clipboard;
pub use color::Color; pub use color::Color;
pub use content_fit::ContentFit; pub use content_fit::ContentFit;
pub use element::Element;
pub use event::Event;
pub use font::Font; pub use font::Font;
pub use gradient::Gradient; pub use gradient::Gradient;
pub use hasher::Hasher;
pub use layout::Layout;
pub use length::Length; pub use length::Length;
pub use overlay::Overlay;
pub use padding::Padding; pub use padding::Padding;
pub use pixels::Pixels; pub use pixels::Pixels;
pub use point::Point; pub use point::Point;
pub use rectangle::Rectangle; pub use rectangle::Rectangle;
pub use renderer::Renderer;
pub use shell::Shell;
pub use size::Size; pub use size::Size;
pub use text::Text;
pub use vector::Vector; pub use vector::Vector;
pub use widget::Widget;

View file

@ -1,8 +1,11 @@
//! Handle mouse events. //! Handle mouse events.
pub mod click;
mod button; mod button;
mod event; mod event;
mod interaction; mod interaction;
pub use button::Button; pub use button::Button;
pub use click::Click;
pub use event::{Event, ScrollDelta}; pub use event::{Event, ScrollDelta};
pub use interaction::Interaction; pub use interaction::Interaction;

View file

@ -2,11 +2,8 @@
mod element; mod element;
mod group; mod group;
pub mod menu;
pub use element::Element; pub use element::Element;
pub use group::Group; pub use group::Group;
pub use menu::Menu;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;

View file

@ -1,12 +1,10 @@
use iced_core::{Point, Rectangle, Size};
use crate::event; use crate::event;
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::widget; use crate::widget;
use crate::{Clipboard, Event, Layout, Overlay, Shell}; use crate::{Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size};
/// An [`Overlay`] container that displays multiple overlay [`overlay::Element`] /// An [`Overlay`] container that displays multiple overlay [`overlay::Element`]
/// children. /// children.

View file

@ -1,6 +1,7 @@
//! Write your own renderer. //! Write your own renderer.
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
mod null; mod null;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub use null::Null; pub use null::Null;

View file

@ -1,6 +1,6 @@
use crate::renderer::{self, Renderer}; use crate::renderer::{self, Renderer};
use crate::text::{self, Text}; use crate::text::{self, Text};
use crate::{Background, Font, Point, Rectangle, Size, Theme, Vector}; use crate::{Background, Font, Point, Rectangle, Size, Vector};
use std::borrow::Cow; use std::borrow::Cow;
@ -18,7 +18,7 @@ impl Null {
} }
impl Renderer for Null { impl Renderer for Null {
type Theme = Theme; type Theme = ();
fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {} fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {}

145
core/src/widget.rs Normal file
View file

@ -0,0 +1,145 @@
//! Create custom widgets and operate on them.
pub mod operation;
pub mod text;
pub mod tree;
mod id;
pub use id::Id;
pub use operation::Operation;
pub use text::Text;
pub use tree::Tree;
use crate::event::{self, Event};
use crate::layout::{self, Layout};
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::{Clipboard, Length, Point, Rectangle, Shell};
/// A component that displays information and allows interaction.
///
/// If you want to build your own widgets, you will need to implement this
/// trait.
///
/// # Examples
/// The repository has some [examples] showcasing how to implement a custom
/// widget:
///
/// - [`bezier_tool`], a Paint-like tool for drawing Bézier curves using
/// [`lyon`].
/// - [`custom_widget`], a demonstration of how to build a custom widget that
/// draws a circle.
/// - [`geometry`], a custom widget showcasing how to draw geometry with the
/// `Mesh2D` primitive in [`iced_wgpu`].
///
/// [examples]: https://github.com/iced-rs/iced/tree/0.8/examples
/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.8/examples/bezier_tool
/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.8/examples/custom_widget
/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.8/examples/geometry
/// [`lyon`]: https://github.com/nical/lyon
/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.8/wgpu
pub trait Widget<Message, Renderer>
where
Renderer: crate::Renderer,
{
/// Returns the width of the [`Widget`].
fn width(&self) -> Length;
/// Returns the height of the [`Widget`].
fn height(&self) -> Length;
/// Returns the [`layout::Node`] of the [`Widget`].
///
/// This [`layout::Node`] is used by the runtime to compute the [`Layout`] of the
/// user interface.
fn layout(
&self,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node;
/// Draws the [`Widget`] using the associated `Renderer`.
fn draw(
&self,
state: &Tree,
renderer: &mut Renderer,
theme: &Renderer::Theme,
style: &renderer::Style,
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
);
/// Returns the [`Tag`] of the [`Widget`].
///
/// [`Tag`]: tree::Tag
fn tag(&self) -> tree::Tag {
tree::Tag::stateless()
}
/// Returns the [`State`] of the [`Widget`].
///
/// [`State`]: tree::State
fn state(&self) -> tree::State {
tree::State::None
}
/// Returns the state [`Tree`] of the children of the [`Widget`].
fn children(&self) -> Vec<Tree> {
Vec::new()
}
/// Reconciliates the [`Widget`] with the provided [`Tree`].
fn diff(&self, _tree: &mut Tree) {}
/// Applies an [`Operation`] to the [`Widget`].
fn operate(
&self,
_state: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn Operation<Message>,
) {
}
/// Processes a runtime [`Event`].
///
/// By default, it does nothing.
fn on_event(
&mut self,
_state: &mut Tree,
_event: Event,
_layout: Layout<'_>,
_cursor_position: Point,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
) -> event::Status {
event::Status::Ignored
}
/// Returns the current [`mouse::Interaction`] of the [`Widget`].
///
/// By default, it returns [`mouse::Interaction::Idle`].
fn mouse_interaction(
&self,
_state: &Tree,
_layout: Layout<'_>,
_cursor_position: Point,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> mouse::Interaction {
mouse::Interaction::Idle
}
/// Returns the overlay of the [`Widget`], if there is any.
fn overlay<'a>(
&'a mut self,
_state: &'a mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
) -> Option<overlay::Element<'a, Message, Renderer>> {
None
}
}

View file

@ -24,7 +24,7 @@ impl Id {
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Internal { enum Internal {
Unique(usize), Unique(usize),
Custom(borrow::Cow<'static, str>), Custom(borrow::Cow<'static, str>),
} }

View file

@ -4,27 +4,13 @@ use crate::layout;
use crate::renderer; use crate::renderer;
use crate::text; use crate::text;
use crate::widget::Tree; use crate::widget::Tree;
use crate::{Element, Layout, Length, Pixels, Point, Rectangle, Size, Widget}; use crate::{
Color, Element, Layout, Length, Pixels, Point, Rectangle, Size, Widget,
};
use std::borrow::Cow; use std::borrow::Cow;
pub use iced_style::text::{Appearance, StyleSheet};
/// A paragraph of text. /// A paragraph of text.
///
/// # Example
///
/// ```
/// # use iced_native::Color;
/// #
/// # type Text<'a> = iced_native::widget::Text<'a, iced_native::renderer::Null>;
/// #
/// Text::new("I <3 iced!")
/// .size(40)
/// .style(Color::from([0.0, 0.0, 1.0]));
/// ```
///
/// ![Text drawn by `iced_wgpu`](https://github.com/iced-rs/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text.png?raw=true)
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Text<'a, Renderer> pub struct Text<'a, Renderer>
where where
@ -211,7 +197,7 @@ pub fn draw<Renderer>(
alignment::Vertical::Bottom => bounds.y + bounds.height, alignment::Vertical::Bottom => bounds.y + bounds.height,
}; };
renderer.fill_text(crate::text::Text { renderer.fill_text(crate::Text {
content, content,
size: size.unwrap_or_else(|| renderer.default_size()), size: size.unwrap_or_else(|| renderer.default_size()),
bounds: Rectangle { x, y, ..bounds }, bounds: Rectangle { x, y, ..bounds },
@ -252,12 +238,40 @@ where
} }
} }
impl<'a, Renderer> From<&'a str> for Text<'a, Renderer>
where
Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{
fn from(content: &'a str) -> Self {
Self::new(content)
}
}
impl<'a, Message, Renderer> From<&'a str> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<&'a str> for Element<'a, Message, Renderer>
where where
Renderer: text::Renderer + 'a, Renderer: text::Renderer + 'a,
Renderer::Theme: StyleSheet, Renderer::Theme: StyleSheet,
{ {
fn from(contents: &'a str) -> Self { fn from(content: &'a str) -> Self {
Text::new(contents).into() Text::from(content).into()
} }
} }
/// The style sheet of some text.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Copy;
/// Produces the [`Appearance`] of some text.
fn appearance(&self, style: Self::Style) -> Appearance;
}
/// The apperance of some text.
#[derive(Debug, Clone, Copy, Default)]
pub struct Appearance {
/// The [`Color`] of the text.
///
/// The default, `None`, means using the inherited color.
pub color: Option<Color>,
}

10
core/src/window.rs Normal file
View file

@ -0,0 +1,10 @@
//! Build window-based GUI applications.
mod event;
mod mode;
mod redraw_request;
mod user_attention;
pub use event::Event;
pub use mode::Mode;
pub use redraw_request::RedrawRequest;
pub use user_attention::UserAttention;

View file

@ -6,6 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = ["debug"] } iced = { path = "../..", features = ["debug", "lazy"] }
iced_native = { path = "../../native" }
iced_lazy = { path = "../../lazy" }

View file

@ -47,9 +47,8 @@ impl Sandbox for Component {
mod numeric_input { mod numeric_input {
use iced::alignment::{self, Alignment}; use iced::alignment::{self, Alignment};
use iced::widget::{self, button, row, text, text_input}; use iced::widget::{button, component, row, text, text_input, Component};
use iced::{Element, Length}; use iced::{Element, Length, Renderer};
use iced_lazy::{self, Component};
pub struct NumericInput<Message> { pub struct NumericInput<Message> {
value: Option<u32>, value: Option<u32>,
@ -82,13 +81,7 @@ mod numeric_input {
} }
} }
impl<Message, Renderer> Component<Message, Renderer> for NumericInput<Message> impl<Message> Component<Message, Renderer> for NumericInput<Message> {
where
Renderer: iced_native::text::Renderer + 'static,
Renderer::Theme: widget::button::StyleSheet
+ widget::text_input::StyleSheet
+ widget::text::StyleSheet,
{
type State = (); type State = ();
type Event = Event; type Event = Event;
@ -151,17 +144,12 @@ mod numeric_input {
} }
} }
impl<'a, Message, Renderer> From<NumericInput<Message>> impl<'a, Message> From<NumericInput<Message>> for Element<'a, Message, Renderer>
for Element<'a, Message, Renderer>
where where
Message: 'a, Message: 'a,
Renderer: 'static + iced_native::text::Renderer,
Renderer::Theme: widget::button::StyleSheet
+ widget::text_input::StyleSheet
+ widget::text::StyleSheet,
{ {
fn from(numeric_input: NumericInput<Message>) -> Self { fn from(numeric_input: NumericInput<Message>) -> Self {
iced_lazy::component(numeric_input) component(numeric_input)
} }
} }
} }

View file

@ -6,5 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../.." } iced = { path = "../..", features = ["advanced"] }
iced_native = { path = "../../native" }

View file

@ -1,9 +1,9 @@
//! This example showcases a drawing a quad. //! This example showcases a drawing a quad.
mod quad { mod quad {
use iced_native::layout::{self, Layout}; use iced::advanced::layout::{self, Layout};
use iced_native::renderer; use iced::advanced::renderer;
use iced_native::widget::{self, Widget}; use iced::advanced::widget::{self, Widget};
use iced_native::{Color, Element, Length, Point, Rectangle, Size}; use iced::{Color, Element, Length, Point, Rectangle, Size};
pub struct CustomQuad { pub struct CustomQuad {
size: f32, size: f32,

View file

@ -6,5 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../.." } iced = { path = "../..", features = ["advanced"] }
iced_native = { path = "../../native" }

View file

@ -9,10 +9,10 @@ mod circle {
// Of course, you can choose to make the implementation renderer-agnostic, // Of course, you can choose to make the implementation renderer-agnostic,
// if you wish to, by creating your own `Renderer` trait, which could be // if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers. // implemented by `iced_wgpu` and other renderers.
use iced_native::layout::{self, Layout}; use iced::advanced::layout::{self, Layout};
use iced_native::renderer; use iced::advanced::renderer;
use iced_native::widget::{self, Widget}; use iced::advanced::widget::{self, Widget};
use iced_native::{Color, Element, Length, Point, Rectangle, Size}; use iced::{Color, Element, Length, Point, Rectangle, Size};
pub struct Circle { pub struct Circle {
radius: f32, radius: f32,

View file

@ -7,4 +7,3 @@ publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = ["debug"] } iced = { path = "../..", features = ["debug"] }
iced_native = { path = "../../native" }

View file

@ -1,12 +1,13 @@
use iced::alignment; use iced::alignment;
use iced::executor; use iced::executor;
use iced::subscription;
use iced::widget::{button, checkbox, container, text, Column}; use iced::widget::{button, checkbox, container, text, Column};
use iced::window; use iced::window;
use iced::Event;
use iced::{ use iced::{
Alignment, Application, Command, Element, Length, Settings, Subscription, Alignment, Application, Command, Element, Length, Settings, Subscription,
Theme, Theme,
}; };
use iced_native::Event;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
Events::run(Settings { Events::run(Settings {
@ -17,13 +18,13 @@ pub fn main() -> iced::Result {
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct Events { struct Events {
last: Vec<iced_native::Event>, last: Vec<Event>,
enabled: bool, enabled: bool,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Message { enum Message {
EventOccurred(iced_native::Event), EventOccurred(Event),
Toggled(bool), Toggled(bool),
Exit, Exit,
} }
@ -70,7 +71,7 @@ impl Application for Events {
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {
iced_native::subscription::events().map(Message::EventOccurred) subscription::events().map(Message::EventOccurred)
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {

View file

@ -6,6 +6,5 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../.." } iced = { path = "../..", features = ["advanced"] }
iced_native = { path = "../../native" }
iced_graphics = { path = "../../graphics" } iced_graphics = { path = "../../graphics" }

View file

@ -1,23 +1,13 @@
//! This example showcases a simple native custom widget that renders using //! This example showcases a simple native custom widget that renders using
//! arbitrary low-level geometry. //! arbitrary low-level geometry.
mod rainbow { mod rainbow {
// For now, to implement a custom native widget you will need to add
// `iced_native` and `iced_wgpu` to your dependencies.
//
// Then, you simply need to define your widget type and implement the
// `iced_native::Widget` trait with the `iced_wgpu::Renderer`.
//
// Of course, you can choose to make the implementation renderer-agnostic,
// if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers.
use iced_graphics::primitive::{ColoredVertex2D, Primitive}; use iced_graphics::primitive::{ColoredVertex2D, Primitive};
use iced_graphics::renderer::{self, Renderer};
use iced_graphics::Backend;
use iced_native::layout; use iced::advanced::layout::{self, Layout};
use iced_native::widget::{self, Widget}; use iced::advanced::renderer;
use iced_native::{ use iced::advanced::widget::{self, Widget};
Element, Layout, Length, Point, Rectangle, Size, Vector, use iced::{
Element, Length, Point, Rectangle, Renderer, Size, Theme, Vector,
}; };
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
@ -27,10 +17,7 @@ mod rainbow {
Rainbow Rainbow
} }
impl<Message, B, T> Widget<Message, Renderer<B, T>> for Rainbow impl<Message> Widget<Message, Renderer> for Rainbow {
where
B: Backend,
{
fn width(&self) -> Length { fn width(&self) -> Length {
Length::Fill Length::Fill
} }
@ -41,7 +28,7 @@ mod rainbow {
fn layout( fn layout(
&self, &self,
_renderer: &Renderer<B, T>, _renderer: &Renderer,
limits: &layout::Limits, limits: &layout::Limits,
) -> layout::Node { ) -> layout::Node {
let size = limits.width(Length::Fill).resolve(Size::ZERO); let size = limits.width(Length::Fill).resolve(Size::ZERO);
@ -52,15 +39,15 @@ mod rainbow {
fn draw( fn draw(
&self, &self,
_tree: &widget::Tree, _tree: &widget::Tree,
renderer: &mut Renderer<B, T>, renderer: &mut Renderer,
_theme: &T, _theme: &Theme,
_style: &renderer::Style, _style: &renderer::Style,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_viewport: &Rectangle, _viewport: &Rectangle,
) { ) {
use iced::advanced::Renderer as _;
use iced_graphics::primitive::Mesh2D; use iced_graphics::primitive::Mesh2D;
use iced_native::Renderer as _;
let b = layout.bounds(); let b = layout.bounds();
@ -151,10 +138,7 @@ mod rainbow {
} }
} }
impl<'a, Message, B, T> From<Rainbow> for Element<'a, Message, Renderer<B, T>> impl<'a, Message> From<Rainbow> for Element<'a, Message, Renderer> {
where
B: Backend,
{
fn from(rainbow: Rainbow) -> Self { fn from(rainbow: Rainbow) -> Self {
Self::new(rainbow) Self::new(rainbow)
} }

View file

@ -8,6 +8,7 @@ publish = false
[dependencies] [dependencies]
iced_winit = { path = "../../winit" } iced_winit = { path = "../../winit" }
iced_wgpu = { path = "../../wgpu", features = ["webgl"] } iced_wgpu = { path = "../../wgpu", features = ["webgl"] }
iced_widget = { path = "../../widget" }
env_logger = "0.8" env_logger = "0.8"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]

View file

@ -1,6 +1,8 @@
use iced_wgpu::Renderer; use iced_wgpu::Renderer;
use iced_winit::widget::{slider, text_input, Column, Row, Text}; use iced_widget::{slider, text_input, Column, Row, Text};
use iced_winit::{Alignment, Color, Command, Element, Length, Program}; use iced_winit::core::{Alignment, Color, Element, Length};
use iced_winit::native::{Command, Program};
use iced_winit::style::Theme;
pub struct Controls { pub struct Controls {
background_color: Color, background_color: Color,
@ -27,7 +29,7 @@ impl Controls {
} }
impl Program for Controls { impl Program for Controls {
type Renderer = Renderer; type Renderer = Renderer<Theme>;
type Message = Message; type Message = Message;
fn update(&mut self, message: Message) -> Command<Message> { fn update(&mut self, message: Message) -> Command<Message> {
@ -43,7 +45,7 @@ impl Program for Controls {
Command::none() Command::none()
} }
fn view(&self) -> Element<Message, Renderer> { fn view(&self) -> Element<Message, Renderer<Theme>> {
let background_color = self.background_color; let background_color = self.background_color;
let text = &self.text; let text = &self.text;

View file

@ -4,11 +4,14 @@ mod scene;
use controls::Controls; use controls::Controls;
use scene::Scene; use scene::Scene;
use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport}; use iced_wgpu::graphics::Viewport;
use iced_winit::{ use iced_wgpu::{wgpu, Backend, Renderer, Settings};
conversion, futures, program, renderer, winit, Clipboard, Color, Debug, use iced_winit::core::renderer;
Size, use iced_winit::core::{Color, Size};
}; use iced_winit::native::program;
use iced_winit::native::Debug;
use iced_winit::style::Theme;
use iced_winit::{conversion, futures, winit, Clipboard};
use winit::{ use winit::{
dpi::PhysicalPosition, dpi::PhysicalPosition,
@ -73,43 +76,45 @@ pub fn main() {
let instance = wgpu::Instance::new(backend); let instance = wgpu::Instance::new(backend);
let surface = unsafe { instance.create_surface(&window) }; let surface = unsafe { instance.create_surface(&window) };
let (format, (device, queue)) = futures::executor::block_on(async { let (format, (device, queue)) =
let adapter = wgpu::util::initialize_adapter_from_env_or_default( futures::futures::executor::block_on(async {
&instance, let adapter = wgpu::util::initialize_adapter_from_env_or_default(
backend, &instance,
Some(&surface), backend,
) Some(&surface),
.await )
.expect("No suitable GPU adapters found on the system!"); .await
.expect("No suitable GPU adapters found on the system!");
let adapter_features = adapter.features(); let adapter_features = adapter.features();
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
let needed_limits = wgpu::Limits::downlevel_webgl2_defaults() let needed_limits = wgpu::Limits::downlevel_webgl2_defaults()
.using_resolution(adapter.limits()); .using_resolution(adapter.limits());
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
let needed_limits = wgpu::Limits::default(); let needed_limits = wgpu::Limits::default();
( (
surface surface
.get_supported_formats(&adapter) .get_supported_formats(&adapter)
.first() .first()
.copied() .copied()
.expect("Get preferred format"), .expect("Get preferred format"),
adapter adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: None, label: None,
features: adapter_features & wgpu::Features::default(), features: adapter_features
limits: needed_limits, & wgpu::Features::default(),
}, limits: needed_limits,
None, },
) None,
.await )
.expect("Request device"), .await
) .expect("Request device"),
}); )
});
surface.configure( surface.configure(
&device, &device,
@ -188,7 +193,7 @@ pub fn main() {
viewport.scale_factor(), viewport.scale_factor(),
), ),
&mut renderer, &mut renderer,
&iced_wgpu::Theme::Dark, &Theme::Dark,
&renderer::Style { text_color: Color::WHITE }, &renderer::Style { text_color: Color::WHITE },
&mut clipboard, &mut clipboard,
&mut debug, &mut debug,

View file

@ -1,5 +1,5 @@
use iced_wgpu::wgpu; use iced_wgpu::wgpu;
use iced_winit::Color; use iced_winit::core::Color;
pub struct Scene { pub struct Scene {
pipeline: wgpu::RenderPipeline, pipeline: wgpu::RenderPipeline,

View file

@ -6,5 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = ["debug"] } iced = { path = "../..", features = ["debug", "lazy"] }
iced_lazy = { path = "../../lazy" }

View file

@ -1,10 +1,9 @@
use iced::theme; use iced::theme;
use iced::widget::{ use iced::widget::{
button, column, horizontal_space, pick_list, row, scrollable, text, button, column, horizontal_space, lazy, pick_list, row, scrollable, text,
text_input, text_input,
}; };
use iced::{Element, Length, Sandbox, Settings}; use iced::{Element, Length, Sandbox, Settings};
use iced_lazy::lazy;
use std::collections::HashSet; use std::collections::HashSet;
use std::hash::Hash; use std::hash::Hash;

View file

@ -6,5 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = [] } iced = { path = "../..", features = ["advanced"] }
iced_native = { path = "../../native" }

View file

@ -178,12 +178,15 @@ impl App {
} }
mod modal { mod modal {
use iced_native::alignment::Alignment; use iced::advanced::layout::{self, Layout};
use iced_native::widget::{self, Tree}; use iced::advanced::overlay;
use iced_native::{ use iced::advanced::renderer;
event, layout, mouse, overlay, renderer, Clipboard, Color, Element, use iced::advanced::widget::{self, Widget};
Event, Layout, Length, Point, Rectangle, Shell, Size, Widget, use iced::advanced::{self, Clipboard, Shell};
}; use iced::alignment::Alignment;
use iced::event;
use iced::mouse;
use iced::{Color, Element, Event, Length, Point, Rectangle, Size};
/// A widget that centers a modal element over some base element /// A widget that centers a modal element over some base element
pub struct Modal<'a, Message, Renderer> { pub struct Modal<'a, Message, Renderer> {
@ -218,14 +221,17 @@ mod modal {
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Modal<'a, Message, Renderer> for Modal<'a, Message, Renderer>
where where
Renderer: iced_native::Renderer, Renderer: advanced::Renderer,
Message: Clone, Message: Clone,
{ {
fn children(&self) -> Vec<Tree> { fn children(&self) -> Vec<widget::Tree> {
vec![Tree::new(&self.base), Tree::new(&self.modal)] vec![
widget::Tree::new(&self.base),
widget::Tree::new(&self.modal),
]
} }
fn diff(&self, tree: &mut Tree) { fn diff(&self, tree: &mut widget::Tree) {
tree.diff_children(&[&self.base, &self.modal]); tree.diff_children(&[&self.base, &self.modal]);
} }
@ -247,7 +253,7 @@ mod modal {
fn on_event( fn on_event(
&mut self, &mut self,
state: &mut Tree, state: &mut widget::Tree,
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
@ -268,9 +274,9 @@ mod modal {
fn draw( fn draw(
&self, &self,
state: &Tree, state: &widget::Tree,
renderer: &mut Renderer, renderer: &mut Renderer,
theme: &<Renderer as iced_native::Renderer>::Theme, theme: &<Renderer as advanced::Renderer>::Theme,
style: &renderer::Style, style: &renderer::Style,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
@ -289,7 +295,7 @@ mod modal {
fn overlay<'b>( fn overlay<'b>(
&'b mut self, &'b mut self,
state: &'b mut Tree, state: &'b mut widget::Tree,
layout: Layout<'_>, layout: Layout<'_>,
_renderer: &Renderer, _renderer: &Renderer,
) -> Option<overlay::Element<'b, Message, Renderer>> { ) -> Option<overlay::Element<'b, Message, Renderer>> {
@ -306,7 +312,7 @@ mod modal {
fn mouse_interaction( fn mouse_interaction(
&self, &self,
state: &Tree, state: &widget::Tree,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
viewport: &Rectangle, viewport: &Rectangle,
@ -323,7 +329,7 @@ mod modal {
fn operate( fn operate(
&self, &self,
state: &mut Tree, state: &mut widget::Tree,
layout: Layout<'_>, layout: Layout<'_>,
renderer: &Renderer, renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>, operation: &mut dyn widget::Operation<Message>,
@ -339,7 +345,7 @@ mod modal {
struct Overlay<'a, 'b, Message, Renderer> { struct Overlay<'a, 'b, Message, Renderer> {
content: &'b mut Element<'a, Message, Renderer>, content: &'b mut Element<'a, Message, Renderer>,
tree: &'b mut Tree, tree: &'b mut widget::Tree,
size: Size, size: Size,
on_blur: Option<Message>, on_blur: Option<Message>,
} }
@ -347,7 +353,7 @@ mod modal {
impl<'a, 'b, Message, Renderer> overlay::Overlay<Message, Renderer> impl<'a, 'b, Message, Renderer> overlay::Overlay<Message, Renderer>
for Overlay<'a, 'b, Message, Renderer> for Overlay<'a, 'b, Message, Renderer>
where where
Renderer: iced_native::Renderer, Renderer: advanced::Renderer,
Message: Clone, Message: Clone,
{ {
fn layout( fn layout(
@ -469,7 +475,7 @@ mod modal {
impl<'a, Message, Renderer> From<Modal<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Modal<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'a + iced_native::Renderer, Renderer: 'a + advanced::Renderer,
Message: 'a + Clone, Message: 'a + Clone,
{ {
fn from(modal: Modal<'a, Message, Renderer>) -> Self { fn from(modal: Modal<'a, Message, Renderer>) -> Self {

View file

@ -6,6 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = ["debug"] } iced = { path = "../..", features = ["debug", "lazy"] }
iced_native = { path = "../../native" }
iced_lazy = { path = "../../lazy" }

View file

@ -1,14 +1,16 @@
use iced::alignment::{self, Alignment}; use iced::alignment::{self, Alignment};
use iced::event::{self, Event};
use iced::executor; use iced::executor;
use iced::keyboard; use iced::keyboard;
use iced::subscription;
use iced::theme::{self, Theme}; use iced::theme::{self, Theme};
use iced::widget::pane_grid::{self, PaneGrid}; use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::{button, column, container, row, scrollable, text}; use iced::widget::{
button, column, container, responsive, row, scrollable, text,
};
use iced::{ use iced::{
Application, Color, Command, Element, Length, Settings, Size, Subscription, Application, Color, Command, Element, Length, Settings, Size, Subscription,
}; };
use iced_lazy::responsive;
use iced_native::{event, subscription, Event};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
Example::run(Settings::default()) Example::run(Settings::default())

View file

@ -6,5 +6,4 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = [] } iced = { path = "../..", features = ["advanced"] }
iced_native = { path = "../../native" }

View file

@ -176,17 +176,23 @@ mod toast {
use std::fmt; use std::fmt;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use iced::advanced;
use iced::advanced::layout::{self, Layout};
use iced::advanced::overlay;
use iced::advanced::renderer;
use iced::advanced::widget::{self, Operation, Tree};
use iced::advanced::{Clipboard, Shell, Widget};
use iced::event::{self, Event};
use iced::mouse;
use iced::theme; use iced::theme;
use iced::widget::{ use iced::widget::{
button, column, container, horizontal_rule, horizontal_space, row, text, button, column, container, horizontal_rule, horizontal_space, row, text,
}; };
use iced::window;
use iced::{ use iced::{
Alignment, Element, Length, Point, Rectangle, Renderer, Size, Theme, Alignment, Element, Length, Point, Rectangle, Renderer, Size, Theme,
Vector, Vector,
}; };
use iced_native::widget::{tree, Operation, Tree};
use iced_native::{event, layout, mouse, overlay, renderer, window};
use iced_native::{Clipboard, Event, Layout, Shell, Widget};
pub const DEFAULT_TIMEOUT: u64 = 5; pub const DEFAULT_TIMEOUT: u64 = 5;
@ -324,13 +330,13 @@ mod toast {
self.content.as_widget().layout(renderer, limits) self.content.as_widget().layout(renderer, limits)
} }
fn tag(&self) -> tree::Tag { fn tag(&self) -> widget::tree::Tag {
struct Marker(Vec<Instant>); struct Marker(Vec<Instant>);
iced_native::widget::tree::Tag::of::<Marker>() widget::tree::Tag::of::<Marker>()
} }
fn state(&self) -> tree::State { fn state(&self) -> widget::tree::State {
iced_native::widget::tree::State::new(Vec::<Option<Instant>>::new()) widget::tree::State::new(Vec::<Option<Instant>>::new())
} }
fn children(&self) -> Vec<Tree> { fn children(&self) -> Vec<Tree> {
@ -584,7 +590,7 @@ mod toast {
fn draw( fn draw(
&self, &self,
renderer: &mut Renderer, renderer: &mut Renderer,
theme: &<Renderer as iced_native::Renderer>::Theme, theme: &<Renderer as advanced::Renderer>::Theme,
style: &renderer::Style, style: &renderer::Style,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
@ -613,7 +619,7 @@ mod toast {
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,
renderer: &Renderer, renderer: &Renderer,
operation: &mut dyn iced_native::widget::Operation<Message>, operation: &mut dyn widget::Operation<Message>,
) { ) {
operation.container(None, &mut |operation| { operation.container(None, &mut |operation| {
self.toasts self.toasts

View file

@ -7,4 +7,3 @@ publish = false
[dependencies] [dependencies]
iced = { path = "../.." } iced = { path = "../.." }
iced_native = { path = "../../native" }

View file

@ -1,12 +1,10 @@
use iced::event::{Event, MacOS, PlatformSpecific};
use iced::executor; use iced::executor;
use iced::subscription;
use iced::widget::{container, text}; use iced::widget::{container, text};
use iced::{ use iced::{
Application, Command, Element, Length, Settings, Subscription, Theme, Application, Command, Element, Length, Settings, Subscription, Theme,
}; };
use iced_native::{
event::{MacOS, PlatformSpecific},
Event,
};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
App::run(Settings::default()) App::run(Settings::default())
@ -19,7 +17,7 @@ struct App {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Message { enum Message {
EventOccurred(iced_native::Event), EventOccurred(Event),
} }
impl Application for App { impl Application for App {
@ -52,7 +50,7 @@ impl Application for App {
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {
iced_native::subscription::events().map(Message::EventOccurred) subscription::events().map(Message::EventOccurred)
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@ pub use builder::Builder;
pub use lyon_path; 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. /// An immutable set of points that may or may not be connected.
/// ///

View file

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

View file

@ -1,5 +1,6 @@
use crate::geometry::path::{arc, Arc, Path}; 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::builder::{self, SvgPathBuilder};
use lyon_path::geom; use lyon_path::geom;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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_core::alignment;
use iced_core::image;
use iced_native::image; use iced_core::svg;
use iced_native::svg; use iced_core::{Background, Color, Font, Gradient, Rectangle, Size, Vector};
use iced_native::{Background, Color, Font, Gradient, Rectangle, Size, Vector};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::sync::Arc; use std::sync::Arc;

View file

@ -1,15 +1,15 @@
//! Create a renderer from a [`Backend`]. //! Create a renderer from a [`Backend`].
use crate::backend::{self, Backend}; use crate::backend::{self, Backend};
use crate::{Primitive, Vector}; use crate::Primitive;
use iced_native::image; use iced_core::image;
use iced_native::layout; use iced_core::layout;
use iced_native::renderer; use iced_core::renderer;
use iced_native::svg; use iced_core::svg;
use iced_native::text::{self, Text}; use iced_core::text::{self, Text};
use iced_native::{Background, Color, Element, Font, Point, Rectangle, Size}; use iced_core::{
Background, Color, Element, Font, Point, Rectangle, Size, Vector,
pub use iced_native::renderer::Style; };
use std::borrow::Cow; use std::borrow::Cow;
use std::marker::PhantomData; 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 where
B: Backend, 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. /// A viewing region for displaying computer graphics.
#[derive(Debug, Clone)] #[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],
);
}

View file

@ -1,18 +0,0 @@
[package]
name = "iced_lazy"
version = "0.5.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
description = "Lazy widgets for Iced"
license = "MIT"
repository = "https://github.com/iced-rs/iced"
documentation = "https://docs.rs/iced_lazy"
keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]
[dependencies]
ouroboros = "0.13"
[dependencies.iced_native]
version = "0.9"
path = "../native"

View file

@ -11,9 +11,6 @@ repository = "https://github.com/iced-rs/iced"
debug = [] debug = []
[dependencies] [dependencies]
twox-hash = { version = "1.5", default-features = false }
unicode-segmentation = "1.6"
num-traits = "0.2"
thiserror = "1" thiserror = "1"
[dependencies.iced_core] [dependencies.iced_core]
@ -24,7 +21,3 @@ path = "../core"
version = "0.6" version = "0.6"
path = "../futures" path = "../futures"
features = ["thread-pool"] features = ["thread-pool"]
[dependencies.iced_style]
version = "0.7"
path = "../style"

View file

@ -3,28 +3,6 @@ use iced_futures::MaybeSend;
use std::fmt; use std::fmt;
/// A buffer for short-term storage and transfer within and between
/// applications.
pub trait Clipboard {
/// Reads the current content of the [`Clipboard`] as text.
fn read(&self) -> Option<String>;
/// Writes the given text contents to the [`Clipboard`].
fn write(&mut self, contents: String);
}
/// A null implementation of the [`Clipboard`] trait.
#[derive(Debug, Clone, Copy)]
pub struct Null;
impl Clipboard for Null {
fn read(&self) -> Option<String> {
None
}
fn write(&mut self, _contents: String) {}
}
/// A clipboard action to be performed by some [`Command`]. /// A clipboard action to be performed by some [`Command`].
/// ///
/// [`Command`]: crate::Command /// [`Command`]: crate::Command

View file

@ -28,7 +28,9 @@ impl<T> Command<T> {
} }
/// Creates a [`Command`] that performs a [`widget::Operation`]. /// Creates a [`Command`] that performs a [`widget::Operation`].
pub fn widget(operation: impl widget::Operation<T> + 'static) -> Self { pub fn widget(
operation: impl iced_core::widget::Operation<T> + 'static,
) -> Self {
Self(iced_futures::Command::single(Action::Widget( Self(iced_futures::Command::single(Action::Widget(
widget::Action::new(operation), widget::Action::new(operation),
))) )))

View file

@ -1,5 +1,5 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use crate::time; use crate::core::time;
use std::collections::VecDeque; use std::collections::VecDeque;

View file

@ -42,32 +42,19 @@
clippy::useless_conversion clippy::useless_conversion
)] )]
#![forbid(unsafe_code, rust_2018_idioms)] #![forbid(unsafe_code, rust_2018_idioms)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
pub mod clipboard; pub mod clipboard;
pub mod command; pub mod command;
pub mod event;
pub mod font; pub mod font;
pub mod image;
pub mod keyboard; pub mod keyboard;
pub mod layout;
pub mod mouse;
pub mod overlay;
pub mod program; pub mod program;
pub mod renderer;
pub mod subscription; pub mod subscription;
pub mod svg;
pub mod system; pub mod system;
pub mod text;
pub mod touch;
pub mod user_interface; pub mod user_interface;
pub mod widget; pub mod widget;
pub mod window; pub mod window;
mod element;
mod hasher;
mod runtime; mod runtime;
mod shell;
// We disable debug capabilities on release builds unless the `debug` feature // We disable debug capabilities on release builds unless the `debug` feature
// is explicitly enabled. // is explicitly enabled.
@ -78,35 +65,13 @@ mod debug;
#[path = "debug/null.rs"] #[path = "debug/null.rs"]
mod debug; mod debug;
pub use iced_core::alignment; pub use iced_core as core;
pub use iced_core::gradient; pub use iced_futures as futures;
pub use iced_core::time;
pub use iced_core::{
color, Alignment, Background, Color, ContentFit, Length, Padding, Pixels,
Point, Rectangle, Size, Vector,
};
pub use iced_futures::{executor, futures};
pub use iced_style::application;
pub use iced_style::theme;
#[doc(no_inline)]
pub use executor::Executor;
pub use clipboard::Clipboard;
pub use command::Command; pub use command::Command;
pub use debug::Debug; pub use debug::Debug;
pub use element::Element;
pub use event::Event;
pub use font::Font; pub use font::Font;
pub use gradient::Gradient;
pub use hasher::Hasher;
pub use layout::Layout;
pub use overlay::Overlay;
pub use program::Program; pub use program::Program;
pub use renderer::Renderer;
pub use runtime::Runtime; pub use runtime::Runtime;
pub use shell::Shell;
pub use subscription::Subscription; pub use subscription::Subscription;
pub use theme::Theme;
pub use user_interface::UserInterface; pub use user_interface::UserInterface;
pub use widget::Widget;

View file

@ -1,6 +0,0 @@
//! Track mouse events.
pub mod click;
pub use click::Click;
pub use iced_core::mouse::*;

View file

@ -1,6 +1,8 @@
//! Build interactive programs using The Elm Architecture. //! Build interactive programs using The Elm Architecture.
use crate::text; use crate::Command;
use crate::{Command, Element, Renderer};
use iced_core::text;
use iced_core::{Element, Renderer};
mod state; mod state;

View file

@ -1,9 +1,9 @@
use crate::application; use crate::core::event::{self, Event};
use crate::event::{self, Event}; use crate::core::mouse;
use crate::mouse; use crate::core::renderer;
use crate::renderer; use crate::core::{Clipboard, Point, Size};
use crate::user_interface::{self, UserInterface}; use crate::user_interface::{self, UserInterface};
use crate::{Clipboard, Command, Debug, Point, Program, Size}; use crate::{Command, Debug, Program};
/// The execution state of a [`Program`]. It leverages caching, event /// The execution state of a [`Program`]. It leverages caching, event
/// processing, and rendering primitive storage. /// processing, and rendering primitive storage.
@ -22,7 +22,6 @@ where
impl<P> State<P> impl<P> State<P>
where where
P: Program + 'static, P: Program + 'static,
<P::Renderer as crate::Renderer>::Theme: application::StyleSheet,
{ {
/// Creates a new [`State`] with the provided [`Program`], initializing its /// Creates a new [`State`] with the provided [`Program`], initializing its
/// primitive with the given logical bounds and renderer. /// primitive with the given logical bounds and renderer.
@ -91,7 +90,7 @@ where
bounds: Size, bounds: Size,
cursor_position: Point, cursor_position: Point,
renderer: &mut P::Renderer, renderer: &mut P::Renderer,
theme: &<P::Renderer as crate::Renderer>::Theme, theme: &<P::Renderer as iced_core::Renderer>::Theme,
style: &renderer::Style, style: &renderer::Style,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
debug: &mut Debug, debug: &mut Debug,
@ -182,10 +181,7 @@ fn build_user_interface<'a, P: Program>(
renderer: &mut P::Renderer, renderer: &mut P::Renderer,
size: Size, size: Size,
debug: &mut Debug, debug: &mut Debug,
) -> UserInterface<'a, P::Message, P::Renderer> ) -> UserInterface<'a, P::Message, P::Renderer> {
where
<P::Renderer as crate::Renderer>::Theme: application::StyleSheet,
{
debug.view_started(); debug.view_started();
let view = program.view(); let view = program.view();
debug.view_finished(); debug.view_finished();

View file

@ -1,6 +1,6 @@
//! Run commands and subscriptions. //! Run commands and subscriptions.
use crate::event::{self, Event}; use iced_core::event::{self, Event};
use crate::Hasher; use iced_core::Hasher;
/// A native runtime with a generic executor and receiver of results. /// A native runtime with a generic executor and receiver of results.
/// ///

View file

@ -1,10 +1,9 @@
//! Listen to external events in your application. //! Listen to external events in your application.
use crate::event::{self, Event}; use crate::core::event::{self, Event};
use crate::window; use crate::core::window;
use crate::Hasher; use crate::core::Hasher;
use crate::futures::futures::{self, Future, Stream};
use iced_futures::futures::{self, Future, Stream}; use crate::futures::{BoxStream, MaybeSend};
use iced_futures::{BoxStream, MaybeSend};
use std::hash::Hash; use std::hash::Hash;
@ -144,7 +143,9 @@ where
/// ///
/// ``` /// ```
/// use iced_native::subscription::{self, Subscription}; /// use iced_native::subscription::{self, Subscription};
/// use iced_native::futures::channel::mpsc; /// use iced_native::futures::futures;
///
/// use futures::channel::mpsc;
/// ///
/// pub enum Event { /// pub enum Event {
/// Ready(mpsc::Sender<Input>), /// Ready(mpsc::Sender<Input>),
@ -174,7 +175,7 @@ where
/// (Some(Event::Ready(sender)), State::Ready(receiver)) /// (Some(Event::Ready(sender)), State::Ready(receiver))
/// } /// }
/// State::Ready(mut receiver) => { /// State::Ready(mut receiver) => {
/// use iced_native::futures::StreamExt; /// use futures::StreamExt;
/// ///
/// // Read next input sent from `Application` /// // Read next input sent from `Application`
/// let input = receiver.select_next_some().await; /// let input = receiver.select_next_some().await;

View file

@ -1,14 +1,12 @@
//! Implement your own event loop to drive a user interface. //! Implement your own event loop to drive a user interface.
use crate::application; use crate::core::event::{self, Event};
use crate::event::{self, Event}; use crate::core::layout;
use crate::layout; use crate::core::mouse;
use crate::mouse; use crate::core::renderer;
use crate::renderer; use crate::core::widget;
use crate::widget; use crate::core::window;
use crate::window; use crate::core::{Clipboard, Point, Rectangle, Size, Vector};
use crate::{ use crate::core::{Element, Layout, Shell};
Clipboard, Element, Layout, Point, Rectangle, Shell, Size, Vector,
};
/// A set of interactive graphical elements with a specific [`Layout`]. /// A set of interactive graphical elements with a specific [`Layout`].
/// ///
@ -34,8 +32,7 @@ pub struct UserInterface<'a, Message, Renderer> {
impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer> impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer>
where where
Renderer: crate::Renderer, Renderer: iced_core::Renderer,
Renderer::Theme: application::StyleSheet,
{ {
/// Builds a user interface for an [`Element`]. /// Builds a user interface for an [`Element`].
/// ///
@ -48,24 +45,21 @@ where
/// is naive way to set up our application loop: /// is naive way to set up our application loop:
/// ///
/// ```no_run /// ```no_run
/// use iced_native::Size;
/// use iced_native::user_interface::{self, UserInterface};
/// use iced_wgpu::Renderer;
///
/// # mod iced_wgpu { /// # mod iced_wgpu {
/// # pub use iced_native::renderer::Null as Renderer; /// # pub use iced_native::core::renderer::Null as Renderer;
/// # } /// # }
/// # /// #
/// # use iced_native::widget::Column;
/// #
/// # pub struct Counter; /// # pub struct Counter;
/// # /// #
/// # impl Counter { /// # impl Counter {
/// # pub fn new() -> Self { Counter } /// # pub fn new() -> Self { Counter }
/// # pub fn view(&self) -> Column<(), Renderer> { /// # pub fn view(&self) -> iced_core::Element<(), Renderer> { unimplemented!() }
/// # Column::new() /// # pub fn update(&mut self, _: ()) {}
/// # }
/// # } /// # }
/// use iced_native::core::Size;
/// use iced_native::user_interface::{self, UserInterface};
/// use iced_wgpu::Renderer;
///
/// // Initialization /// // Initialization
/// let mut counter = Counter::new(); /// let mut counter = Counter::new();
/// let mut cache = user_interface::Cache::new(); /// let mut cache = user_interface::Cache::new();
@ -124,25 +118,21 @@ where
/// completing [the previous example](#example): /// completing [the previous example](#example):
/// ///
/// ```no_run /// ```no_run
/// use iced_native::{clipboard, Size, Point};
/// use iced_native::user_interface::{self, UserInterface};
/// use iced_wgpu::Renderer;
///
/// # mod iced_wgpu { /// # mod iced_wgpu {
/// # pub use iced_native::renderer::Null as Renderer; /// # pub use iced_native::core::renderer::Null as Renderer;
/// # } /// # }
/// # /// #
/// # use iced_native::widget::Column;
/// #
/// # pub struct Counter; /// # pub struct Counter;
/// # /// #
/// # impl Counter { /// # impl Counter {
/// # pub fn new() -> Self { Counter } /// # pub fn new() -> Self { Counter }
/// # pub fn view(&self) -> Column<(), Renderer> { /// # pub fn view(&self) -> iced_core::Element<(), Renderer> { unimplemented!() }
/// # Column::new() /// # pub fn update(&mut self, _: ()) {}
/// # }
/// # pub fn update(&mut self, message: ()) {}
/// # } /// # }
/// use iced_native::core::{clipboard, Size, Point};
/// use iced_native::user_interface::{self, UserInterface};
/// use iced_wgpu::Renderer;
///
/// let mut counter = Counter::new(); /// let mut counter = Counter::new();
/// let mut cache = user_interface::Cache::new(); /// let mut cache = user_interface::Cache::new();
/// let mut renderer = Renderer::new(); /// let mut renderer = Renderer::new();
@ -357,27 +347,24 @@ where
/// [completing the last example](#example-1): /// [completing the last example](#example-1):
/// ///
/// ```no_run /// ```no_run
/// use iced_native::clipboard;
/// use iced_native::renderer;
/// use iced_native::user_interface::{self, UserInterface};
/// use iced_native::{Size, Point, Theme};
/// use iced_wgpu::Renderer;
///
/// # mod iced_wgpu { /// # mod iced_wgpu {
/// # pub use iced_native::renderer::Null as Renderer; /// # pub use iced_native::core::renderer::Null as Renderer;
/// # pub type Theme = ();
/// # } /// # }
/// # /// #
/// # use iced_native::widget::Column;
/// #
/// # pub struct Counter; /// # pub struct Counter;
/// # /// #
/// # impl Counter { /// # impl Counter {
/// # pub fn new() -> Self { Counter } /// # pub fn new() -> Self { Counter }
/// # pub fn view(&self) -> Column<(), Renderer> { /// # pub fn view(&self) -> Element<(), Renderer> { unimplemented!() }
/// # Column::new() /// # pub fn update(&mut self, _: ()) {}
/// # }
/// # pub fn update(&mut self, message: ()) {}
/// # } /// # }
/// use iced_native::core::clipboard;
/// use iced_native::core::renderer;
/// use iced_native::core::{Element, Size, Point};
/// use iced_native::user_interface::{self, UserInterface};
/// use iced_wgpu::{Renderer, Theme};
///
/// let mut counter = Counter::new(); /// let mut counter = Counter::new();
/// let mut cache = user_interface::Cache::new(); /// let mut cache = user_interface::Cache::new();
/// let mut renderer = Renderer::new(); /// let mut renderer = Renderer::new();
@ -386,6 +373,7 @@ where
/// let mut clipboard = clipboard::Null; /// let mut clipboard = clipboard::Null;
/// let mut events = Vec::new(); /// let mut events = Vec::new();
/// let mut messages = Vec::new(); /// let mut messages = Vec::new();
/// let mut theme = Theme::default();
/// ///
/// loop { /// loop {
/// // Obtain system events... /// // Obtain system events...
@ -407,7 +395,7 @@ where
/// ); /// );
/// ///
/// // Draw the user interface /// // Draw the user interface
/// let mouse_cursor = user_interface.draw(&mut renderer, &Theme::default(), &renderer::Style::default(), cursor_position); /// let mouse_cursor = user_interface.draw(&mut renderer, &theme, &renderer::Style::default(), cursor_position);
/// ///
/// cache = user_interface.into_cache(); /// cache = user_interface.into_cache();
/// ///

View file

@ -11,212 +11,6 @@
//! source of inspiration. //! source of inspiration.
//! //!
//! [renderer]: crate::renderer //! [renderer]: crate::renderer
pub mod button;
pub mod checkbox;
pub mod column;
pub mod container;
pub mod helpers;
pub mod image;
pub mod operation;
pub mod pane_grid;
pub mod pick_list;
pub mod progress_bar;
pub mod radio;
pub mod row;
pub mod rule;
pub mod scrollable;
pub mod slider;
pub mod space;
pub mod svg;
pub mod text;
pub mod text_input;
pub mod toggler;
pub mod tooltip;
pub mod tree;
pub mod vertical_slider;
mod action; mod action;
mod id;
#[doc(no_inline)]
pub use button::Button;
#[doc(no_inline)]
pub use checkbox::Checkbox;
#[doc(no_inline)]
pub use column::Column;
#[doc(no_inline)]
pub use container::Container;
#[doc(no_inline)]
pub use helpers::*;
#[doc(no_inline)]
pub use image::Image;
#[doc(no_inline)]
pub use pane_grid::PaneGrid;
#[doc(no_inline)]
pub use pick_list::PickList;
#[doc(no_inline)]
pub use progress_bar::ProgressBar;
#[doc(no_inline)]
pub use radio::Radio;
#[doc(no_inline)]
pub use row::Row;
#[doc(no_inline)]
pub use rule::Rule;
#[doc(no_inline)]
pub use scrollable::Scrollable;
#[doc(no_inline)]
pub use slider::Slider;
#[doc(no_inline)]
pub use space::Space;
#[doc(no_inline)]
pub use svg::Svg;
#[doc(no_inline)]
pub use text::Text;
#[doc(no_inline)]
pub use text_input::TextInput;
#[doc(no_inline)]
pub use toggler::Toggler;
#[doc(no_inline)]
pub use tooltip::Tooltip;
#[doc(no_inline)]
pub use tree::Tree;
#[doc(no_inline)]
pub use vertical_slider::VerticalSlider;
pub use action::Action; pub use action::Action;
pub use id::Id;
pub use operation::Operation;
use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::{Clipboard, Layout, Length, Point, Rectangle, Shell};
/// A component that displays information and allows interaction.
///
/// If you want to build your own widgets, you will need to implement this
/// trait.
///
/// # Examples
/// The repository has some [examples] showcasing how to implement a custom
/// widget:
///
/// - [`bezier_tool`], a Paint-like tool for drawing Bézier curves using
/// [`lyon`].
/// - [`custom_widget`], a demonstration of how to build a custom widget that
/// draws a circle.
/// - [`geometry`], a custom widget showcasing how to draw geometry with the
/// `Mesh2D` primitive in [`iced_wgpu`].
///
/// [examples]: https://github.com/iced-rs/iced/tree/0.8/examples
/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.8/examples/bezier_tool
/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.8/examples/custom_widget
/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.8/examples/geometry
/// [`lyon`]: https://github.com/nical/lyon
/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.8/wgpu
pub trait Widget<Message, Renderer>
where
Renderer: crate::Renderer,
{
/// Returns the width of the [`Widget`].
fn width(&self) -> Length;
/// Returns the height of the [`Widget`].
fn height(&self) -> Length;
/// Returns the [`layout::Node`] of the [`Widget`].
///
/// This [`layout::Node`] is used by the runtime to compute the [`Layout`] of the
/// user interface.
fn layout(
&self,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node;
/// Draws the [`Widget`] using the associated `Renderer`.
fn draw(
&self,
state: &Tree,
renderer: &mut Renderer,
theme: &Renderer::Theme,
style: &renderer::Style,
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
);
/// Returns the [`Tag`] of the [`Widget`].
///
/// [`Tag`]: tree::Tag
fn tag(&self) -> tree::Tag {
tree::Tag::stateless()
}
/// Returns the [`State`] of the [`Widget`].
///
/// [`State`]: tree::State
fn state(&self) -> tree::State {
tree::State::None
}
/// Returns the state [`Tree`] of the children of the [`Widget`].
fn children(&self) -> Vec<Tree> {
Vec::new()
}
/// Reconciliates the [`Widget`] with the provided [`Tree`].
fn diff(&self, _tree: &mut Tree) {}
/// Applies an [`Operation`] to the [`Widget`].
fn operate(
&self,
_state: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn Operation<Message>,
) {
}
/// Processes a runtime [`Event`].
///
/// By default, it does nothing.
fn on_event(
&mut self,
_state: &mut Tree,
_event: Event,
_layout: Layout<'_>,
_cursor_position: Point,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
) -> event::Status {
event::Status::Ignored
}
/// Returns the current [`mouse::Interaction`] of the [`Widget`].
///
/// By default, it returns [`mouse::Interaction::Idle`].
fn mouse_interaction(
&self,
_state: &Tree,
_layout: Layout<'_>,
_cursor_position: Point,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> mouse::Interaction {
mouse::Interaction::Idle
}
/// Returns the overlay of the [`Widget`], if there is any.
fn overlay<'a>(
&'a mut self,
_state: &'a mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
) -> Option<overlay::Element<'a, Message, Renderer>> {
None
}
}

View file

@ -1,8 +1,7 @@
use crate::widget::operation::{ use iced_core::widget::operation::{
self, Focusable, Operation, Scrollable, TextInput, self, Focusable, Operation, Scrollable, TextInput,
}; };
use crate::widget::Id; use iced_core::widget::Id;
use iced_futures::MaybeSend; use iced_futures::MaybeSend;
use std::any::Any; use std::any::Any;

View file

@ -1,317 +0,0 @@
//! Helper functions to create pure widgets.
use crate::overlay;
use crate::widget;
use crate::{Element, Length, Pixels};
use std::borrow::Cow;
use std::ops::RangeInclusive;
/// Creates a [`Column`] with the given children.
///
/// [`Column`]: widget::Column
#[macro_export]
macro_rules! column {
() => (
$crate::widget::Column::new()
);
($($x:expr),+ $(,)?) => (
$crate::widget::Column::with_children(vec![$($crate::Element::from($x)),+])
);
}
/// Creates a [`Row`] with the given children.
///
/// [`Row`]: widget::Row
#[macro_export]
macro_rules! row {
() => (
$crate::widget::Row::new()
);
($($x:expr),+ $(,)?) => (
$crate::widget::Row::with_children(vec![$($crate::Element::from($x)),+])
);
}
/// Creates a new [`Container`] with the provided content.
///
/// [`Container`]: widget::Container
pub fn container<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Container<'a, Message, Renderer>
where
Renderer: crate::Renderer,
Renderer::Theme: widget::container::StyleSheet,
{
widget::Container::new(content)
}
/// Creates a new [`Column`] with the given children.
///
/// [`Column`]: widget::Column
pub fn column<Message, Renderer>(
children: Vec<Element<'_, Message, Renderer>>,
) -> widget::Column<'_, Message, Renderer> {
widget::Column::with_children(children)
}
/// Creates a new [`Row`] with the given children.
///
/// [`Row`]: widget::Row
pub fn row<Message, Renderer>(
children: Vec<Element<'_, Message, Renderer>>,
) -> widget::Row<'_, Message, Renderer> {
widget::Row::with_children(children)
}
/// Creates a new [`Scrollable`] with the provided content.
///
/// [`Scrollable`]: widget::Scrollable
pub fn scrollable<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Scrollable<'a, Message, Renderer>
where
Renderer: crate::Renderer,
Renderer::Theme: widget::scrollable::StyleSheet,
{
widget::Scrollable::new(content)
}
/// Creates a new [`Button`] with the provided content.
///
/// [`Button`]: widget::Button
pub fn button<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Button<'a, Message, Renderer>
where
Renderer: crate::Renderer,
Renderer::Theme: widget::button::StyleSheet,
<Renderer::Theme as widget::button::StyleSheet>::Style: Default,
{
widget::Button::new(content)
}
/// Creates a new [`Tooltip`] with the provided content, tooltip text, and [`tooltip::Position`].
///
/// [`Tooltip`]: widget::Tooltip
/// [`tooltip::Position`]: widget::tooltip::Position
pub fn tooltip<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
tooltip: impl ToString,
position: widget::tooltip::Position,
) -> widget::Tooltip<'a, Message, Renderer>
where
Renderer: crate::text::Renderer,
Renderer::Theme: widget::container::StyleSheet + widget::text::StyleSheet,
{
widget::Tooltip::new(content, tooltip.to_string(), position)
}
/// Creates a new [`Text`] widget with the provided content.
///
/// [`Text`]: widget::Text
pub fn text<'a, Renderer>(text: impl ToString) -> widget::Text<'a, Renderer>
where
Renderer: crate::text::Renderer,
Renderer::Theme: widget::text::StyleSheet,
{
widget::Text::new(text.to_string())
}
/// Creates a new [`Checkbox`].
///
/// [`Checkbox`]: widget::Checkbox
pub fn checkbox<'a, Message, Renderer>(
label: impl Into<String>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
) -> widget::Checkbox<'a, Message, Renderer>
where
Renderer: crate::text::Renderer,
Renderer::Theme: widget::checkbox::StyleSheet + widget::text::StyleSheet,
{
widget::Checkbox::new(label, is_checked, f)
}
/// Creates a new [`Radio`].
///
/// [`Radio`]: widget::Radio
pub fn radio<Message, Renderer, V>(
label: impl Into<String>,
value: V,
selected: Option<V>,
on_click: impl FnOnce(V) -> Message,
) -> widget::Radio<Message, Renderer>
where
Message: Clone,
Renderer: crate::text::Renderer,
Renderer::Theme: widget::radio::StyleSheet,
V: Copy + Eq,
{
widget::Radio::new(value, label, selected, on_click)
}
/// Creates a new [`Toggler`].
///
/// [`Toggler`]: widget::Toggler
pub fn toggler<'a, Message, Renderer>(
label: impl Into<Option<String>>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
) -> widget::Toggler<'a, Message, Renderer>
where
Renderer: crate::text::Renderer,
Renderer::Theme: widget::toggler::StyleSheet,
{
widget::Toggler::new(label, is_checked, f)
}
/// Creates a new [`TextInput`].
///
/// [`TextInput`]: widget::TextInput
pub fn text_input<'a, Message, Renderer>(
placeholder: &str,
value: &str,
on_change: impl Fn(String) -> Message + 'a,
) -> widget::TextInput<'a, Message, Renderer>
where
Message: Clone,
Renderer: crate::text::Renderer,
Renderer::Theme: widget::text_input::StyleSheet,
{
widget::TextInput::new(placeholder, value, on_change)
}
/// Creates a new [`Slider`].
///
/// [`Slider`]: widget::Slider
pub fn slider<'a, T, Message, Renderer>(
range: std::ops::RangeInclusive<T>,
value: T,
on_change: impl Fn(T) -> Message + 'a,
) -> widget::Slider<'a, T, Message, Renderer>
where
T: Copy + From<u8> + std::cmp::PartialOrd,
Message: Clone,
Renderer: crate::Renderer,
Renderer::Theme: widget::slider::StyleSheet,
{
widget::Slider::new(range, value, on_change)
}
/// Creates a new [`VerticalSlider`].
///
/// [`VerticalSlider`]: widget::VerticalSlider
pub fn vertical_slider<'a, T, Message, Renderer>(
range: std::ops::RangeInclusive<T>,
value: T,
on_change: impl Fn(T) -> Message + 'a,
) -> widget::VerticalSlider<'a, T, Message, Renderer>
where
T: Copy + From<u8> + std::cmp::PartialOrd,
Message: Clone,
Renderer: crate::Renderer,
Renderer::Theme: widget::slider::StyleSheet,
{
widget::VerticalSlider::new(range, value, on_change)
}
/// Creates a new [`PickList`].
///
/// [`PickList`]: widget::PickList
pub fn pick_list<'a, Message, Renderer, T>(
options: impl Into<Cow<'a, [T]>>,
selected: Option<T>,
on_selected: impl Fn(T) -> Message + 'a,
) -> widget::PickList<'a, T, Message, Renderer>
where
T: ToString + Eq + 'static,
[T]: ToOwned<Owned = Vec<T>>,
Renderer: crate::text::Renderer,
Renderer::Theme: widget::pick_list::StyleSheet
+ widget::scrollable::StyleSheet
+ overlay::menu::StyleSheet
+ widget::container::StyleSheet,
<Renderer::Theme as overlay::menu::StyleSheet>::Style:
From<<Renderer::Theme as widget::pick_list::StyleSheet>::Style>,
{
widget::PickList::new(options, selected, on_selected)
}
/// Creates a new [`Image`].
///
/// [`Image`]: widget::Image
pub fn image<Handle>(handle: impl Into<Handle>) -> widget::Image<Handle> {
widget::Image::new(handle.into())
}
/// Creates a new horizontal [`Space`] with the given [`Length`].
///
/// [`Space`]: widget::Space
pub fn horizontal_space(width: impl Into<Length>) -> widget::Space {
widget::Space::with_width(width)
}
/// Creates a new vertical [`Space`] with the given [`Length`].
///
/// [`Space`]: widget::Space
pub fn vertical_space(height: impl Into<Length>) -> widget::Space {
widget::Space::with_height(height)
}
/// Creates a horizontal [`Rule`] with the given height.
///
/// [`Rule`]: widget::Rule
pub fn horizontal_rule<Renderer>(
height: impl Into<Pixels>,
) -> widget::Rule<Renderer>
where
Renderer: crate::Renderer,
Renderer::Theme: widget::rule::StyleSheet,
{
widget::Rule::horizontal(height)
}
/// Creates a vertical [`Rule`] with the given width.
///
/// [`Rule`]: widget::Rule
pub fn vertical_rule<Renderer>(
width: impl Into<Pixels>,
) -> widget::Rule<Renderer>
where
Renderer: crate::Renderer,
Renderer::Theme: widget::rule::StyleSheet,
{
widget::Rule::vertical(width)
}
/// Creates a new [`ProgressBar`].
///
/// It expects:
/// * an inclusive range of possible values, and
/// * the current value of the [`ProgressBar`].
///
/// [`ProgressBar`]: widget::ProgressBar
pub fn progress_bar<Renderer>(
range: RangeInclusive<f32>,
value: f32,
) -> widget::ProgressBar<Renderer>
where
Renderer: crate::Renderer,
Renderer::Theme: widget::progress_bar::StyleSheet,
{
widget::ProgressBar::new(range, value)
}
/// Creates a new [`Svg`] widget from the given [`Handle`].
///
/// [`Svg`]: widget::Svg
/// [`Handle`]: widget::svg::Handle
pub fn svg<Renderer>(
handle: impl Into<widget::svg::Handle>,
) -> widget::Svg<Renderer>
where
Renderer: crate::svg::Renderer,
Renderer::Theme: widget::svg::StyleSheet,
{
widget::Svg::new(handle)
}

View file

@ -1,18 +1,11 @@
//! Build window-based GUI applications. //! Build window-based GUI applications.
mod action; mod action;
mod event;
mod mode;
mod redraw_request;
mod user_attention;
pub use action::Action; pub use action::Action;
pub use event::Event;
pub use mode::Mode;
pub use redraw_request::RedrawRequest;
pub use user_attention::UserAttention;
use crate::core::time::Instant;
use crate::core::window::Event;
use crate::subscription::{self, Subscription}; use crate::subscription::{self, Subscription};
use crate::time::Instant;
/// Subscribes to the frames of the window of the running application. /// Subscribes to the frames of the window of the running application.
/// ///
@ -24,7 +17,7 @@ use crate::time::Instant;
/// animations without missing any frames. /// animations without missing any frames.
pub fn frames() -> Subscription<Instant> { pub fn frames() -> Subscription<Instant> {
subscription::raw_events(|event, _status| match event { subscription::raw_events(|event, _status| match event {
crate::Event::Window(Event::RedrawRequested(at)) => Some(at), iced_core::Event::Window(Event::RedrawRequested(at)) => Some(at),
_ => None, _ => None,
}) })
} }

View file

@ -1,6 +1,6 @@
use crate::window::{Mode, UserAttention}; use crate::core::window::{Mode, UserAttention};
use crate::futures::MaybeSend;
use iced_futures::MaybeSend;
use std::fmt; use std::fmt;
/// An operation to be performed on some window. /// An operation to be performed on some window.

Some files were not shown because too many files have changed in this diff Show more