Implement pure version of QRCode widget
This commit is contained in:
parent
497a3ca8ab
commit
989c562920
3 changed files with 73 additions and 0 deletions
|
|
@ -4,3 +4,9 @@ pub mod canvas;
|
||||||
|
|
||||||
#[cfg(feature = "canvas")]
|
#[cfg(feature = "canvas")]
|
||||||
pub use canvas::Canvas;
|
pub use canvas::Canvas;
|
||||||
|
|
||||||
|
#[cfg(feature = "qr_code")]
|
||||||
|
pub mod qr_code;
|
||||||
|
|
||||||
|
#[cfg(feature = "qr_code")]
|
||||||
|
pub use qr_code::QRCode;
|
||||||
|
|
|
||||||
61
graphics/src/widget/pure/qr_code.rs
Normal file
61
graphics/src/widget/pure/qr_code.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
//! Encode and display information in a QR code.
|
||||||
|
pub use crate::qr_code::*;
|
||||||
|
|
||||||
|
use crate::{Backend, Renderer};
|
||||||
|
|
||||||
|
use iced_native::layout::{self, Layout};
|
||||||
|
use iced_native::renderer;
|
||||||
|
use iced_native::{Length, Point, Rectangle};
|
||||||
|
use iced_pure::widget::tree::Tree;
|
||||||
|
use iced_pure::{Element, Widget};
|
||||||
|
|
||||||
|
impl<'a, Message, B> Widget<Message, Renderer<B>> for QRCode<'a>
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
|
fn width(&self) -> Length {
|
||||||
|
<Self as iced_native::Widget<Message, Renderer<B>>>::width(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn height(&self) -> Length {
|
||||||
|
<Self as iced_native::Widget<Message, Renderer<B>>>::height(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout(
|
||||||
|
&self,
|
||||||
|
renderer: &Renderer<B>,
|
||||||
|
limits: &layout::Limits,
|
||||||
|
) -> layout::Node {
|
||||||
|
<Self as iced_native::Widget<Message, Renderer<B>>>::layout(
|
||||||
|
self, renderer, limits,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(
|
||||||
|
&self,
|
||||||
|
_tree: &Tree,
|
||||||
|
renderer: &mut Renderer<B>,
|
||||||
|
style: &renderer::Style,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor_position: Point,
|
||||||
|
viewport: &Rectangle,
|
||||||
|
) {
|
||||||
|
<Self as iced_native::Widget<Message, Renderer<B>>>::draw(
|
||||||
|
self,
|
||||||
|
renderer,
|
||||||
|
style,
|
||||||
|
layout,
|
||||||
|
cursor_position,
|
||||||
|
viewport,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, Message, B> Into<Element<'a, Message, Renderer<B>>> for QRCode<'a>
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
|
fn into(self) -> Element<'a, Message, Renderer<B>> {
|
||||||
|
Element::new(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -139,6 +139,9 @@ pub use toggler::Toggler;
|
||||||
#[cfg(feature = "canvas")]
|
#[cfg(feature = "canvas")]
|
||||||
pub use iced_graphics::widget::pure::canvas;
|
pub use iced_graphics::widget::pure::canvas;
|
||||||
|
|
||||||
|
#[cfg(feature = "qr_code")]
|
||||||
|
pub use iced_graphics::widget::pure::qr_code;
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
pub mod image {
|
pub mod image {
|
||||||
//! Display images in your user interface.
|
//! Display images in your user interface.
|
||||||
|
|
@ -151,5 +154,8 @@ pub mod image {
|
||||||
#[cfg(feature = "canvas")]
|
#[cfg(feature = "canvas")]
|
||||||
pub use canvas::Canvas;
|
pub use canvas::Canvas;
|
||||||
|
|
||||||
|
#[cfg(feature = "qr_code")]
|
||||||
|
pub use qr_code::QRCode;
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
pub use image::Image;
|
pub use image::Image;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue