Showcase color filtering in existing svg example
... and remove the `svg_style` example
This commit is contained in:
parent
c0ca1807d4
commit
1220ce55bc
4 changed files with 54 additions and 106 deletions
|
|
@ -1,39 +1,76 @@
|
|||
use iced::widget::{container, svg};
|
||||
use iced::{Element, Length, Sandbox, Settings};
|
||||
use iced::theme;
|
||||
use iced::widget::{checkbox, column, container, svg};
|
||||
use iced::{color, Element, Length, Sandbox, Settings};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Tiger::run(Settings::default())
|
||||
}
|
||||
|
||||
struct Tiger;
|
||||
#[derive(Debug, Default)]
|
||||
struct Tiger {
|
||||
apply_color_filter: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Message {
|
||||
ToggleColorFilter(bool),
|
||||
}
|
||||
|
||||
impl Sandbox for Tiger {
|
||||
type Message = ();
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
Tiger
|
||||
Tiger::default()
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("SVG - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, _message: ()) {}
|
||||
fn update(&mut self, message: Self::Message) {
|
||||
match message {
|
||||
Message::ToggleColorFilter(apply_color_filter) => {
|
||||
self.apply_color_filter = apply_color_filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<()> {
|
||||
let svg = svg(svg::Handle::from_path(format!(
|
||||
fn view(&self) -> Element<Self::Message> {
|
||||
let handle = svg::Handle::from_path(format!(
|
||||
"{}/resources/tiger.svg",
|
||||
env!("CARGO_MANIFEST_DIR")
|
||||
)))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill);
|
||||
));
|
||||
|
||||
container(svg)
|
||||
let svg = svg(handle).width(Length::Fill).height(Length::Fill).style(
|
||||
if self.apply_color_filter {
|
||||
theme::Svg::custom_fn(|_theme| svg::Appearance {
|
||||
color: Some(color!(0x0000ff)),
|
||||
})
|
||||
} else {
|
||||
theme::Svg::Default
|
||||
},
|
||||
);
|
||||
|
||||
let apply_color_filter = checkbox(
|
||||
"Apply a color filter",
|
||||
self.apply_color_filter,
|
||||
Message::ToggleColorFilter,
|
||||
);
|
||||
|
||||
container(
|
||||
column![
|
||||
svg,
|
||||
container(apply_color_filter).width(Length::Fill).center_x()
|
||||
]
|
||||
.spacing(20)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.padding(20)
|
||||
.center_x()
|
||||
.center_y()
|
||||
.into()
|
||||
.height(Length::Fill),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.padding(20)
|
||||
.center_x()
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
[package]
|
||||
name = "svg_style"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
iced = { path = "../..", features = ["svg"] }
|
||||
iced_style = { path = "../../style" }
|
||||
|
|
@ -1 +0,0 @@
|
|||
<svg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'><path color='#bebebe' d='M0 0h16v16H0z' fill='gray' fill-opacity='.01'/><path d='m7.94 1.94 6.062 6.063-6.062 6.063c-1.438 1.437-2.688-.063-1.625-1.125l4.937-4.938-4.937-4.937C5.502 2.253 6.752.753 7.94 1.94z' fill='#232323'/></svg>
|
||||
|
Before Width: | Height: | Size: 293 B |
|
|
@ -1,78 +0,0 @@
|
|||
use iced::widget::{container, svg};
|
||||
use iced::{Color, Element, Length, Sandbox, Settings};
|
||||
use iced_style::svg::Appearance;
|
||||
use iced_style::theme::{self, Theme};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
SvgStyleExample::run(Settings::default())
|
||||
}
|
||||
|
||||
struct SvgStyleExample;
|
||||
|
||||
impl Sandbox for SvgStyleExample {
|
||||
type Message = ();
|
||||
|
||||
fn new() -> Self {
|
||||
SvgStyleExample
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
Theme::Light
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("SVG - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, _message: ()) {}
|
||||
|
||||
fn view(&self) -> Element<()> {
|
||||
let svg1: Element<_> = svg(svg::Handle::from_path(format!(
|
||||
"{}/resources/go-next-symbolic.svg",
|
||||
env!("CARGO_MANIFEST_DIR")
|
||||
)))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into();
|
||||
|
||||
let svg2: Element<_> = svg(svg::Handle::from_path(format!(
|
||||
"{}/resources/go-next-symbolic.svg",
|
||||
env!("CARGO_MANIFEST_DIR")
|
||||
)))
|
||||
.style(theme::Svg::custom_fn(|_theme| Appearance {
|
||||
color: Some(Color {
|
||||
r: 0.0,
|
||||
g: 0.28627452,
|
||||
b: 0.42745098,
|
||||
a: 1.0,
|
||||
}),
|
||||
}))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into();
|
||||
|
||||
let svg3: Element<_> = svg(svg::Handle::from_path(format!(
|
||||
"{}/resources/go-next-symbolic.svg",
|
||||
env!("CARGO_MANIFEST_DIR")
|
||||
)))
|
||||
.style(theme::Svg::custom_fn(|_theme| Appearance {
|
||||
color: Some(Color {
|
||||
r: 0.5803922,
|
||||
g: 0.92156863,
|
||||
b: 0.92156863,
|
||||
a: 1.0,
|
||||
}),
|
||||
}))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into();
|
||||
|
||||
container(iced::widget::row!(svg1, svg2, svg3))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.padding(20)
|
||||
.center_x()
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue