summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-03-16 17:09:00 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-16 17:09:00 +0100
commit503a48e89977437bf8b7bf485f416a15a2e83ed0 (patch)
tree30306bbaee7a31090ace9d7725d46c2c0027fe6b /src/lib.rs
parent0524e9b4571d264018656418f02a1f9e27e268d7 (diff)
parentcfc0383bbfff083786840e3f1fd499e5991fa629 (diff)
downloadiced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.gz
iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.bz2
iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.zip
Merge pull request #2331 from iced-rs/program-api
`Program` API
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c596f2a6..cda5341c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -175,6 +175,7 @@ mod error;
mod sandbox;
pub mod application;
+pub mod program;
pub mod settings;
pub mod time;
pub mod window;
@@ -308,6 +309,7 @@ pub use error::Error;
pub use event::Event;
pub use executor::Executor;
pub use font::Font;
+pub use program::Program;
pub use renderer::Renderer;
pub use sandbox::Sandbox;
pub use settings::Settings;
@@ -327,3 +329,49 @@ pub type Element<
///
/// [`Application`]: crate::Application
pub type Result = std::result::Result<(), Error>;
+
+/// Runs a basic iced application with default [`Settings`] given
+/// - its window title,
+/// - its update logic,
+/// - and its view logic.
+///
+/// # Example
+/// ```no_run
+/// use iced::widget::{button, column, text, Column};
+///
+/// pub fn main() -> iced::Result {
+/// iced::run("A counter", update, view)
+/// }
+///
+/// #[derive(Debug, Clone)]
+/// enum Message {
+/// Increment,
+/// }
+///
+/// fn update(value: &mut u64, message: Message) {
+/// match message {
+/// Message::Increment => *value += 1,
+/// }
+/// }
+///
+/// fn view(value: &u64) -> Column<Message> {
+/// column![
+/// text(value),
+/// button("+").on_press(Message::Increment),
+/// ]
+/// }
+/// ```
+pub fn run<State, Message>(
+ title: impl program::Title<State> + 'static,
+ update: impl Fn(&mut State, Message) + 'static,
+ view: impl for<'a> program::View<'a, State, Message> + 'static,
+) -> Result
+where
+ State: Default + 'static,
+ Message: std::fmt::Debug + Send + 'static,
+{
+ sandbox(title, update, view).run()
+}
+
+#[doc(inline)]
+pub use program::{application, sandbox};