I have a problem with Window widgets in SFGUI. What I try to achieve is that if the user right_clicks on an inventory item, a popup appears with a description of the item. I implement this by holding an sfg::Window::Ptr and adding the text to the label in the window. If the window is "opened" (actually happens only the first time), the window is revealed with Show(true). The onCloseButton is bound to a lambda that just hides the window.
The problem is that the window becomes unresponsive in the following scenarios:
- open popup
- drag it around
- "close" the popup (it is actually just hidden). At this point this works.
- "open" it again. Now the correct text appears, but the window will not respond to events anymore. It will not drag or close.
or
- open popup. The correct text appears
- right click on another inventory item. Now the label changes into the expected text, but the window becomes unresponsive.
The label is found with no problem, the text changes as expected. Only the window can not be dragged or hidden anymore. Here the code, it's small enough.
button->GetSignal (sfg::Widget::OnRightClick).Connect ([this, table, index = i * 10 + j] (){show_description (table, index); }); // the inventory is a sfg::Table of sfg::Togglebutton, the index indicates which button is right-clicked
// ...
void Character_sheet::show_description (sfg::Table::Ptr table, size_t index)
{
// code to determine the description text left out, goes into desc
auto desc = item_data->description;
if (index < inv->bag.contents.size ()) // skip if there is no actual item associated with this inventory slot
{
if (m_description_popup)
{
m_description_popup->Show (true);
}
else
{
m_description_popup = sfg::Window::Create (sfg::Window::Style::TOPLEVEL | sfg::Window::Style::CLOSE);
m_description_popup->GetSignal (sfg::Window::OnCloseButton).Connect ([this] (){m_description_popup->Show (false); });
auto text = sfg::Label::Create ();
text->SetRequisition({ 200.0f,0.0f });
text->SetLineWrap (true);
text->SetId ("item_description");
m_description_popup->Add (text);
m_desktop->Add (m_description_popup);
}
auto text = find_widget ("item_description");
text->SetText (desc);
}
}
template <typename T = sfg::Label>
std::shared_ptr<T> find_widget (const std::string& id)
{
return std::dynamic_pointer_cast<T>(sfg::Widget::GetWidgetById (id));
}