multiline textbox mode

This commit is contained in:
MihailRis
2024-02-26 15:12:02 +03:00
parent 925ef426de
commit 256808630b
11 changed files with 260 additions and 51 deletions
+40 -1
View File
@@ -31,7 +31,12 @@ namespace gui {
bool multiline = false;
// runtime values
/// @brief Text Y offset relative to label position
/// (last calculated alignment)
int textYOffset = 0;
/// @brief Text line height multiplied by line interval
int totalLineHeight = 1;
public:
Label(std::string text, std::string fontName="normal");
@@ -43,15 +48,39 @@ namespace gui {
virtual void setFontName(std::string name);
virtual const std::string& getFontName() const;
/// @brief Set text vertical alignment (default value: center)
/// @param align Align::top / Align::center / Align::bottom
virtual void setVerticalAlign(Align align);
virtual Align getVerticalAlign() const;
/// @brief Get line height multiplier used for multiline labels
/// (default value: 1.5)
virtual float getLineInterval() const;
/// @brief Set line height multiplier used for multiline labels
virtual void setLineInterval(float interval);
/// @brief Get Y position of the text relative to label position
/// @return Y offset
virtual int getTextYOffset() const;
/// @brief Get Y position of the line relative to label position
/// @param line target line index
/// @return Y offset
virtual int getLineYOffset(uint line) const;
/// @brief Get position of line start in the text
/// @param line target line index
/// @return position in the text [0..length]
virtual size_t getTextLineOffset(uint line) const;
/// @brief Get line index by its Y offset relative to label position
/// @param offset target Y offset
/// @return line index [0..+]
virtual uint getLineByYOffset(int offset) const;
virtual uint getLineByTextIndex(size_t index) const;
virtual uint getLinesNumber() const;
virtual void draw(const GfxContext* pctx, Assets* assets) override;
virtual void textSupplier(wstringsupplier supplier);
@@ -133,8 +162,11 @@ namespace gui {
bool valid = true;
/// @brief text input pointer, value may be greather than text length
uint caret = 0;
/// @brief actual local (line) position of the caret on vertical move
uint maxLocalCaret = 0;
uint textOffset = 0;
int textInitX;
/// @brief last time of the caret was moved (used for blink animation)
double caretLastMove = 0.0;
Font* font = nullptr;
@@ -146,13 +178,20 @@ namespace gui {
size_t normalizeIndex(int index);
int calcIndexAt(int x) const;
int calcIndexAt(int x, int y) const;
void paste(const std::wstring& text);
void setTextOffset(uint x);
void erase(size_t start, size_t length);
bool eraseSelected();
void resetSelection();
void extendSelection(int index);
size_t getLineLength(uint line) const;
/// @brief Get total length of the selection
size_t getSelectionLength() const;
/// @brief Set maxLocalCaret to local (line) caret position
void resetMaxLocalCaret();
public:
TextBox(std::wstring placeholder,
glm::vec4 padding=glm::vec4(4.0f));