1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

add help text

This commit is contained in:
Laserlicht
2024-07-29 00:54:58 +02:00
committed by GitHub
parent 2e2d8f8833
commit 6adc49b814
5 changed files with 33 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ CTextInput::CTextInput(const Rect & Pos)
pos.h = Pos.h;
pos.w = Pos.w;
addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
addUsedEvents(LCLICK | SHOW_POPUP | KEYBOARD | TEXTINPUT);
}
void CTextInput::createLabel(bool giveFocusToInput)
@@ -106,6 +106,11 @@ void CTextInput::setCallback(const TextEditedCallback & cb)
onTextEdited = cb;
}
void CTextInput::setPopupCallback(const std::function<void()> & cb)
{
callbackPopup = cb;
}
void CTextInput::setFilterFilename()
{
assert(!onTextFiltering);
@@ -122,6 +127,12 @@ std::string CTextInput::getVisibleText() const
return hasFocus() ? currentText + composedText + "_" : currentText;
}
void CTextInput::showPopupWindow(const Point & cursorPosition)
{
if(callbackPopup)
callbackPopup();
}
void CTextInput::clickPressed(const Point & cursorPosition)
{
// attempt to give focus unconditionally, even if we already have it

View File

@@ -14,6 +14,7 @@
#include "../render/EFont.h"
#include "../../lib/filesystem/ResourcePath.h"
#include "../../lib/FunctionList.h"
class CLabel;
class IImage;
@@ -58,6 +59,7 @@ class CTextInput final : public CFocusable
TextEditedCallback onTextEdited;
TextFilterCallback onTextFiltering;
CFunctionList<void()> callbackPopup;
//Filter that will block all characters not allowed in filenames
static void filenameFilter(std::string & text, const std::string & oldText);
@@ -74,6 +76,7 @@ class CTextInput final : public CFocusable
void textEdited(const std::string & enteredText) final;
void onFocusGot() final;
void onFocusLost() final;
void showPopupWindow(const Point & cursorPosition) final;
CTextInput(const Rect & Pos);
public:
@@ -89,6 +92,9 @@ public:
/// Set callback that will be called whenever player enters new text
void setCallback(const TextEditedCallback & cb);
/// Set callback when player want to open popup
void setPopupCallback(const std::function<void()> & cb);
/// Enables filtering entered text that ensures that text is valid filename (existing or not)
void setFilterFilename();
/// Enable filtering entered text that ensures that text is valid number in provided range [min, max]