Textbox updates work again, and added notices for web version users

This commit is contained in:
Yousef Khadadeh 2025-11-17 16:08:42 +03:00
parent f0f289d785
commit 174b267589
8 changed files with 63 additions and 29 deletions

View file

@ -43,12 +43,12 @@ void DrawTextBox::save_file(cereal::PortableBinaryOutputArchive& a) const {
void DrawTextBox::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { void DrawTextBox::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) {
if(version < VersionNumber(0, 3, 0)) { if(version < VersionNumber(0, 3, 0)) {
bool editing; // Unused bool loadedEditing; // Unused
Vector4f textColor; Vector4f textColor;
float textSize; float textSize;
RichText::TextBox::Cursor cursor; // Unused, Equivalent to old cursor structure, just paragraph index and text index flipped RichText::TextBox::Cursor loadedCursor; // Unused, Equivalent to old cursor structure, just paragraph index and text index flipped
std::string currentText; std::string currentText;
a(editing, d.p1, d.p2, textColor, textSize, cursor, currentText); a(loadedEditing, d.p1, d.p2, textColor, textSize, loadedCursor, currentText);
textBox->insert({0, 0}, currentText); textBox->insert({0, 0}, currentText);
textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared<ColorTextStyleModifier>(textColor)); textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared<ColorTextStyleModifier>(textColor));
textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared<SizeTextStyleModifier>(textSize)); textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared<SizeTextStyleModifier>(textSize));
@ -64,6 +64,7 @@ void DrawTextBox::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber
std::shared_ptr<DrawComponent> DrawTextBox::copy(DrawingProgram& drawP) const { std::shared_ptr<DrawComponent> DrawTextBox::copy(DrawingProgram& drawP) const {
auto a = std::make_shared<DrawTextBox>(); auto a = std::make_shared<DrawTextBox>();
a->d = d; a->d = d;
*a->cursor = *cursor;
a->coords = coords; a->coords = coords;
a->textBox->set_rich_text_data(textBox->get_rich_text_data()); a->textBox->set_rich_text_data(textBox->get_rich_text_data());
a->init_text_box(drawP); a->init_text_box(drawP);
@ -73,6 +74,7 @@ std::shared_ptr<DrawComponent> DrawTextBox::copy(DrawingProgram& drawP) const {
std::shared_ptr<DrawComponent> DrawTextBox::deep_copy(DrawingProgram& drawP) const { std::shared_ptr<DrawComponent> DrawTextBox::deep_copy(DrawingProgram& drawP) const {
auto a = std::make_shared<DrawTextBox>(); auto a = std::make_shared<DrawTextBox>();
a->d = d; a->d = d;
*a->cursor = *cursor;
a->coords = coords; a->coords = coords;
a->textBox->set_rich_text_data(textBox->get_rich_text_data()); a->textBox->set_rich_text_data(textBox->get_rich_text_data());
a->collisionTree = collisionTree; a->collisionTree = collisionTree;
@ -83,6 +85,8 @@ std::shared_ptr<DrawComponent> DrawTextBox::deep_copy(DrawingProgram& drawP) con
void DrawTextBox::update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) { void DrawTextBox::update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) {
std::shared_ptr<DrawTextBox> newPtr = std::static_pointer_cast<DrawTextBox>(delayedUpdatePtr); std::shared_ptr<DrawTextBox> newPtr = std::static_pointer_cast<DrawTextBox>(delayedUpdatePtr);
d = newPtr->d; d = newPtr->d;
*cursor = *newPtr->cursor;
textBox->set_rich_text_data(newPtr->textBox->get_rich_text_data());
} }
void DrawTextBox::init_text_box(DrawingProgram& drawP) { void DrawTextBox::init_text_box(DrawingProgram& drawP) {

View file

@ -76,6 +76,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
CLAY({ CLAY({
.layout = { .layout = {
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, 300)}, .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, 300)},
.layoutDirection = CLAY_TOP_TO_BOTTOM
}, },
.backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor1), .backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(4), .cornerRadius = CLAY_CORNER_RADIUS(4),
@ -158,6 +159,14 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
if(fontChangedFromTextbox && !io->mouse.leftClick && val != std::numeric_limits<size_t>::max()) if(fontChangedFromTextbox && !io->mouse.leftClick && val != std::numeric_limits<size_t>::max())
scrollAmount = -static_cast<float>(val) * ENTRY_HEIGHT; scrollAmount = -static_cast<float>(val) * ENTRY_HEIGHT;
}); });
#ifdef __EMSCRIPTEN__
CLAY({
.layout = {
.padding = CLAY_PADDING_ALL(io.theme->padding1)
}}) {
gui->text_label_light_centered("Local fonts not usable in web version");
}
#endif
} }
} }
} }

