egui/src/style.rs

51 lines
1.4 KiB
Rust
Raw Normal View History

2018-12-26 13:38:46 +00:00
use crate::types::*;
/// TODO: a Style struct which defines colors etc
fn translate_cmd(cmd: GuiCmd) -> PaintCmd {
match cmd {
GuiCmd::Rect {
rect,
style,
interact,
} => match style {
RectStyle::Button => {
2018-12-26 14:28:38 +00:00
let fill_style = if interact.active {
"#888888ff".to_string()
} else if interact.hovered {
2018-12-26 13:38:46 +00:00
"#444444ff".to_string()
} else {
"#222222ff".to_string()
};
PaintCmd::RoundedRect {
corner_radius: 5.0,
fill_style,
pos: rect.pos,
size: rect.size,
}
}
},
GuiCmd::Text {
pos,
text,
text_align,
style,
} => {
let fill_style = match style {
TextStyle::Button => "#ffffffbb".to_string(),
TextStyle::Label => "#ffffffbb".to_string(),
};
PaintCmd::Text {
fill_style,
font: "14px Palatino".to_string(),
pos,
text,
text_align,
}
}
}
}
2018-12-26 14:28:38 +00:00
pub fn into_paint_commands(gui_commands: &[GuiCmd]) -> Vec<PaintCmd> {
gui_commands.iter().cloned().map(translate_cmd).collect()
2018-12-26 13:38:46 +00:00
}