summaryrefslogtreecommitdiffstats
path: root/examples/qr_code
diff options
context:
space:
mode:
authorLibravatar Clark Moody <clark@clarkmoody.com>2024-02-02 10:45:37 -0600
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-09 23:47:09 +0100
commit4c6ea3cfe2f6023a2f92d8ebfc227f0381c8ac78 (patch)
tree9164d63bda877dde29069748b5f72919eb04fbce /examples/qr_code
parentc2d82833a0d56660b66bb06a9fb6360f425416af (diff)
downloadiced-4c6ea3cfe2f6023a2f92d8ebfc227f0381c8ac78.tar.gz
iced-4c6ea3cfe2f6023a2f92d8ebfc227f0381c8ac78.tar.bz2
iced-4c6ea3cfe2f6023a2f92d8ebfc227f0381c8ac78.zip
Update `qr_code` example with theme selector
Diffstat (limited to 'examples/qr_code')
-rw-r--r--examples/qr_code/src/main.rs34
1 files changed, 28 insertions, 6 deletions
diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs
index 867ebfa4..68bbf260 100644
--- a/examples/qr_code/src/main.rs
+++ b/examples/qr_code/src/main.rs
@@ -1,6 +1,6 @@
use iced::widget::qr_code::{self, QRCode};
-use iced::widget::{column, container, text, text_input};
-use iced::{Alignment, Color, Element, Length, Sandbox, Settings};
+use iced::widget::{column, container, pick_list, row, text, text_input};
+use iced::{Alignment, Element, Length, Sandbox, Settings, Theme};
pub fn main() -> iced::Result {
QRGenerator::run(Settings::default())
@@ -10,11 +10,13 @@ pub fn main() -> iced::Result {
struct QRGenerator {
data: String,
qr_code: Option<qr_code::State>,
+ theme: Theme,
}
#[derive(Debug, Clone)]
enum Message {
DataChanged(String),
+ ThemeChanged(Theme),
}
impl Sandbox for QRGenerator {
@@ -41,13 +43,18 @@ impl Sandbox for QRGenerator {
self.data = data;
}
+ Message::ThemeChanged(theme) => {
+ self.theme = theme;
+
+ if self.qr_code.is_some() {
+ self.qr_code = qr_code::State::new(&self.data).ok();
+ }
+ }
}
}
fn view(&self) -> Element<Message> {
- let title = text("QR Code Generator")
- .size(70)
- .style(Color::from([0.5, 0.5, 0.5]));
+ let title = text("QR Code Generator").size(70);
let input =
text_input("Type the data of your QR code here...", &self.data)
@@ -55,7 +62,18 @@ impl Sandbox for QRGenerator {
.size(30)
.padding(15);
- let mut content = column![title, input]
+ let choose_theme = row![
+ text("Theme:"),
+ pick_list(
+ Theme::ALL,
+ Some(self.theme.clone()),
+ Message::ThemeChanged,
+ )
+ ]
+ .spacing(10)
+ .align_items(Alignment::Center);
+
+ let mut content = column![title, input, choose_theme]
.width(700)
.spacing(20)
.align_items(Alignment::Center);
@@ -72,4 +90,8 @@ impl Sandbox for QRGenerator {
.center_y()
.into()
}
+
+ fn theme(&self) -> Theme {
+ self.theme.clone()
+ }
}