Fixed many issues with text paragraphs in GUI
This commit is contained in:
parent
2d039dc47b
commit
eb490906a0
13 changed files with 132 additions and 37 deletions
|
|
@ -3,7 +3,6 @@
|
|||
#include "TextStyleModifier.hpp"
|
||||
#include "cereal/archives/portable_binary.hpp"
|
||||
#include <include/core/SkFontMetrics.h>
|
||||
#include <limits>
|
||||
#include <modules/skparagraph/include/DartTypes.h>
|
||||
#include <modules/skparagraph/include/Metrics.h>
|
||||
#include <modules/skparagraph/include/Paragraph.h>
|
||||
|
|
@ -838,13 +837,36 @@ int TextBox::get_line_number_at_from_byte_text_pos(TextPosition pos) {
|
|||
return paragraphs[pos.fParagraphIndex].p->getLineNumberAt(renderPos.fTextByteIndex);
|
||||
}
|
||||
|
||||
void TextBox::set_width(float newWidth) {
|
||||
void TextBox::set_max_width(float newWidth) {
|
||||
if(width != newWidth) {
|
||||
width = std::max(newWidth, 4.0f);
|
||||
needsRebuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::set_max_height(float newMaxHeight) {
|
||||
if(maxHeight != newMaxHeight) {
|
||||
maxHeight = newMaxHeight;
|
||||
needsRebuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::set_ellipsis(bool newEllipsis) {
|
||||
if(ellipsis != newEllipsis) {
|
||||
ellipsis = newEllipsis;
|
||||
needsRebuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
float TextBox::get_width() {
|
||||
rebuild();
|
||||
float toRet = 0.0f;
|
||||
for(auto& p : paragraphs)
|
||||
toRet = std::max(toRet, p.p->getLongestLine());
|
||||
toRet += 1.0f;
|
||||
return toRet;
|
||||
}
|
||||
|
||||
float TextBox::get_height() {
|
||||
rebuild();
|
||||
return paragraphs.back().heightOffset + paragraphs.back().p->getHeight();
|
||||
|
|
@ -875,6 +897,10 @@ void TextBox::rebuild() {
|
|||
ParagraphData& pData = paragraphs[pIndex];
|
||||
skia::textlayout::ParagraphStyle pStyle = pData.pStyleData.get_paragraph_style();
|
||||
pStyle.setTextStyle(tStyle);
|
||||
if(ellipsis)
|
||||
pStyle.setEllipsis(SkString("..."));
|
||||
if(maxHeight != 0.0f)
|
||||
pStyle.setHeight(maxHeight);
|
||||
|
||||
if(!newlinesAllowed) {
|
||||
pStyle.setTextHeightBehavior(skia::textlayout::kDisableAll);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,9 @@ class TextBox {
|
|||
};
|
||||
|
||||
TextPosition move(Movement movement, TextPosition pos, std::optional<float>* previousX = nullptr, bool flipDependingOnTextDirection = false);
|
||||
void set_width(float newWidth);
|
||||
void set_max_width(float newWidth);
|
||||
void set_max_height(float newMaxHeight);
|
||||
void set_ellipsis(bool newEllipsis);
|
||||
TextPosition insert(TextPosition pos, std::string_view textToInsert, const std::optional<TextStyleModifier::ModifierMap>& inputModMap = std::nullopt);
|
||||
TextPosition remove(TextPosition p1, TextPosition p2);
|
||||
void set_font_data(const std::shared_ptr<FontData>& fD);
|
||||
|
|
@ -129,6 +131,8 @@ class TextBox {
|
|||
SELECT_ALL
|
||||
};
|
||||
|
||||
float get_width();
|
||||
|
||||
void set_initial_text_style(const skia::textlayout::TextStyle& tStyle);
|
||||
void set_initial_text_style_modifier(const std::shared_ptr<TextStyleModifier>& modifier);
|
||||
void set_text_style_modifier_between(TextPosition p1, TextPosition p2, const std::shared_ptr<TextStyleModifier>& modifier);
|
||||
|
|
@ -193,7 +197,9 @@ class TextBox {
|
|||
int get_line_number_at_from_byte_text_pos(TextPosition pos);
|
||||
|
||||
bool newlinesAllowed = true;
|
||||
float width = 0.0f;
|
||||
bool ellipsis = false;
|
||||
float width = 4.0f;
|
||||
float maxHeight = 0.0f;
|
||||
bool needsRebuild = true;
|
||||
unsigned tabWidth = 4;
|
||||
std::shared_ptr<FontData> fontData;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue