Added empty text string to textbox gui element
This commit is contained in:
parent
e0a19a9c49
commit
6feebe351d
4 changed files with 38 additions and 17 deletions
|
|
@ -13,11 +13,13 @@ template <typename T, typename OptT> TextBoxData<T> textbox_options_to_data(cons
|
||||||
toRet.immutable = options.immutable;
|
toRet.immutable = options.immutable;
|
||||||
toRet.onSelect = options.onSelect;
|
toRet.onSelect = options.onSelect;
|
||||||
toRet.onDeselect = options.onDeselect;
|
toRet.onDeselect = options.onDeselect;
|
||||||
|
toRet.emptyText = options.emptyText;
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextBoxOptions {
|
struct TextBoxOptions {
|
||||||
bool immutable = false;
|
bool immutable = false;
|
||||||
|
std::string emptyText;
|
||||||
std::function<void()> onEnter;
|
std::function<void()> onEnter;
|
||||||
std::function<void()> onEdit;
|
std::function<void()> onEdit;
|
||||||
std::function<void()> onSelect;
|
std::function<void()> onSelect;
|
||||||
|
|
@ -27,6 +29,7 @@ struct TextBoxOptions {
|
||||||
struct TextBoxScalarOptions {
|
struct TextBoxScalarOptions {
|
||||||
int decimalPrecision = 0;
|
int decimalPrecision = 0;
|
||||||
bool immutable = false;
|
bool immutable = false;
|
||||||
|
std::string emptyText;
|
||||||
std::function<void()> onEnter;
|
std::function<void()> onEnter;
|
||||||
std::function<void()> onEdit;
|
std::function<void()> onEdit;
|
||||||
std::function<void()> onSelect;
|
std::function<void()> onSelect;
|
||||||
|
|
@ -36,6 +39,7 @@ struct TextBoxScalarOptions {
|
||||||
struct TextBoxScalarsOptions {
|
struct TextBoxScalarsOptions {
|
||||||
int decimalPrecision = 0;
|
int decimalPrecision = 0;
|
||||||
bool immutable = false;
|
bool immutable = false;
|
||||||
|
std::string emptyText;
|
||||||
std::function<void(size_t)> onEnter;
|
std::function<void(size_t)> onEnter;
|
||||||
std::function<void(size_t)> onEdit;
|
std::function<void(size_t)> onEdit;
|
||||||
std::function<void(size_t)> onSelect;
|
std::function<void(size_t)> onSelect;
|
||||||
|
|
@ -45,6 +49,7 @@ struct TextBoxScalarsOptions {
|
||||||
struct TextBoxPathOptions {
|
struct TextBoxPathOptions {
|
||||||
std::filesystem::file_type fileTypeRestriction;
|
std::filesystem::file_type fileTypeRestriction;
|
||||||
bool immutable = false;
|
bool immutable = false;
|
||||||
|
std::string emptyText;
|
||||||
std::function<void()> onEnter;
|
std::function<void()> onEnter;
|
||||||
std::function<void()> onEdit;
|
std::function<void()> onEdit;
|
||||||
std::function<void()> onSelect;
|
std::function<void()> onSelect;
|
||||||
|
|
@ -54,6 +59,7 @@ struct TextBoxPathOptions {
|
||||||
struct TextBoxHexColorOptions {
|
struct TextBoxHexColorOptions {
|
||||||
bool hasAlpha = true;
|
bool hasAlpha = true;
|
||||||
bool immutable = false;
|
bool immutable = false;
|
||||||
|
std::string emptyText;
|
||||||
std::function<void()> onEnter;
|
std::function<void()> onEnter;
|
||||||
std::function<void()> onEdit;
|
std::function<void()> onEdit;
|
||||||
std::function<void()> onSelect;
|
std::function<void()> onSelect;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ template <typename T> struct TextBoxData {
|
||||||
bool singleLine = true;
|
bool singleLine = true;
|
||||||
bool immutable = false;
|
bool immutable = false;
|
||||||
InputManager::TextInputProperties textInputProps;
|
InputManager::TextInputProperties textInputProps;
|
||||||
|
std::string emptyText;
|
||||||
std::function<void()> onEdit;
|
std::function<void()> onEdit;
|
||||||
std::function<void()> onEnter;
|
std::function<void()> onEnter;
|
||||||
std::function<void()> onSelect;
|
std::function<void()> onSelect;
|
||||||
|
|
@ -48,6 +49,7 @@ template <typename T> class TextBox : public Element {
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
~TextBox();
|
~TextBox();
|
||||||
private:
|
private:
|
||||||
|
void populate_empty_textbox();
|
||||||
void after_text_input_callback();
|
void after_text_input_callback();
|
||||||
void init_textbox(UpdateInputData& io);
|
void init_textbox(UpdateInputData& io);
|
||||||
void reset_textbox_text();
|
void reset_textbox_text();
|
||||||
|
|
@ -60,10 +62,12 @@ template <typename T> class TextBox : public Element {
|
||||||
RichText::TextBox::Cursor cur;
|
RichText::TextBox::Cursor cur;
|
||||||
} oldDD;
|
} oldDD;
|
||||||
|
|
||||||
|
bool isEmptyText = false;
|
||||||
bool isHeld = false;
|
bool isHeld = false;
|
||||||
std::optional<TextEditData> edit;
|
std::optional<TextEditData> edit;
|
||||||
|
|
||||||
std::optional<T> oldData;
|
std::optional<T> oldData;
|
||||||
|
std::string oldEmptyText;
|
||||||
TextBoxData<T> userInfo;
|
TextBoxData<T> userInfo;
|
||||||
std::shared_ptr<RichText::TextBox> textbox;
|
std::shared_ptr<RichText::TextBox> textbox;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> cur;
|
std::shared_ptr<RichText::TextBox::Cursor> cur;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,11 @@ template <typename T> void TextBox<T>::layout(const Clay_ElementId& id, const Te
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
this->userInfo = userInfo;
|
this->userInfo = userInfo;
|
||||||
init_textbox(io);
|
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();
|
reset_textbox_text();
|
||||||
|
populate_empty_textbox();
|
||||||
|
gui.invalidate_draw_element(this);
|
||||||
|
}
|
||||||
|
|
||||||
CLAY(id, {
|
CLAY(id, {
|
||||||
.layout = {
|
.layout = {
|
||||||
|
|
@ -75,6 +78,8 @@ template <typename T> void TextBox<T>::select() {
|
||||||
if(!is_selected()) {
|
if(!is_selected()) {
|
||||||
SCollision::AABB<float> rect = {boundingBox.value().min * gui.io.guiScaleMultiplier, boundingBox.value().max * gui.io.guiScaleMultiplier};
|
SCollision::AABB<float> 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);
|
unsigned id = gui.io.input->set_text_box_front(rect, userInfo.textInputProps);
|
||||||
|
if(isEmptyText)
|
||||||
|
textbox->clear_text();
|
||||||
edit = TextEditData(id, textbox, cur);
|
edit = TextEditData(id, textbox, cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,6 +90,7 @@ template <typename T> void TextBox<T>::deselect() {
|
||||||
if(userInfo.onDeselect) userInfo.onDeselect();
|
if(userInfo.onDeselect) userInfo.onDeselect();
|
||||||
reset_textbox_text();
|
reset_textbox_text();
|
||||||
edit = std::nullopt;
|
edit = std::nullopt;
|
||||||
|
populate_empty_textbox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,6 +120,21 @@ template <typename T> void TextBox<T>::input_text_key_callback(const InputManage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> void TextBox<T>::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<RichText::SlantTextStyleModifier>(SkFontStyle::kItalic_Slant);
|
||||||
|
positionedMod.mods[RichText::TextStyleModifier::ModifierType::COLOR] = std::make_shared<RichText::ColorTextStyleModifier>(convert_vec4<Vector4f>(gui.io.theme->frontColor2));
|
||||||
|
|
||||||
|
textbox->set_rich_text_data(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T> void TextBox<T>::after_text_input_callback() {
|
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));
|
||||||
|
|
@ -167,7 +188,9 @@ template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void TextBox<T>::reset_textbox_text() {
|
template <typename T> void TextBox<T>::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->pos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->pos);
|
||||||
cur->selectionBeginPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionBeginPos);
|
cur->selectionBeginPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionBeginPos);
|
||||||
cur->selectionEndPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionEndPos);
|
cur->selectionEndPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionEndPos);
|
||||||
|
|
|
||||||
|
|
@ -412,16 +412,6 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
}) {
|
}) {
|
||||||
text_label(gui, main.conf.palettes[objIndex.back()].name);
|
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) {
|
if(objIndex.back() != 0) {
|
||||||
gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] {
|
gui.set_z_index_keep_clipping_region(gui.get_z_index() + 1, [&] {
|
||||||
svg_icon_button(gui, "delete button", "data/icons/trash.svg", {
|
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<TreeListingObjIndexList>& objIndices, const TreeListingObjIndexList& newObjIndex) {
|
.moveObj = [&](const std::vector<TreeListingObjIndexList>& objIndices, const TreeListingObjIndexList& newObjIndex) {
|
||||||
if(newObjIndex.back() == 0)
|
if(newObjIndex.back() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -452,6 +438,7 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color) {
|
||||||
main.conf.palettes.erase(main.conf.palettes.begin() + p.back());
|
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());
|
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();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
input_text_field(gui, "paletteinputname", "Name", &colorPickerPopupData.newPaletteStr, {
|
input_text(gui, "paletteinputname", &colorPickerPopupData.newPaletteStr, {
|
||||||
|
.emptyText = "New Palette Name...",
|
||||||
.onEnter = addPaletteFunc
|
.onEnter = addPaletteFunc
|
||||||
});
|
});
|
||||||
svg_icon_button(gui, "paletteadd", "data/icons/plus.svg", {
|
svg_icon_button(gui, "paletteadd", "data/icons/plus.svg", {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue