Added text style modifiers

This commit is contained in:
Yousef Khadadeh 2025-11-04 10:58:26 +03:00
parent 640d4673ad
commit b43fedaaac
11 changed files with 385 additions and 34 deletions

View file

@ -38,7 +38,7 @@ void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std:
.cornerRadius = CLAY_CORNER_RADIUS(4),
.border = {
.color = convert_vec4<Clay_Color>(borderColor),
.width = CLAY_BORDER_OUTSIDE(1)
.width = CLAY_BORDER_OUTSIDE(2)
}
}) {
CLAY({.layout = {

View file

@ -59,13 +59,23 @@ 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(), bb.min.y());
canvas->translate(bb.min.x() + 2.0f, bb.min.y());
RichTextBox::PaintOpts paintOpts;
if(selection.selected)
paintOpts.cursor = *cur;
paintOpts.cursorColor = {io.theme->fillColor1.fR, io.theme->fillColor1.fG, io.theme->fillColor1.fB};
auto fontFamiliesMod = std::make_shared<FontFamiliesTextStyleModifier>();
fontFamiliesMod->families.emplace_back("Roboto");
textbox->set_initial_text_style_modifier(fontFamiliesMod);
auto fontSizeMod = std::make_shared<SizeTextStyleModifier>();
fontSizeMod->size = io.fontSize;
textbox->set_initial_text_style_modifier(fontSizeMod);
auto fontColorMod = std::make_shared<ColorTextStyleModifier>();
fontColorMod->color = convert_vec4<Vector4f>(io.theme->frontColor1);
textbox->set_initial_text_style_modifier(fontColorMod);
textbox->paint(canvas, paintOpts);
canvas->restore();
@ -80,6 +90,7 @@ template <typename T> class TextBox : public Element {
textbox = std::make_shared<RichTextBox>();
textbox->set_font_collection(io.fontCollection);
textbox->set_allow_newlines(!singleLine);
cur = std::make_shared<RichTextBox::Cursor>();
if(data) {

View file

@ -209,6 +209,16 @@ void GUIManager::draw(SkCanvas* canvas) {
break;
}
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
Clay_ClipRenderData* clip = &command->renderData.clip;
if(!clip->horizontal) {
bb.x = 0.0f;
bb.width = std::numeric_limits<float>::max();
}
if(!clip->vertical) {
bb.y = 0.0f;
bb.height = std::numeric_limits<float>::max();
}
canvas->save();
SkRect clipRect = SkRect::MakeXYWH(bb.x - 1.0f, bb.y - 1.0f, bb.width + 1.0f, bb.height + 1.0f);
canvas->clipRect(clipRect);
@ -578,6 +588,7 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
.childGap = 1,
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
.layoutDirection = CLAY_TOP_TO_BOTTOM
}
@ -727,7 +738,7 @@ void GUIManager::scroll_bar_many_entries_area(const std::string& uniqueId, float
scrollAmount = std::fabs(scrollAmount);
float entryHeight = 25.0f;
size_t startPoint = scrollAmount / entryHeight;
size_t elementsContainable = (containerHeight / entryHeight) + 1;
size_t elementsContainable = (containerHeight / entryHeight) + 2; // Displaying 2 more elements ensures that there isn't any empty space in the container
size_t endPoint = std::min(entryCount, startPoint + elementsContainable);
if(startPoint != 0) {