summaryrefslogtreecommitdiffstats
path: root/examples/qr_code/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qr_code/src/main.rs')
-rw-r--r--examples/qr_code/src/main.rs34
1 files changed, 26 insertions, 8 deletions
diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs
index 867ebfa4..8b2e9500 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())
@@ -9,12 +9,14 @@ pub fn main() -> iced::Result {
#[derive(Default)]
struct QRGenerator {
data: String,
- qr_code: Option<qr_code::State>,
+ qr_code: Option<qr_code::Data>,
+ theme: Theme,
}
#[derive(Debug, Clone)]
enum Message {
DataChanged(String),
+ ThemeChanged(Theme),
}
impl Sandbox for QRGenerator {
@@ -36,18 +38,19 @@ impl Sandbox for QRGenerator {
self.qr_code = if data.is_empty() {
None
} else {
- qr_code::State::new(&data).ok()
+ qr_code::Data::new(&data).ok()
};
self.data = data;
}
+ Message::ThemeChanged(theme) => {
+ self.theme = theme;
+ }
}
}
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 +58,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 +86,8 @@ impl Sandbox for QRGenerator {
.center_y()
.into()
}
+
+ fn theme(&self) -> Theme {
+ self.theme.clone()
+ }
}