Implement Widget::draw for QRCode in iced_graphics
This commit is contained in:
parent
0b66095f9f
commit
77bab6beee
1 changed files with 41 additions and 41 deletions
|
|
@ -5,7 +5,8 @@ use crate::Backend;
|
||||||
|
|
||||||
use iced_native::layout;
|
use iced_native::layout;
|
||||||
use iced_native::{
|
use iced_native::{
|
||||||
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector,
|
||||||
|
Widget,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -81,56 +82,55 @@ where
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
_renderer: &mut Renderer<B>,
|
renderer: &mut Renderer<B>,
|
||||||
_style: &renderer::Style,
|
_style: &renderer::Style,
|
||||||
_layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
_cursor_position: Point,
|
_cursor_position: Point,
|
||||||
_viewport: &Rectangle,
|
_viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
// let bounds = layout.bounds();
|
use iced_native::Renderer as _;
|
||||||
// let side_length = self.state.width + 2 * QUIET_ZONE;
|
|
||||||
|
|
||||||
// // Reuse cache if possible
|
let bounds = layout.bounds();
|
||||||
// let geometry = self.state.cache.draw(bounds.size(), |frame| {
|
let side_length = self.state.width + 2 * QUIET_ZONE;
|
||||||
// // Scale units to cell size
|
|
||||||
// frame.scale(f32::from(self.cell_size));
|
|
||||||
|
|
||||||
// // Draw background
|
// Reuse cache if possible
|
||||||
// frame.fill_rectangle(
|
let geometry = self.state.cache.draw(bounds.size(), |frame| {
|
||||||
// Point::ORIGIN,
|
// Scale units to cell size
|
||||||
// Size::new(side_length as f32, side_length as f32),
|
frame.scale(f32::from(self.cell_size));
|
||||||
// self.light,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // Avoid drawing on the quiet zone
|
// Draw background
|
||||||
// frame.translate(Vector::new(QUIET_ZONE as f32, QUIET_ZONE as f32));
|
frame.fill_rectangle(
|
||||||
|
Point::ORIGIN,
|
||||||
|
Size::new(side_length as f32, side_length as f32),
|
||||||
|
self.light,
|
||||||
|
);
|
||||||
|
|
||||||
// // Draw contents
|
// Avoid drawing on the quiet zone
|
||||||
// self.state
|
frame.translate(Vector::new(QUIET_ZONE as f32, QUIET_ZONE as f32));
|
||||||
// .contents
|
|
||||||
// .iter()
|
|
||||||
// .enumerate()
|
|
||||||
// .filter(|(_, value)| **value == qrcode::Color::Dark)
|
|
||||||
// .for_each(|(index, _)| {
|
|
||||||
// let row = index / self.state.width;
|
|
||||||
// let column = index % self.state.width;
|
|
||||||
|
|
||||||
// frame.fill_rectangle(
|
// Draw contents
|
||||||
// Point::new(column as f32, row as f32),
|
self.state
|
||||||
// Size::UNIT,
|
.contents
|
||||||
// self.dark,
|
.iter()
|
||||||
// );
|
.enumerate()
|
||||||
// });
|
.filter(|(_, value)| **value == qrcode::Color::Dark)
|
||||||
// });
|
.for_each(|(index, _)| {
|
||||||
|
let row = index / self.state.width;
|
||||||
|
let column = index % self.state.width;
|
||||||
|
|
||||||
// (
|
frame.fill_rectangle(
|
||||||
// Primitive::Translate {
|
Point::new(column as f32, row as f32),
|
||||||
// translation: Vector::new(bounds.x, bounds.y),
|
Size::UNIT,
|
||||||
// content: Box::new(geometry.into_primitive()),
|
self.dark,
|
||||||
// },
|
);
|
||||||
// mouse::Interaction::default(),
|
});
|
||||||
// )
|
});
|
||||||
// TODO
|
|
||||||
|
let translation = Vector::new(bounds.x, bounds.y);
|
||||||
|
|
||||||
|
renderer.with_translation(translation, |renderer| {
|
||||||
|
renderer.draw_primitive(geometry.into_primitive());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue