GUECS now has a click_on function so you can programatically click on buttons for testing.

master
Zed A. Shaw 3 days ago
parent 78ba83e916
commit 70d27b9a95
  1. 29
      guecs.cpp
  2. 2
      guecs.hpp

@ -259,7 +259,7 @@ namespace guecs {
bool UI::mouse(float x, float y, bool hover) {
int action_count = 0;
$world.query<lel::Cell, Clickable>([&](auto ent, auto& cell, auto &clicked) {
$world.query<lel::Cell>([&](auto ent, auto& cell) {
if((x >= cell.x && x <= cell.x + cell.w) &&
(y >= cell.y && y <= cell.y + cell.h))
{
@ -275,11 +275,7 @@ namespace guecs {
if(hover) return;
if(auto action_data = get_if<ActionData>(ent)) {
clicked.action(ent, action_data->data);
} else {
clicked.action(ent, {});
}
click_on(ent);
action_count++;
} else {
@ -317,6 +313,27 @@ namespace guecs {
}
}
void UI::click_on(const std::string& name, bool required) {
auto ent = entity(name);
if(required) {
dbc::check(has<Clickable>(ent),
fmt::format("click_on required '{}' to exist but it doesn't", name));
}
click_on(ent);
}
void UI::click_on(DinkyECS::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::show_label(string region, wstring content) {
auto ent = entity(region);

@ -155,6 +155,8 @@ namespace guecs {
void init();
void render(sf::RenderWindow& window);
bool mouse(float x, float y, bool hover);
void click_on(const std::string& name, bool required=false);
void click_on(DinkyECS::Entity slot_id);
void debug_layout(sf::RenderWindow& window);
template <typename Comp>

Loading…
Cancel
Save