Skip to content

Commit

Permalink
feat: support build_pattern for iced_sessionlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 3, 2024
1 parent 9ff9f5c commit 599cb4b
Show file tree
Hide file tree
Showing 4 changed files with 739 additions and 592 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions iced_examples/counter_lock_pattern/Cargo.toml
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
87 changes: 87 additions & 0 deletions iced_examples/counter_lock_pattern/src/main.rs
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()
}
}
Loading

0 comments on commit 599cb4b

Please sign in to comment.