Implement vertical meters.
This commit is contained in:
parent
ad116b5515
commit
48b672eec4
3 changed files with 26 additions and 4 deletions
|
|
@ -15,13 +15,23 @@ struct TestMeters {
|
|||
|
||||
void init() {
|
||||
$gui.position(0, 0, 1280, 720);
|
||||
$gui.layout("[meter1][=meter2][meter3][meter4]");
|
||||
$gui.layout(
|
||||
"[*%(300,100)meter1|_|_|*%(100,400)vert1|*%(100,400)vert2|*%(100,400)vert3]"
|
||||
"[*%(300,100)meter2|_|_|_|_|_]"
|
||||
"[*%(300,100)meter3|_|_|_|_|_]"
|
||||
"[*%(300,100)meter4|_|_|_|_|_]");
|
||||
|
||||
for(auto& [name, cell] : $gui.cells()) {
|
||||
auto gui_id = $gui.entity(name);
|
||||
|
||||
$gui.set<guecs::Rectangle>(gui_id, {guecs::THEME.PADDING, {120, 25, 25, 255}});
|
||||
|
||||
if(name.starts_with("meter")) {
|
||||
$gui.set<guecs::Meter>(gui_id, {1.0f, guecs::THEME.DARK_LIGHT, guecs::THEME.PADDING});
|
||||
} else {
|
||||
$gui.set<guecs::Meter>(gui_id, {1.0f, guecs::THEME.DARK_LIGHT, guecs::THEME.PADDING, true});
|
||||
}
|
||||
|
||||
$gui.set<guecs::Effect>(gui_id, {});
|
||||
$gui.set<guecs::Text>(gui_id, {guecs::to_wstring(name)});
|
||||
$gui.set<guecs::Clickable>(gui_id, {
|
||||
|
|
|
|||
|
|
@ -70,9 +70,12 @@ namespace guecs {
|
|||
float percent = 1.0f;
|
||||
sf::Color color = THEME.BG_COLOR_DARK;
|
||||
int padding = THEME.PADDING;
|
||||
bool vertical = false;
|
||||
Rectangle bar{padding, color};
|
||||
// this is set automatically if a Rectangle is configured for the cell
|
||||
Rectangle backing_rect{padding, color};
|
||||
size_t $cell_x = 0;
|
||||
size_t $cell_y = 0;
|
||||
size_t $cell_w = 0;
|
||||
size_t $cell_h = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ namespace guecs {
|
|||
}
|
||||
|
||||
void Meter::init(lel::Cell& cell) {
|
||||
$cell_x = cell.x;
|
||||
$cell_y = cell.y;
|
||||
$cell_w = cell.w;
|
||||
$cell_h = cell.h;
|
||||
bar.init(cell);
|
||||
|
|
@ -125,9 +127,16 @@ namespace guecs {
|
|||
|
||||
void Meter::update_percent(float pct) {
|
||||
percent = pct;
|
||||
if(vertical) {
|
||||
float level = std::clamp(percent, 0.0f, 1.0f) * float($cell_h);
|
||||
sf::Vector2f size{float($cell_w) - padding * 2, std::max(level, 0.0f) - padding};
|
||||
bar.shape->setSize(size);
|
||||
bar.shape->setPosition({float($cell_x + padding), float($cell_y) + (float($cell_h) - size.y)});
|
||||
} else {
|
||||
float level = std::clamp(percent, 0.0f, 1.0f) * float($cell_w);
|
||||
bar.shape->setSize({std::max(level, 0.0f) - padding * 2, float($cell_h) - padding * 2});
|
||||
}
|
||||
}
|
||||
|
||||
void Sound::play(bool hover) {
|
||||
if(!hover) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue