-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support build_pattern for iced_sessionlock
- Loading branch information
1 parent
9ff9f5c
commit 599cb4b
Showing
4 changed files
with
739 additions
and
592 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "counter_lock_pattern" | ||
authors.workspace = true | ||
edition.workspace = true | ||
version.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
description.workspace = true | ||
keywords.workspace = true | ||
readme.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
iced.workspace = true | ||
iced_runtime.workspace = true | ||
iced_sessionlock.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use iced::widget::{button, column, text, text_input, Space}; | ||
use iced::{event, Alignment, Element, Event, Length, Task as Command}; | ||
use iced_sessionlock::actions::UnLockAction; | ||
use iced_sessionlock::build_pattern::application; | ||
pub fn main() -> Result<(), iced_sessionlock::Error> { | ||
application(Counter::update, Counter::view) | ||
.subscription(Counter::subscription) | ||
.run_with(Counter::new) | ||
} | ||
|
||
struct Counter { | ||
value: i32, | ||
text: String, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
enum Message { | ||
IncrementPressed, | ||
DecrementPressed, | ||
TextInput(String), | ||
IcedEvent(Event), | ||
UnLock, | ||
} | ||
|
||
impl TryInto<UnLockAction> for Message { | ||
type Error = Self; | ||
fn try_into(self) -> Result<UnLockAction, Self::Error> { | ||
if let Self::UnLock = self { | ||
return Ok(UnLockAction); | ||
} | ||
Err(self) | ||
} | ||
} | ||
|
||
impl Counter { | ||
fn new() -> (Self, Command<Message>) { | ||
( | ||
Self { | ||
value: 0, | ||
text: "lock".to_string(), | ||
}, | ||
Command::none(), | ||
) | ||
} | ||
|
||
fn subscription(&self) -> iced::Subscription<Message> { | ||
event::listen().map(Message::IcedEvent) | ||
} | ||
|
||
fn update(&mut self, message: Message) -> Command<Message> { | ||
match message { | ||
Message::IcedEvent(_event) => Command::none(), | ||
Message::IncrementPressed => { | ||
self.value += 1; | ||
Command::none() | ||
} | ||
Message::DecrementPressed => { | ||
self.value -= 1; | ||
Command::none() | ||
} | ||
Message::TextInput(text) => { | ||
self.text = text; | ||
Command::none() | ||
} | ||
Message::UnLock => Command::done(message), | ||
} | ||
} | ||
|
||
fn view(&self, _id: iced::window::Id) -> Element<Message> { | ||
column![ | ||
Space::with_height(Length::Fill), | ||
button("Increment").on_press(Message::IncrementPressed), | ||
button("UnLock").on_press(Message::UnLock), | ||
text(self.value).size(50), | ||
text_input("hello", &self.text) | ||
.on_input(Message::TextInput) | ||
.padding(10), | ||
button("Decrement").on_press(Message::DecrementPressed), | ||
Space::with_height(Length::Fill), | ||
] | ||
.padding(20) | ||
.align_x(Alignment::Center) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.into() | ||
} | ||
} |
Oops, something went wrong.