-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showcase color filtering in existing
svg
example
... and remove the `svg_style` example
- Loading branch information
Showing
4 changed files
with
54 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
)); | ||
|
||
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 | ||
}, | ||
); | ||
|
||
container(svg) | ||
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() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.