useful functions for control text manipulation

This commit is contained in:
2025-03-16 15:57:25 -05:00
parent 735b324ffa
commit 8c48cbab4f
3 changed files with 19 additions and 5 deletions

View File

@@ -20,6 +20,7 @@
#include "tools/cursors.hpp"
#include "replay.hpp"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "winutil.hpp"
// Hyperlink forward declaration
@@ -39,8 +40,19 @@ std::string cControl::generateRandomString() {
void cControl::setText(std::string l){
lbl = l;
// TODO: calling recalcRect() here has major unwanted side effects
// recalcRect();
// NOTE: calling recalcRect() here seems like a good idea but it has too many unwanted side-effects.
// It's better to call it manually when changing clickable text.
}
void cControl::replaceText(std::string find, std::string replace) {
std::string text = getText();
boost::replace_first(text, find, replace);
setText(text);
}
void cControl::appendText(std::string l) {
std::string text = getText();
setText(text + l);
}
std::string cControl::getText() const {

View File

@@ -259,6 +259,10 @@ public:
/// Set the control's text.
/// @param l The new text.
virtual void setText(std::string l);
/// Replace the first occurrence of the given string in this control's text
void replaceText(std::string find, std::string replace);
/// Append a string to this control's text
void appendText(std::string l);
/// Fetch the control's text.
/// @return The control's current text.
virtual std::string getText() const;