summaryrefslogtreecommitdiffstats
path: root/examples/svg.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-12-16 21:38:33 +0100
committerLibravatar GitHub <noreply@github.com>2019-12-16 21:38:33 +0100
commit3702b109977a249247a0f1be40e57bec2cbaa4e3 (patch)
tree9919f2ee30ab29c83a2455f838313ab5bfb2f146 /examples/svg.rs
parentc1b9f6652517dcbf5ffd83b5db4a624f9a5b0da4 (diff)
parent514ccf8a72d660d77f26e085b545e5104389c138 (diff)
downloadiced-3702b109977a249247a0f1be40e57bec2cbaa4e3.tar.gz
iced-3702b109977a249247a0f1be40e57bec2cbaa4e3.tar.bz2
iced-3702b109977a249247a0f1be40e57bec2cbaa4e3.zip
Merge pull request #111 from Maldela/svg
Svg and icon support
Diffstat (limited to 'examples/svg.rs')
-rw-r--r--examples/svg.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/svg.rs b/examples/svg.rs
new file mode 100644
index 00000000..cdf238f0
--- /dev/null
+++ b/examples/svg.rs
@@ -0,0 +1,54 @@
+use iced::{Container, Element, Length, Sandbox, Settings};
+
+pub fn main() {
+ Tiger::run(Settings::default())
+}
+
+#[derive(Default)]
+struct Tiger;
+
+impl Sandbox for Tiger {
+ type Message = ();
+
+ fn new() -> Self {
+ Self::default()
+ }
+
+ fn title(&self) -> String {
+ String::from("SVG - Iced")
+ }
+
+ fn update(&mut self, _message: ()) {}
+
+ fn view(&mut self) -> Element<()> {
+ #[cfg(feature = "svg")]
+ let content = {
+ use iced::{Column, Svg};
+
+ Column::new()
+ .width(Length::Shrink)
+ .padding(20)
+ .push(Svg::new(format!(
+ "{}/examples/resources/tiger.svg",
+ env!("CARGO_MANIFEST_DIR")
+ )))
+ };
+
+ #[cfg(not(feature = "svg"))]
+ let content = {
+ use iced::{HorizontalAlignment, Text};
+
+ Text::new("You need to enable the `svg` feature!")
+ .width(Length::Shrink)
+ .horizontal_alignment(HorizontalAlignment::Center)
+ .size(30)
+ };
+
+ Container::new(content)
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .center_x()
+ .center_y()
+ .into()
+ }
+}