Added SelectionChanged signal to TextBox (#97)
parent
1a77e0ec60
commit
fef92953c4
|
@ -1,6 +1,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
|
||||
|
||||
|
|
|
@ -568,7 +568,8 @@ namespace tgui
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
|
||||
SignalString onTextChange = {"TextChanged"}; ///< The text was changed. Optional parameter: new text
|
||||
SignalString onTextChange = {"TextChanged"}; ///< The text was changed. Optional parameter: new text
|
||||
Signal onSelectionChange = {"SelectionChanged"}; ///< Selected text changed
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -593,6 +594,7 @@ namespace tgui
|
|||
// Information about the selection
|
||||
sf::Vector2<std::size_t> m_selStart;
|
||||
sf::Vector2<std::size_t> m_selEnd;
|
||||
std::pair<sf::Vector2<std::size_t>, sf::Vector2<std::size_t>> m_lastSelection;
|
||||
|
||||
// Information about the caret
|
||||
Vector2f m_caretPosition;
|
||||
|
|
|
@ -1546,6 +1546,17 @@ namespace tgui
|
|||
}
|
||||
|
||||
recalculatePositions();
|
||||
|
||||
// Send an event when the selection changed
|
||||
if ((m_selStart != m_lastSelection.first) || (m_selEnd != m_lastSelection.second))
|
||||
{
|
||||
// Only send the event when there is an actual change, not when the caret position moved
|
||||
if ((m_selStart != m_selEnd) || (m_lastSelection.first != m_lastSelection.second))
|
||||
onSelectionChange.emit(this);
|
||||
|
||||
m_lastSelection.first = m_selStart;
|
||||
m_lastSelection.second = m_selEnd;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1710,6 +1721,8 @@ namespace tgui
|
|||
{
|
||||
if (signalName == toLower(onTextChange.getName()))
|
||||
return onTextChange;
|
||||
else if (signalName == toLower(onSelectionChange.getName()))
|
||||
return onSelectionChange;
|
||||
else
|
||||
return Widget::getSignal(std::move(signalName));
|
||||
}
|
||||
|
|
|
@ -441,6 +441,8 @@ TEST_CASE("[TextBox]")
|
|||
textBox->textEntered('C');
|
||||
REQUIRE(textBox->getText() == "ABCDEFGHIJKLMNOPQRSTUVWXYZABC");
|
||||
}
|
||||
|
||||
// TODO: TextChanged and SelectionChanged events
|
||||
}
|
||||
|
||||
testWidgetRenderer(textBox->getRenderer());
|
||||
|
|
Loading…
Reference in New Issue