nes_yew/components/
sprite.rs1use std::borrow::Cow;
2use strum::{EnumIter, IntoEnumIterator};
3use yew::prelude::*;
4
5#[derive(Properties, PartialEq)]
6pub struct SpriteProps {
7 pub sprite: SpriteKind,
8 pub class: Option<Cow<'static, str>>,
9 pub style: Option<AttrValue>,
10}
11
12#[derive(Copy, Clone, PartialEq, EnumIter)]
13pub enum SpriteKind {
14 Octocat,
15 Mario,
16 Ash,
17 Pokeball,
18 Bulbasaur,
19 Charmander,
20 Squirtle,
21 Smartphone,
22 Phone,
23 Kirby,
24 Bcrikko,
25}
26
27impl SpriteKind {
28 pub fn iter() -> impl Iterator<Item = Self> {
29 <Self as IntoEnumIterator>::iter()
30 }
31
32 pub fn to_str(&self) -> &'static str {
33 match self {
34 SpriteKind::Octocat => "nes-octocat",
35 SpriteKind::Mario => "nes-mario",
36 SpriteKind::Ash => "nes-ash",
37 SpriteKind::Pokeball => "nes-pokeball",
38 SpriteKind::Bulbasaur => "nes-bulbasaur",
39 SpriteKind::Charmander => "nes-charmander",
40 SpriteKind::Squirtle => "nes-squirtle",
41 SpriteKind::Smartphone => "nes-smartphone",
42 SpriteKind::Phone => "nes-phone",
43 SpriteKind::Kirby => "nes-kirby",
44 SpriteKind::Bcrikko => "nes-bcrikko",
45 }
46 }
47}
48
49#[function_component(Sprite)]
50pub fn sprite(
51 SpriteProps {
52 sprite,
53 class,
54 style,
55 }: &SpriteProps,
56) -> Html {
57 html! {
58 <i
59 class={classes!(class, sprite.to_str())}
60 style={style.clone()}
61 />
62 }
63}