Skip to content

Commit

Permalink
Implement pure version of Svg widget
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Mar 22, 2022
1 parent 9157f5b commit ef4c79e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pure/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod radio;
pub mod rule;
pub mod scrollable;
pub mod slider;
pub mod svg;
pub mod text_input;
pub mod toggler;
pub mod tree;
Expand All @@ -32,6 +33,7 @@ pub use rule::Rule;
pub use scrollable::Scrollable;
pub use slider::Slider;
pub use space::Space;
pub use svg::Svg;
pub use text::Text;
pub use text_input::TextInput;
pub use toggler::Toggler;
Expand Down
62 changes: 62 additions & 0 deletions pure/src/widget/svg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::widget::{Tree, Widget};
use crate::Element;

use iced_native::layout::{self, Layout};
use iced_native::renderer;
use iced_native::widget::svg;
use iced_native::{Length, Point, Rectangle};

pub use iced_native::svg::Handle;
pub use svg::Svg;

impl<Message, Renderer> Widget<Message, Renderer> for Svg
where
Renderer: iced_native::svg::Renderer,
{
fn width(&self) -> Length {
<Self as iced_native::Widget<Message, Renderer>>::width(self)
}

fn height(&self) -> Length {
<Self as iced_native::Widget<Message, Renderer>>::height(self)
}

fn layout(
&self,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
<Self as iced_native::Widget<Message, Renderer>>::layout(
self, renderer, limits,
)
}

fn draw(
&self,
_tree: &Tree,
renderer: &mut Renderer,
style: &renderer::Style,
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
) {
<Self as iced_native::Widget<Message, Renderer>>::draw(
self,
renderer,
style,
layout,
cursor_position,
viewport,
)
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Svg
where
Message: Clone + 'a,
Renderer: iced_native::svg::Renderer + 'a,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
}
}
6 changes: 6 additions & 0 deletions src/pure/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ pub mod image {
pub type Image = iced_pure::widget::Image<Handle>;
}

#[cfg(feature = "svg")]
pub use iced_pure::widget::svg;

#[cfg(feature = "canvas")]
pub use canvas::Canvas;

Expand All @@ -159,3 +162,6 @@ pub use qr_code::QRCode;

#[cfg(feature = "image")]
pub use image::Image;

#[cfg(feature = "svg")]
pub use svg::Svg;

0 comments on commit ef4c79e

Please sign in to comment.