View file

@ -313,7 +313,7 @@ void GUIManager::text_label_centered(const std::string& val) {
.childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER},
} }
}) { }) {
CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor1), .fontSize = io->fontSize })); CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor1), .fontSize = io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER}));
} }
} }
@ -324,7 +324,7 @@ void GUIManager::text_label_light_centered(const std::string& val) {
.childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER},
} }
}) { }) {
CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor2), .fontSize = io->fontSize })); CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor2), .fontSize = io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER}));
} }
} }

View file

@ -1,5 +1,7 @@
#include "MainProgram.hpp" #include "MainProgram.hpp"
#include "DrawingProgram/DrawingProgramToolBase.hpp" #include "DrawingProgram/DrawingProgramToolBase.hpp"
#include "Helpers/VersionNumber.hpp"
#include "VersionConstants.hpp"
#include "cereal/archives/portable_binary.hpp" #include "cereal/archives/portable_binary.hpp"
#include "cereal/details/helpers.hpp" #include "cereal/details/helpers.hpp"
#include <chrono> #include <chrono>
@ -169,6 +171,7 @@ void MainProgram::save_config() {
using json = nlohmann::json; using json = nlohmann::json;
json j; json j;
j["version"] = VersionConstants::CURRENT_VERSION_STRING;
j["settings"] = toolbar.get_config_json(); j["settings"] = toolbar.get_config_json();
j["window"]["pos"] = window.writtenPos; j["window"]["pos"] = window.writtenPos;
j["window"]["size"] = window.writtenSize; j["window"]["size"] = window.writtenSize;
@ -198,11 +201,23 @@ void MainProgram::load_config() {
toolbar.file_selector_path() = homePath; toolbar.file_selector_path() = homePath;
if(f.is_open()) { if(f.is_open()) {
using json = nlohmann::json; using json = nlohmann::json;
try { try {
json j; json j;
f >> j; f >> j;
VersionNumber version(0, 0, 1);
try { try {
toolbar.set_config_json(j["settings"]); std::string versionStr;
j.at("version").get_to(versionStr);
auto optVersion = version_str_to_version_numbers(versionStr);
if(optVersion.has_value())
version = optVersion.value();
}
catch(...) {}
try {
toolbar.set_config_json(j["settings"], version);
} }
catch(...) {} catch(...) {}
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__

View file

@ -86,16 +86,16 @@ bool ImageResourceDisplay::load(ResourceManager& rMan, const std::string& fileNa
totalFramesToLoad = codec->getFrameCount(); totalFramesToLoad = codec->getFrameCount();
imageInfo = codec->getInfo(); imageInfo = codec->getInfo();
frames.resize(totalFramesToLoad); frames.resize(totalFramesToLoad);
loadedFrames = 0;
if(rotate) { if(rotate) {
Logger::get().log("INFO", "Image loaded is rotated, so must rotate dimensions"); Logger::get().log("INFO", "Image loaded is rotated, so must rotate dimensions");
imageInfo = imageInfo.makeDimensions(SkISize(imageInfo.height(), imageInfo.width())); imageInfo = imageInfo.makeDimensions(SkISize(imageInfo.height(), imageInfo.width()));
} }
try{ try{
Logger::get().log("INFO", "[ImageResourceDisplay::load] Failed to create load thread, loading on main thread");
loadedFrames = 0;
loadThread = std::make_unique<std::thread>(&ImageResourceDisplay::load_thread, this); loadThread = std::make_unique<std::thread>(&ImageResourceDisplay::load_thread, this);
} }
catch(...) { catch(...) {
Logger::get().log("INFO", "[ImageResourceDisplay::load] Failed to create load thread, loading on main thread");
load_thread(); load_thread();
} }
return true; return true;

View file

@ -221,7 +221,6 @@ nlohmann::json Toolbar::get_config_json() {
jKeybinds[json(static_cast<InputManager::KeyCodeEnum>(i))] = main.input.key_assignment_to_str(f->first); jKeybinds[json(static_cast<InputManager::KeyCodeEnum>(i))] = main.input.key_assignment_to_str(f->first);
} }
toRet["keybinds"] = jKeybinds; toRet["keybinds"] = jKeybinds;
toRet["guiScale"] = guiScale; toRet["guiScale"] = guiScale;
toRet["jumpTransitionTime"] = jumpTransitionTime; toRet["jumpTransitionTime"] = jumpTransitionTime;
toRet["dragZoomSpeed"] = dragZoomSpeed; toRet["dragZoomSpeed"] = dragZoomSpeed;
@ -250,7 +249,7 @@ nlohmann::json Toolbar::get_config_json() {
return toRet; return toRet;
} }
void Toolbar::set_config_json(const nlohmann::json& j) { void Toolbar::set_config_json(const nlohmann::json& j, VersionNumber version) {
using json = nlohmann::json; using json = nlohmann::json;
main.input.keyAssignments.clear(); main.input.keyAssignments.clear();
try { try {
@ -274,27 +273,28 @@ void Toolbar::set_config_json(const nlohmann::json& j) {
catch(...) { catch(...) {
main.input.keyAssignments = main.input.defaultKeyAssignments; main.input.keyAssignments = main.input.defaultKeyAssignments;
} }
j.at("displayName").get_to(main.displayName); try{j.at("displayName").get_to(main.displayName);} catch(...) {}
j.at("jumpTransitionTime").get_to(jumpTransitionTime); try{j.at("jumpTransitionTime").get_to(jumpTransitionTime);} catch(...) {}
j.at("dragZoomSpeed").get_to(dragZoomSpeed); try{j.at("dragZoomSpeed").get_to(dragZoomSpeed);} catch(...) {}
j.at("scrollZoomSpeed").get_to(scrollZoomSpeed); try{j.at("scrollZoomSpeed").get_to(scrollZoomSpeed);} catch(...) {}
j.at("guiScale").get_to(guiScale); try{j.at("guiScale").get_to(guiScale);} catch(...) {}
j.at("showPerformance").get_to(showPerformance); try{j.at("showPerformance").get_to(showPerformance);} catch(...) {}
j.at("useNativeFilePicker").get_to(useNativeFilePicker); try{j.at("useNativeFilePicker").get_to(useNativeFilePicker);} catch(...) {}
j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded); try{j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);} catch(...) {}
j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth); try{j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth);} catch(...) {}
j.at("jumpTransitionEasing").get_to(jumpTransitionEasing); try{j.at("jumpTransitionEasing").get_to(jumpTransitionEasing);} catch(...) {}
j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor); if(version >= VersionNumber(0, 3, 0))
j.at("flipZoomToolDirection").get_to(flipZoomToolDirection); try{j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor);} catch(...) {}
try{j.at("flipZoomToolDirection").get_to(flipZoomToolDirection);} catch(...) {}
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
j.at("checkForUpdates").get_to(updateCheckerData.checkForUpdates); try{j.at("checkForUpdates").get_to(updateCheckerData.checkForUpdates);} catch(...) {}
#endif #endif
j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth); try{j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth);} catch(...) {}
j.at("tablet").at("smoothingSamplingTime").get_to(tabletOptions.smoothingSamplingTime); try{j.at("tablet").at("smoothingSamplingTime").get_to(tabletOptions.smoothingSamplingTime);} catch(...) {}
j.at("tablet").at("middleClickButton").get_to(tabletOptions.middleClickButton); try{j.at("tablet").at("middleClickButton").get_to(tabletOptions.middleClickButton);} catch(...) {}
j.at("tablet").at("rightClickButton").get_to(tabletOptions.rightClickButton); try{j.at("tablet").at("rightClickButton").get_to(tabletOptions.rightClickButton);} catch(...) {}
j.at("tablet").at("ignoreMouseMovementWhenPenInProximity").get_to(tabletOptions.ignoreMouseMovementWhenPenInProximity); try{j.at("tablet").at("ignoreMouseMovementWhenPenInProximity").get_to(tabletOptions.ignoreMouseMovementWhenPenInProximity);} catch(...) {}
main.update_display_names(); main.update_display_names();
} }
@ -563,6 +563,8 @@ R"(This version contains more known issues than the native version of the app. T
- Rare crashes - Rare crashes
- If this browser tab is unfocused, or the window is minimized, any InfiniPaint tabs connected online (whether host or client) will be disconnected - If this browser tab is unfocused, or the window is minimized, any InfiniPaint tabs connected online (whether host or client) will be disconnected
- 4GB memory limit. Might be a problem if you're uploading many files/images - 4GB memory limit. Might be a problem if you're uploading many files/images
- Not multithreaded
- Can't access local fonts
If you like this app, consider downloading the native version for your system)"); If you like this app, consider downloading the native version for your system)");
if(gui.text_button_wide("got it", "Got It")) if(gui.text_button_wide("got it", "Got It"))

