yew_google_material/
lib.rs

1//! # Yew Google Material
2//! 
3//! `yew-google-material` is a very simple crate to use some of google materials and `https://fonts.google.com/`
4//! 
5//! Unfortunately a lot of crates with materials, icons for yew framework are depricated and use depricated javascript code.
6//!  
7//! Here I use only Rust code to add some design features for yew. 
8//! 
9//! Now only buttons, text fields and icons are available.
10//! Buttons and text fields are not the same as one in google material web, but very similar to them. 
11//! 
12//! See more information in `GButton`, `GIcon` and `GTextInput` modules below.
13
14use yew::AttrValue;
15
16pub mod icons;
17pub mod input_text;
18pub mod buttons;
19
20#[derive(Default, Debug, PartialEq, Clone)]
21pub enum GIconStyle {
22    #[default]
23    Outlined,
24    Rounded,
25    Sharp,
26}
27
28#[derive(Default, PartialEq)]
29pub enum GInputStyle {
30    #[default]
31    Outlined,
32    Filled,
33}
34
35#[derive(PartialEq, Default, Clone)]
36pub enum GButtonStyle {
37    Elevated,
38    #[default]
39    Filled, 
40    Outlined,
41    Text,
42}
43
44pub mod prelude {
45    pub use crate::icons::GIcon;
46    pub use crate::GIconStyle;
47    pub use crate::input_text::{GTextInput, GInputEvent};
48    pub use crate::GInputStyle;
49    pub use crate::buttons::{GButton, DependsOn};
50    pub use crate::GButtonStyle;
51}
52
53fn parse_number_and_unit(input: AttrValue) -> (f64, String) {
54    let input = input.as_str();
55    let pos = input
56        .find(|c: char| !c.is_digit(10) && c != '.' && c != '+' && c != '-');
57
58    match pos {
59        Some(pos) => {
60            let (number_str, unit) = input.split_at(pos);
61            let number = match number_str.parse::<f64>() {
62                Ok(number) => number,
63                Err(_) => {
64                    return (3.5, "em".to_string());
65                },
66            };
67            (number, unit.to_string())
68        },
69        None => {
70            let number = match input.parse::<f64>() {
71                Ok(number) => number,
72                Err(_) => {
73                    return (3.5, "em".to_string());
74                },
75            };
76            (number, "".to_string())
77        }, 
78    }
79}