UI is now working the same as last time but using GUECS.

This commit is contained in:
Zed A. Shaw 2025-04-22 11:54:35 -04:00
parent 70c2ce7d51
commit 8f3a3c10c2
5 changed files with 41 additions and 18 deletions

View file

@ -206,9 +206,10 @@ namespace guecs {
});
$world.query<lel::Cell, Meter>([&](auto ent, auto& cell, const auto &meter) {
float level = std::clamp(meter.percent, 0.0f, 1.0f) * float(cell.w);
int pad = meter.bar.padding * 2;
float level = std::clamp(meter.percent, 0.0f, 1.0f) * float(cell.w - pad);
// ZED: this 6 is a border width, make it a thing
meter.bar.shape->setSize({std::max(level, 0.0f), float(cell.h - 6)});
meter.bar.shape->setSize({std::max(level, 0.0f), float(cell.h - pad)});
render_helper(window, ent, true, meter.bar.shape);
});
@ -264,7 +265,11 @@ namespace guecs {
void UI::show_sprite(string region, string sprite_name) {
auto ent = entity(region);
if(!has<Sprite>(ent)) {
if(has<Sprite>(ent)) {
auto& to_show = get<Sprite>(ent);
auto sprite_texture = textures::get(sprite_name);
to_show.sprite->setTexture(*sprite_texture.texture);
} else {
Sprite to_show{sprite_name};
auto& cell = cell_for(ent);
to_show.init(cell);