summaryrefslogtreecommitdiffstats
path: root/style/src/theme.rs
diff options
context:
space:
mode:
authorLibravatar Clark Moody <clark@clarkmoody.com>2024-02-01 16:23:41 -0600
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-09 23:43:01 +0100
commitc2d82833a0d56660b66bb06a9fb6360f425416af (patch)
treecb506d15b15d99d77db446ec132c8fe926dc686e /style/src/theme.rs
parent99a3f25c5f95a144fee7d25b4607f7275abcfaa2 (diff)
downloadiced-c2d82833a0d56660b66bb06a9fb6360f425416af.tar.gz
iced-c2d82833a0d56660b66bb06a9fb6360f425416af.tar.bz2
iced-c2d82833a0d56660b66bb06a9fb6360f425416af.zip
Styling for QR Code using theme framework
Diffstat (limited to 'style/src/theme.rs')
-rw-r--r--style/src/theme.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/style/src/theme.rs b/style/src/theme.rs
index e579a1c2..afb4d027 100644
--- a/style/src/theme.rs
+++ b/style/src/theme.rs
@@ -12,6 +12,7 @@ use crate::menu;
use crate::pane_grid;
use crate::pick_list;
use crate::progress_bar;
+use crate::qr_code;
use crate::radio;
use crate::rule;
use crate::scrollable;
@@ -956,6 +957,46 @@ impl<T: Fn(&Theme) -> progress_bar::Appearance> progress_bar::StyleSheet for T {
}
}
+/// The style of a QR Code.
+#[derive(Default)]
+pub enum QRCode {
+ /// The default style.
+ #[default]
+ Default,
+ /// A custom style.
+ Custom(Box<dyn qr_code::StyleSheet<Style = Theme>>),
+}
+
+impl<T: Fn(&Theme) -> qr_code::Appearance + 'static> From<T> for QRCode {
+ fn from(f: T) -> Self {
+ Self::Custom(Box::new(f))
+ }
+}
+
+impl qr_code::StyleSheet for Theme {
+ type Style = QRCode;
+
+ fn appearance(&self, style: &Self::Style) -> qr_code::Appearance {
+ let palette = self.palette();
+
+ match style {
+ QRCode::Default => qr_code::Appearance {
+ cell: palette.text,
+ background: palette.background,
+ },
+ QRCode::Custom(custom) => custom.appearance(self),
+ }
+ }
+}
+
+impl<T: Fn(&Theme) -> qr_code::Appearance> qr_code::StyleSheet for T {
+ type Style = Theme;
+
+ fn appearance(&self, style: &Self::Style) -> qr_code::Appearance {
+ (self)(style)
+ }
+}
+
/// The style of a rule.
#[derive(Default)]
pub enum Rule {