egui/src/style.rs

104 lines
3.2 KiB
Rust
Raw Normal View History

2018-12-26 16:01:46 +00:00
use crate::{math::*, types::*};
2018-12-26 13:38:46 +00:00
/// TODO: a Style struct which defines colors etc
2018-12-26 16:01:46 +00:00
fn translate_cmd(out_commands: &mut Vec<PaintCmd>, cmd: GuiCmd) {
2018-12-26 13:38:46 +00:00
match cmd {
2018-12-26 16:32:58 +00:00
GuiCmd::PaintCommands(mut commands) => out_commands.append(&mut commands),
2018-12-26 13:38:46 +00:00
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 16:32:58 +00:00
"#666666ff".to_string()
2018-12-26 13:38:46 +00:00
} else {
2018-12-26 16:32:58 +00:00
"#444444ff".to_string()
2018-12-26 13:38:46 +00:00
};
2018-12-26 16:32:58 +00:00
out_commands.push(PaintCmd::Rect {
2018-12-26 13:38:46 +00:00
corner_radius: 5.0,
2018-12-26 16:32:58 +00:00
fill_style: Some(fill_style),
outline: None,
2018-12-26 13:38:46 +00:00
pos: rect.pos,
size: rect.size,
2018-12-26 16:01:46 +00:00
});
2018-12-26 13:38:46 +00:00
}
},
2018-12-26 16:01:46 +00:00
GuiCmd::Slider {
interact,
label,
max,
min,
rect,
value,
} => {
let thin_rect = Rect::from_center_size(rect.center(), vec2(rect.size.x, 8.0));
let marker_center_x = remap_clamp(value, min, max, rect.min().x, rect.max().x);
let marker_rect =
Rect::from_center_size(vec2(marker_center_x, rect.center().y), vec2(16.0, 16.0));
let marker_fill_style = if interact.active {
"#888888ff".to_string()
} else if interact.hovered {
2018-12-26 16:32:58 +00:00
"#666666ff".to_string()
2018-12-26 16:01:46 +00:00
} else {
2018-12-26 16:32:58 +00:00
"#444444ff".to_string()
2018-12-26 16:01:46 +00:00
};
2018-12-26 16:32:58 +00:00
out_commands.push(PaintCmd::Rect {
2018-12-26 16:01:46 +00:00
corner_radius: 2.0,
2018-12-26 16:32:58 +00:00
fill_style: Some("#222222ff".to_string()),
outline: None,
2018-12-26 16:01:46 +00:00
pos: thin_rect.pos,
size: thin_rect.size,
});
2018-12-26 16:32:58 +00:00
out_commands.push(PaintCmd::Rect {
2018-12-26 16:01:46 +00:00
corner_radius: 3.0,
2018-12-26 16:32:58 +00:00
fill_style: Some(marker_fill_style),
outline: None,
2018-12-26 16:01:46 +00:00
pos: marker_rect.pos,
size: marker_rect.size,
});
out_commands.push(PaintCmd::Text {
fill_style: "#ffffffbb".to_string(),
font: "14px Palatino".to_string(),
2018-12-26 16:32:58 +00:00
pos: rect.min(),
2018-12-26 16:01:46 +00:00
text: format!("{}: {:.3}", label, value),
2018-12-26 16:32:58 +00:00
text_align: TextAlign::Start,
});
}
GuiCmd::Text {
pos,
text,
text_align,
style,
} => {
let fill_style = match style {
TextStyle::Button => "#ffffffbb".to_string(),
TextStyle::Label => "#ffffffbb".to_string(),
};
out_commands.push(PaintCmd::Text {
fill_style,
font: "14px Palatino".to_string(),
pos,
text,
text_align,
2018-12-26 16:01:46 +00:00
});
2018-12-26 13:38:46 +00:00
}
}
}
2018-12-26 14:28:38 +00:00
pub fn into_paint_commands(gui_commands: &[GuiCmd]) -> Vec<PaintCmd> {
2018-12-26 16:01:46 +00:00
let mut paint_commands = vec![];
for gui_cmd in gui_commands {
translate_cmd(&mut paint_commands, gui_cmd.clone())
}
paint_commands
2018-12-26 13:38:46 +00:00
}