View file

@ -8,6 +8,7 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <Helpers/Serializers.hpp> #include <Helpers/Serializers.hpp>
#include <SDL3/SDL_dialog.h> #include <SDL3/SDL_dialog.h>
#include <Helpers/VersionNumber.hpp>
class MainProgram; class MainProgram;
@ -55,7 +56,7 @@ class Toolbar {
GUIStuff::GUIManager gui; GUIStuff::GUIManager gui;
nlohmann::json get_config_json(); nlohmann::json get_config_json();
void set_config_json(const nlohmann::json& j); void set_config_json(const nlohmann::json& j, VersionNumber version);
void save_palettes(); void save_palettes();
void load_palettes(); void load_palettes();

View file

@ -3,6 +3,7 @@
#include "Helpers/HsvRgb.hpp" #include "Helpers/HsvRgb.hpp"
#include "Helpers/MathExtras.hpp" #include "Helpers/MathExtras.hpp"
#include "Helpers/Networking/ByteStream.hpp" #include "Helpers/Networking/ByteStream.hpp"
#include "Helpers/VersionNumber.hpp"
#include "Server/CommandList.hpp" #include "Server/CommandList.hpp"
#include "MainProgram.hpp" #include "MainProgram.hpp"
#include "SharedTypes.hpp" #include "SharedTypes.hpp"
@ -339,6 +340,8 @@ void World::load_from_file(const std::filesystem::path& fileName, std::string_vi
ByteMemStream f((char*)uncompressedDataView.data(), uncompressedDataView.size()); ByteMemStream f((char*)uncompressedDataView.data(), uncompressedDataView.size());
Logger::get().log("INFO", "Loading file from version " + version_numbers_to_version_str(fileVersion));
cereal::PortableBinaryInputArchive a(f); cereal::PortableBinaryInputArchive a(f);
load_file(a, fileVersion); load_file(a, fileVersion);
nextClientID = get_max_id(ownID); nextClientID = get_max_id(ownID);