summaryrefslogtreecommitdiffstats
path: root/examples/screenshot/src
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 /examples/screenshot/src
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 'examples/screenshot/src')
-rw-r--r--examples/screenshot/src/main.rs42
1 files changed, 9 insertions, 33 deletions
diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs
index 2a1eded7..296a7f54 100644
--- a/examples/screenshot/src/main.rs
+++ b/examples/screenshot/src/main.rs
@@ -1,12 +1,10 @@
use iced::alignment;
-use iced::executor;
use iced::keyboard;
use iced::widget::{button, column, container, image, row, text, text_input};
use iced::window;
use iced::window::screenshot::{self, Screenshot};
use iced::{
- Alignment, Application, Command, ContentFit, Element, Length, Rectangle,
- Subscription, Theme,
+ Alignment, Command, ContentFit, Element, Length, Rectangle, Subscription,
};
use ::image as img;
@@ -15,9 +13,12 @@ use ::image::ColorType;
fn main() -> iced::Result {
tracing_subscriber::fmt::init();
- Example::run(iced::Settings::default())
+ iced::application("Screenshot - Iced", Example::update, Example::view)
+ .subscription(Example::subscription)
+ .run()
}
+#[derive(Default)]
struct Example {
screenshot: Option<Screenshot>,
saved_png_path: Option<Result<String, PngError>>,
@@ -42,33 +43,8 @@ enum Message {
HeightInputChanged(Option<u32>),
}
-impl Application for Example {
- type Executor = executor::Default;
- type Message = Message;
- type Theme = Theme;
- type Flags = ();
-
- fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) {
- (
- Example {
- screenshot: None,
- saved_png_path: None,
- png_saving: false,
- crop_error: None,
- x_input_value: None,
- y_input_value: None,
- width_input_value: None,
- height_input_value: None,
- },
- Command::none(),
- )
- }
-
- fn title(&self) -> String {
- "Screenshot".to_string()
- }
-
- fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
+impl Example {
+ fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Screenshot => {
return iced::window::screenshot(
@@ -130,7 +106,7 @@ impl Application for Example {
Command::none()
}
- fn view(&self) -> Element<'_, Self::Message> {
+ fn view(&self) -> Element<'_, Message> {
let image: Element<Message> = if let Some(screenshot) = &self.screenshot
{
image(image::Handle::from_pixels(
@@ -259,7 +235,7 @@ impl Application for Example {
.into()
}
- fn subscription(&self) -> Subscription<Self::Message> {
+ fn subscription(&self) -> Subscription<Message> {
use keyboard::key;
keyboard::on_key_press(|key, _modifiers| {