diff --git a/src/GUIStuff/ElementHelpers/TextBoxHelpers.hpp b/src/GUIStuff/ElementHelpers/TextBoxHelpers.hpp index 3f1ee24..8ba9405 100644 --- a/src/GUIStuff/ElementHelpers/TextBoxHelpers.hpp +++ b/src/GUIStuff/ElementHelpers/TextBoxHelpers.hpp @@ -13,11 +13,13 @@ template TextBoxData textbox_options_to_data(cons toRet.immutable = options.immutable; toRet.onSelect = options.onSelect; toRet.onDeselect = options.onDeselect; + toRet.emptyText = options.emptyText; return toRet; } struct TextBoxOptions { bool immutable = false; + std::string emptyText; std::function onEnter; std::function onEdit; std::function onSelect; @@ -27,6 +29,7 @@ struct TextBoxOptions { struct TextBoxScalarOptions { int decimalPrecision = 0; bool immutable = false; + std::string emptyText; std::function onEnter; std::function onEdit; std::function onSelect; @@ -36,6 +39,7 @@ struct TextBoxScalarOptions { struct TextBoxScalarsOptions { int decimalPrecision = 0; bool immutable = false; + std::string emptyText; std::function onEnter; std::function onEdit; std::function onSelect; @@ -45,6 +49,7 @@ struct TextBoxScalarsOptions { struct TextBoxPathOptions { std::filesystem::file_type fileTypeRestriction; bool immutable = false; + std::string emptyText; std::function onEnter; std::function onEdit; std::function onSelect; @@ -54,6 +59,7 @@ struct TextBoxPathOptions { struct TextBoxHexColorOptions { bool hasAlpha = true; bool immutable = false; + std::string emptyText; std::function onEnter; std::function onEdit; std::function onSelect; diff --git a/src/GUIStuff/Elements/TextBox.decl.hpp b/src/GUIStuff/Elements/TextBox.decl.hpp index 45f2981..b597b88 100644 --- a/src/GUIStuff/Elements/TextBox.decl.hpp +++ b/src/GUIStuff/Elements/TextBox.decl.hpp @@ -16,6 +16,7 @@ template struct TextBoxData { bool singleLine = true; bool immutable = false; InputManager::TextInputProperties textInputProps; + std::string emptyText; std::function onEdit; std::function onEnter; std::function onSelect; @@ -48,6 +49,7 @@ template class TextBox : public Element { virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override; ~TextBox(); private: + void populate_empty_textbox(); void after_text_input_callback(); void init_textbox(UpdateInputData& io); void reset_textbox_text(); @@ -60,10 +62,12 @@ template class TextBox : public Element { RichText::TextBox::Cursor cur; } oldDD; + bool isEmptyText = false; bool isHeld = false; std::optional edit; std::optional oldData; + std::string oldEmptyText; TextBoxData userInfo; std::shared_ptr textbox; std::shared_ptr cur; diff --git a/src/GUIStuff/Elements/TextBox.impl.hpp b/src/GUIStuff/Elements/TextBox.impl.hpp index 3c70347..587bbf3 100644 --- a/src/GUIStuff/Elements/TextBox.impl.hpp +++ b/src/GUIStuff/Elements/TextBox.impl.hpp @@ -9,8 +9,11 @@ template void TextBox::layout(const Clay_ElementId& id, const Te auto& io = gui.io; this->userInfo = userInfo; init_textbox(io); - if(!oldData.has_value() || oldData.value() != *userInfo.data) + if(!oldData.has_value() || oldData.value() != *userInfo.data || (oldEmptyText != userInfo.emptyText)) { reset_textbox_text(); + populate_empty_textbox(); + gui.invalidate_draw_element(this); + } CLAY(id, { .layout = { @@ -75,6 +78,8 @@ template void TextBox::select() { if(!is_selected()) { SCollision::AABB rect = {boundingBox.value().min * gui.io.guiScaleMultiplier, boundingBox.value().max * gui.io.guiScaleMultiplier}; unsigned id = gui.io.input->set_text_box_front(rect, userInfo.textInputProps); + if(isEmptyText) + textbox->clear_text(); edit = TextEditData(id, textbox, cur); } } @@ -85,6 +90,7 @@ template void TextBox::deselect() { if(userInfo.onDeselect) userInfo.onDeselect(); reset_textbox_text(); edit = std::nullopt; + populate_empty_textbox(); } } @@ -114,6 +120,21 @@ template void TextBox::input_text_key_callback(const InputManage } } +template void TextBox::populate_empty_textbox() { + if(!is_selected() && isEmptyText && !userInfo.emptyText.empty()) { + RichText::TextData text; + RichText::TextData::Paragraph& par = text.paragraphs.emplace_back(); + par.text = userInfo.emptyText; + + RichText::PositionedTextStyleMod& positionedMod = text.tStyleMods.emplace_back(); + positionedMod.pos = {0, 0}; + positionedMod.mods[RichText::TextStyleModifier::ModifierType::SLANT] = std::make_shared(SkFontStyle::kItalic_Slant); + positionedMod.mods[RichText::TextStyleModifier::ModifierType::COLOR] = std::make_shared(convert_vec4(gui.io.theme->frontColor2)); + + textbox->set_rich_text_data(text); + } +} + template void TextBox::after_text_input_callback() { if(userInfo.immutable) cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data)); @@ -167,7 +188,9 @@ template void TextBox::init_textbox(UpdateInputData& io) { } template void TextBox::reset_textbox_text() { - textbox->set_string(userInfo.toStr(*userInfo.data)); + std::string newStr = userInfo.toStr(*userInfo.data); + isEmptyText = newStr.empty(); + textbox->set_string(newStr); cur->pos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->pos); cur->selectionBeginPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionBeginPos); cur->selectionEndPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionEndPos); diff --git a/src/Screens/PhoneDrawingProgramScreen.cpp b/src/Screens/PhoneDrawingProgramScreen.cpp index dd3e448..b6cbc1d 100644 --- a/src/Screens/PhoneDrawingProgramScreen.cpp +++ b/src/Screens/PhoneDrawingProgramScreen.cpp @@ -412,16 +412,6 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) { }) { text_label(gui, main.conf.palettes[objIndex.back()].name); } - gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] { - svg_icon_button(gui, "edit button", "data/icons/pencil.svg", { - .drawType = SelectableButton::DrawType::TRANSPARENT_ALL, - .size = TreeListing::ENTRY_HEIGHT, - .onClick = [&, objIndex] { - colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::EXTRA; - colorPickerPopupData.selectedPalette = objIndex.back(); - } - }); - }); if(objIndex.back() != 0) { gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] { svg_icon_button(gui, "delete button", "data/icons/trash.svg", { @@ -435,10 +425,6 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) { }); } }, - .onDoubleClick = [&](const TreeListingObjIndexList& objIndex) { - colorPickerPopupData.screenType = ColorPickerPopupData::ScreenType::EXTRA; - colorPickerPopupData.selectedPalette = objIndex.back(); - }, .moveObj = [&](const std::vector& objIndices, const TreeListingObjIndexList& newObjIndex) { if(newObjIndex.back() == 0) return; @@ -452,6 +438,7 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) { main.conf.palettes.erase(main.conf.palettes.begin() + p.back()); } } + colorPickerPopupData.selectedPalette = 0; main.conf.palettes.insert(main.conf.palettes.begin() + moveIndex, movedPalettes.begin(), movedPalettes.end()); } }); @@ -472,7 +459,8 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) { gui.set_to_layout(); } }; - input_text_field(gui, "paletteinputname", "Name", &colorPickerPopupData.newPaletteStr, { + input_text(gui, "paletteinputname", &colorPickerPopupData.newPaletteStr, { + .emptyText = "New Palette Name...", .onEnter = addPaletteFunc }); svg_icon_button(gui, "paletteadd", "data/icons/plus.svg", {