add markdown dialect (WIP) & add strikethrough and underline font styles

This commit is contained in:
MihailRis
2024-12-06 17:35:03 +03:00
parent 605d7e7897
commit 80e809f97f
15 changed files with 296 additions and 58 deletions
+21 -1
View File
@@ -13,6 +13,7 @@
#include "util/stringutil.hpp"
#include "window/Events.hpp"
#include "window/Window.hpp"
#include "../markdown.hpp"
using namespace gui;
@@ -191,7 +192,18 @@ void TextBox::drawBackground(const DrawContext& pctx, const Assets&) {
void TextBox::refreshLabel() {
label->setColor(textColor * glm::vec4(input.empty() ? 0.5f : 1.0f));
label->setText(input.empty() && !hint.empty() ? hint : getText());
const auto& displayText = input.empty() && !hint.empty() ? hint : getText();
if (markdown) {
auto [processedText, styles] = markdown::process(displayText, !focused);
label->setText(std::move(processedText));
label->setStyles(std::move(styles));
} else {
label->setText(displayText);
if (syntax.empty()) {
label->setStyles(nullptr);
}
}
if (showLineNumbers) {
if (lineNumbersLabel->getLinesNumber() != label->getLinesNumber()) {
@@ -846,3 +858,11 @@ void TextBox::setSyntax(const std::string& lang) {
refreshSyntax();
}
}
void TextBox::setMarkdown(bool flag) {
markdown = flag;
}
bool TextBox::isMarkdown() const {
return markdown;
}