Removed hover on guecs::UI::mouse and now use a generic 16 bit modifier bitset. Also finally fixed Clickable so it just a simple callback with only the modifiers.

This commit is contained in:
Zed A. Shaw 2025-08-14 12:35:25 -04:00
parent 4c019048d0
commit 5d0d8b16fc
5 changed files with 29 additions and 41 deletions

View file

@ -149,9 +149,9 @@ namespace guecs {
});
}
bool UI::mouse(float x, float y, bool hover) {
bool UI::mouse(float x, float y, Modifiers mods) {
int action_count = 0;
// BUG: Is Parser::hit useful?
bool hover = mods.test(size_t(ModBit::hover));
query<lel::Cell>([&](auto ent, auto& cell) {
if((x >= cell.x && x <= cell.x + cell.w) &&
@ -169,11 +169,11 @@ namespace guecs {
if(hover) return;
click_on(ent);
click_on(ent, mods);
action_count++;
} else {
do_if<Effect>(ent, [hover](auto& effect) {
do_if<Effect>(ent, [](auto& effect) {
effect.stop();
});
@ -220,25 +220,10 @@ namespace guecs {
}
}
void UI::click_on(const string& name, bool required) {
auto ent = entity(name);
if(required) {
assert(has<Clickable>(ent) &&
"click_on required '{}' to exist but it doesn't");
}
click_on(ent);
}
void UI::click_on(Entity ent) {
if(auto clicked = get_if<Clickable>(ent)) {
if(auto action_data = get_if<ActionData>(ent)) {
clicked->action(ent, action_data->data);
} else {
clicked->action(ent, {});
}
}
void UI::click_on(Entity gui_id, Modifiers mods) {
if(auto to_click = get_if<Clickable>(gui_id)) {
to_click->action(mods);
};
}
wstring to_wstring(const string& str) {