Added focusable property to Widget

0.8
Bruno Van de Velde 2019-05-24 18:01:29 +02:00
parent 75948ad029
commit 49699ad521
4 changed files with 52 additions and 3 deletions

View File

@ -4,6 +4,7 @@ TGUI 0.8.6 (TBD)
- Added SelectionChanged signal to TextBox
- Added getSelectionStart and getSelectionEnd functions to TextBox
- Added mousePressed and mouseReleased to respond to different mouse buttons in custom widgets
- Added focusable property to widgets
TGUI 0.8.5 (6 April 2019)

View File

@ -497,8 +497,30 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the widget can gain focus
/// @return Can the widget be focused?
/// @brief Changes whether a widget could be focused
///
/// @param focusable Should it be possible for the widget to gain focus?
///
/// By default all widgets are focusable.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setFocusable(bool focusable);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether a widget could be focused
///
/// @return Should it be possible for the widget to gain focus?
///
/// By default all widgets are focusable.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool isFocusable() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the widget can currently gain focus
/// @return Can the widget be focused right now?
///
/// A widget has to be visible, enabled and focusable for this function to return true.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual bool canGainFocus() const;
@ -822,6 +844,9 @@ namespace tgui
// Is the widget focused?
bool m_focused = false;
// Can the widget be focused?
bool m_focusable = true;
// Keep track of the elapsed time.
sf::Time m_animationTimeElapsed;

View File

@ -716,9 +716,23 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Widget::setFocusable(bool focusable)
{
m_focusable = focusable;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Widget::isFocusable() const
{
return m_focusable;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Widget::canGainFocus() const
{
return m_enabled && m_visible;
return m_enabled && m_visible && m_focusable;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -49,6 +49,15 @@ TEST_CASE("[Widget]")
REQUIRE(widget->isEnabled());
}
SECTION("Focusable")
{
REQUIRE(widget->isFocusable());
widget->setFocusable(false);
REQUIRE(!widget->isFocusable());
widget->setFocusable(true);
REQUIRE(widget->isFocusable());
}
SECTION("Parent")
{
tgui::Panel::Ptr panel1 = tgui::Panel::create();