Fixed color display and global log bugs

This commit is contained in:
Yousef Khadadeh 2026-04-07 19:15:58 +03:00
parent c6e2ce5293
commit f5d757a9a5
4 changed files with 51 additions and 48 deletions

View file

@ -18,7 +18,7 @@ template <typename T, typename OptT> TextBoxData<T> textbox_options_to_data(cons
} }
struct TextBoxOptions { struct TextBoxOptions {
bool updateEveryEdit = false; bool updateEveryEdit = true;
bool immutable = false; bool immutable = false;
std::function<void()> onEnter; std::function<void()> onEnter;
std::function<void()> onEdit; std::function<void()> onEdit;
@ -28,7 +28,7 @@ struct TextBoxOptions {
struct TextBoxScalarOptions { struct TextBoxScalarOptions {
int decimalPrecision = 0; int decimalPrecision = 0;
bool updateEveryEdit = false; bool updateEveryEdit = true;
bool immutable = false; bool immutable = false;
std::function<void()> onEnter; std::function<void()> onEnter;
std::function<void()> onEdit; std::function<void()> onEdit;
@ -38,7 +38,7 @@ struct TextBoxScalarOptions {
struct TextBoxScalarsOptions { struct TextBoxScalarsOptions {
int decimalPrecision = 0; int decimalPrecision = 0;
bool updateEveryEdit = false; bool updateEveryEdit = true;
bool immutable = false; bool immutable = false;
std::function<void(size_t)> onEnter; std::function<void(size_t)> onEnter;
std::function<void(size_t)> onEdit; std::function<void(size_t)> onEdit;
@ -48,7 +48,7 @@ struct TextBoxScalarsOptions {
struct TextBoxPathOptions { struct TextBoxPathOptions {
std::filesystem::file_type fileTypeRestriction; std::filesystem::file_type fileTypeRestriction;
bool updateEveryEdit = false; bool updateEveryEdit = true;
bool immutable = false; bool immutable = false;
std::function<void()> onEnter; std::function<void()> onEnter;
std::function<void()> onEdit; std::function<void()> onEdit;
@ -58,7 +58,7 @@ struct TextBoxPathOptions {
struct TextBoxHexColorOptions { struct TextBoxHexColorOptions {
bool hasAlpha = true; bool hasAlpha = true;
bool updateEveryEdit = false; bool updateEveryEdit = true;
bool immutable = false; bool immutable = false;
std::function<void()> onEnter; std::function<void()> onEnter;
std::function<void()> onEdit; std::function<void()> onEdit;

View file

@ -14,7 +14,7 @@ template <typename T> struct TextBoxData {
std::function<std::optional<T>(const std::string&)> fromStr; std::function<std::optional<T>(const std::string&)> fromStr;
std::function<std::string(const T&)> toStr; std::function<std::string(const T&)> toStr;
bool singleLine = true; bool singleLine = true;
bool updateEveryEdit = false; bool updateEveryEdit = true;
bool immutable = false; bool immutable = false;
InputManager::TextInputProperties textInputProps; InputManager::TextInputProperties textInputProps;
std::function<void()> onEdit; std::function<void()> onEdit;

View file

@ -91,7 +91,7 @@ template <typename T> void TextBox<T>::after_text_input_callback() {
if(userInfo.immutable) if(userInfo.immutable)
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data)); cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
else { else {
if(update_data() && userInfo.onEdit) if(userInfo.updateEveryEdit && update_data() && userInfo.onEdit)
gui.set_post_callback_func_high_priority(userInfo.onEdit); gui.set_post_callback_func_high_priority(userInfo.onEdit);
} }
} }

View file

@ -1170,51 +1170,53 @@ void Toolbar::global_log() {
auto& gui = main.g.gui; auto& gui = main.g.gui;
auto& io = gui.io; auto& io = gui.io;
CLAY_AUTO_ID({ gui.new_id("Global log popup list", [&] {
.layout = { CLAY_AUTO_ID({
.sizing = {.width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_FIT(0) }, .layout = {
.childGap = io.theme->childGap1, .sizing = {.width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_FIT(0) },
.childAlignment = { .x = CLAY_ALIGN_X_RIGHT, .y = CLAY_ALIGN_Y_TOP}, .childGap = io.theme->childGap1,
.layoutDirection = CLAY_TOP_TO_BOTTOM .childAlignment = { .x = CLAY_ALIGN_X_RIGHT, .y = CLAY_ALIGN_Y_TOP},
}, .layoutDirection = CLAY_TOP_TO_BOTTOM
.floating = {.offset = {0, 10}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} },
}) { .floating = {.offset = {0, 10}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT}
int i = 0; }) {
for(auto& logM : main.logMessages) { for(size_t i = 0; i < main.logMessages.size(); i++) {
logM.time.update_time_since(); auto& logM = main.logMessages[i];
if(logM.time < LogMessage::DISPLAY_TIME) { logM.time.update_time_since();
float a = 1.0f - lerp_time<float>(logM.time, LogMessage::DISPLAY_TIME, LogMessage::FADE_START_TIME); if(logM.time < LogMessage::DISPLAY_TIME) {
gui.new_id(i, [&] { float a = 1.0f - lerp_time<float>(logM.time, LogMessage::DISPLAY_TIME, LogMessage::FADE_START_TIME);
gui.element<LayoutElement>("GLOBAL LOG", [&] (LayoutElement*, const Clay_ElementId& lId) { gui.new_id(i, [&] {
CLAY(lId, { gui.element<LayoutElement>("Global log message", [&] (LayoutElement*, const Clay_ElementId& lId) {
.layout = { CLAY(lId, {
.sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0) }, .layout = {
.padding = CLAY_PADDING_ALL(io.theme->padding1), .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0) },
.childGap = 0, .padding = CLAY_PADDING_ALL(io.theme->padding1),
.childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, .childGap = 0,
.layoutDirection = CLAY_TOP_TO_BOTTOM .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
}, .layoutDirection = CLAY_TOP_TO_BOTTOM
.backgroundColor = convert_vec4<Clay_Color>(color_mul_alpha(io.theme->backColor1, a)), },
.cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) .backgroundColor = convert_vec4<Clay_Color>(color_mul_alpha(io.theme->backColor1, a)),
}) { .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1)
SkColor4f c{0, 0, 0, 0}; }) {
switch(logM.color) { SkColor4f c{0, 0, 0, 0};
case LogMessage::COLOR_NORMAL: switch(logM.color) {
c = io.theme->frontColor1; case LogMessage::COLOR_NORMAL:
break; c = io.theme->frontColor1;
case LogMessage::COLOR_ERROR: break;
c = io.theme->errorColor; case LogMessage::COLOR_ERROR:
break; c = io.theme->errorColor;
break;
}
text_label_color(gui, logM.text, color_mul_alpha(c, a));
} }
text_label_color(gui, logM.text, color_mul_alpha(c, a)); });
}
}); });
}); }
else
break;
} }
else
break;
} }
} });
} }
void Toolbar::drawing_program_gui() { void Toolbar::drawing_program_gui() {
@ -2131,6 +2133,7 @@ void Toolbar::file_picker_gui() {
} }
}); });
input_path_field(gui, "file picker path", "Path", &filePicker.currentSearchPath, { input_path_field(gui, "file picker path", "Path", &filePicker.currentSearchPath, {
.updateEveryEdit = false,
.onEdit = [&] { .onEdit = [&] {
file_picker_gui_refresh_entries(); file_picker_gui_refresh_entries();
} }