diff options
author | 2022-08-06 00:32:57 +0200 | |
---|---|---|
committer | 2022-08-06 00:32:57 +0200 | |
commit | 1923dbf7f0769d55e5283f572fde0ce752e28b86 (patch) | |
tree | 7be9b36f941f6e13ddc8884f715c04555b1e77db /src/widget.rs | |
parent | 1b4f38c71f6e05e26599ee75ea9c91dde96e71ae (diff) | |
parent | c23ed7e4a0a2b62a0d7cabe6e35d7323eac543d2 (diff) | |
download | iced-1923dbf7f0769d55e5283f572fde0ce752e28b86.tar.gz iced-1923dbf7f0769d55e5283f572fde0ce752e28b86.tar.bz2 iced-1923dbf7f0769d55e5283f572fde0ce752e28b86.zip |
Merge pull request #1393 from iced-rs/deprecate-stateful-widgets
Replace stateful widgets with the new `iced_pure` API
Diffstat (limited to '')
-rw-r--r-- | src/widget.rs | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/src/widget.rs b/src/widget.rs index b8b5c493..817d2d33 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -1,18 +1,7 @@ //! Display information and interactive controls in your application. -//! -//! # Re-exports -//! For convenience, the contents of this module are available at the root -//! module. Therefore, you can directly type: -//! -//! ``` -//! use iced::{button, Button}; -//! ``` -//! -//! # Stateful widgets -//! Some widgets need to keep track of __local state__. -//! -//! These widgets have their own module with a `State` type. For instance, a -//! [`TextInput`] has some [`text_input::State`]. +pub use iced_native::widget::helpers::*; + +pub use iced_native::{column, row}; /// A container that distributes its contents vertically. pub type Column<'a, Message, Renderer = crate::Renderer> = @@ -22,14 +11,18 @@ pub type Column<'a, Message, Renderer = crate::Renderer> = pub type Row<'a, Message, Renderer = crate::Renderer> = iced_native::widget::Row<'a, Message, Renderer>; -/// A paragraph of text. -pub type Text<Renderer = crate::Renderer> = iced_native::widget::Text<Renderer>; +pub mod text { + //! Write some text for your users to read. + pub use iced_native::widget::text::{Appearance, StyleSheet}; + + /// A paragraph of text. + pub type Text<Renderer = crate::Renderer> = + iced_native::widget::Text<Renderer>; +} pub mod button { //! Allow your users to perform actions by pressing a button. - //! - //! A [`Button`] has some local [`State`]. - pub use iced_native::widget::button::{Appearance, State, StyleSheet}; + pub use iced_native::widget::button::{Appearance, StyleSheet}; /// A widget that produces a message when clicked. pub type Button<'a, Message, Renderer = crate::Renderer> = @@ -87,7 +80,7 @@ pub mod pane_grid { pub mod pick_list { //! Display a dropdown list of selectable values. - pub use iced_native::widget::pick_list::{Appearance, State, StyleSheet}; + pub use iced_native::widget::pick_list::{Appearance, StyleSheet}; /// A widget allowing the selection of a single value from a list of options. pub type PickList<'a, T, Message, Renderer = crate::Renderer> = @@ -106,7 +99,7 @@ pub mod radio { pub mod scrollable { //! Navigate an endless amount of content with a scrollbar. pub use iced_native::widget::scrollable::{ - style::Scrollbar, style::Scroller, State, StyleSheet, + snap_to, style::Scrollbar, style::Scroller, Id, StyleSheet, }; /// A widget that can vertically display an infinite amount of content @@ -126,9 +119,9 @@ pub mod toggler { pub mod text_input { //! Display fields that can be filled with text. - //! - //! A [`TextInput`] has some local [`State`]. - pub use iced_native::widget::text_input::{Appearance, State, StyleSheet}; + pub use iced_native::widget::text_input::{ + focus, Appearance, Id, StyleSheet, + }; /// A field that can be filled with text. pub type TextInput<'a, Message, Renderer = crate::Renderer> = @@ -159,6 +152,7 @@ pub use radio::Radio; pub use rule::Rule; pub use scrollable::Scrollable; pub use slider::Slider; +pub use text::Text; pub use text_input::TextInput; pub use toggler::Toggler; pub use tooltip::Tooltip; @@ -167,6 +161,16 @@ pub use tooltip::Tooltip; #[cfg_attr(docsrs, doc(cfg(feature = "canvas")))] pub use iced_graphics::widget::canvas; +#[cfg(feature = "canvas")] +#[cfg_attr(docsrs, doc(cfg(feature = "canvas")))] +/// Creates a new [`Canvas`]. +pub fn canvas<P, Message, Theme>(program: P) -> Canvas<Message, Theme, P> +where + P: canvas::Program<Message, Theme>, +{ + Canvas::new(program) +} + #[cfg(feature = "image")] #[cfg_attr(docsrs, doc(cfg(feature = "image")))] pub mod image { @@ -207,3 +211,22 @@ pub use qr_code::QRCode; #[cfg(feature = "svg")] #[cfg_attr(docsrs, doc(cfg(feature = "svg")))] pub use svg::Svg; + +use crate::Command; +use iced_native::widget::operation; + +/// Focuses the previous focusable widget. +pub fn focus_previous<Message>() -> Command<Message> +where + Message: 'static, +{ + Command::widget(operation::focusable::focus_previous()) +} + +/// Focuses the next focusable widget. +pub fn focus_next<Message>() -> Command<Message> +where + Message: 'static, +{ + Command::widget(operation::focusable::focus_next()) +} |