Added more default fonts, and fixed issue with font selector at different GUI scales

This commit is contained in:
Yousef Khadadeh 2025-11-15 14:05:05 +03:00
parent e451e8b181
commit 5e8016b504
19 changed files with 438 additions and 21 deletions

View file

@ -140,13 +140,13 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
entryColor = io.theme->backColor1;
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(25)},
.padding = {.left = 2, .right = 2},
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}
},
.backgroundColor = convert_vec4<Clay_Color>(entryColor)
}) {
gui->text_paragraph("font name", std::move(p), std::numeric_limits<float>::max());
gui->text_paragraph("font name", std::move(p), 10000.0f); // Setting width to numeric_limits::max will lead to multiplying it by any number greater than 1 to = infinity, which will cause issues
if(io.mouse.leftClick && Clay_Hovered()) {
*fontName = sortedFontList[i];

View file

@ -3,6 +3,7 @@
#include "../../RichText/TextBox.hpp"
#include <limits>
#include <modules/skparagraph/include/TextStyle.h>
#include "../../FontData.hpp"
namespace GUIStuff {
@ -17,14 +18,13 @@ template <typename T> class TextBox : public Element {
data = newData;
fromStr = newFromStr;
toStr = newToStr;
singleLine = newSingleLine;
force_update_textbox(io, false);
textbox->set_width(singleLine ? std::numeric_limits<float>::max() : bb.width());
textbox->set_width(std::numeric_limits<float>::max());
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 2)), .height = singleLine ? CLAY_SIZING_FIXED(static_cast<float>(io.fontSize * 1.25f)) : CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 1.25f))}
.sizing = {.width = CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 2)), .height = CLAY_SIZING_FIXED(static_cast<float>(io.fontSize * 1.25f))}
},
.custom = { .customData = this }
}) {
@ -71,7 +71,9 @@ template <typename T> class TextBox : public Element {
canvas->clipRect(SkRect::MakeXYWH(bb.min.x(), bb.min.y(), bb.width(), bb.height()));
canvas->translate(bb.min.x() + 2.0f, bb.min.y());
float yOffset = bb.height() * 0.5f;
yOffset -= textbox->get_height() * 0.5f;
canvas->translate(bb.min.x() + 2.0f, bb.min.y() + yOffset);
RichText::TextBox::PaintOpts paintOpts;
if(selection.selected)
@ -79,9 +81,7 @@ template <typename T> class TextBox : public Element {
paintOpts.cursorColor = {io.theme->fillColor1.fR, io.theme->fillColor1.fG, io.theme->fillColor1.fB};
skia::textlayout::TextStyle tStyle;
std::vector<SkString> families;
families.emplace_back("Roboto");
tStyle.setFontFamilies(families);
tStyle.setFontFamilies(get_default_font_families());
tStyle.setFontSize(io.fontSize);
tStyle.setForegroundPaint(SkPaint{io.theme->frontColor1});
textbox->set_initial_text_style(tStyle);
@ -99,7 +99,7 @@ template <typename T> class TextBox : public Element {
textbox = std::make_shared<RichText::TextBox>();
textbox->set_font_collection(io.fontCollection);
textbox->set_allow_newlines(!singleLine);
textbox->set_allow_newlines(false);
cur = std::make_shared<RichText::TextBox::Cursor>();
@ -120,8 +120,6 @@ template <typename T> class TextBox : public Element {
T* data = nullptr;
T oldData;
bool singleLine = true;
std::function<std::optional<T>(const std::string&)> fromStr;
std::function<std::string(const T&)> toStr;

View file

@ -24,6 +24,7 @@
#include <modules/skparagraph/include/TextStyle.h>
#include <modules/skunicode/include/SkUnicode_icu.h>
#include <Helpers/Random.hpp>
#include "../FontData.hpp"
namespace GUIStuff {
@ -43,7 +44,7 @@ Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_Te
pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft);
skia::textlayout::TextStyle tStyle;
tStyle.setFontSize(config->fontSize);
tStyle.setFontFamilies({SkString{"Roboto"}});
tStyle.setFontFamilies(get_default_font_families());
pStyle.setTextStyle(tStyle);
skia::textlayout::ParagraphBuilderImpl a(pStyle, window->io->fontCollection, SkUnicodes::ICU::Make());
@ -116,7 +117,7 @@ void GUIManager::draw(SkCanvas* canvas) {
pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft);
skia::textlayout::TextStyle tStyle;
tStyle.setFontSize(config->fontSize);
tStyle.setFontFamilies({SkString{"Roboto"}});
tStyle.setFontFamilies(get_default_font_families());
tStyle.setColor(convert_vec4<SkColor4f>(config->textColor).toSkColor());
pStyle.setTextStyle(tStyle);

View file

@ -19,7 +19,6 @@
using namespace Eigen;
namespace GUIStuff {
class GUIManager {