Fixed rich text modifiers for textbox edit
This commit is contained in:
parent
783f645699
commit
0e732bea40
4 changed files with 22 additions and 11 deletions
|
|
@ -24,6 +24,8 @@ bool TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||||
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
|
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
|
||||||
Toolbar& t = drawP.world.main.toolbar;
|
Toolbar& t = drawP.world.main.toolbar;
|
||||||
|
|
||||||
|
auto& currentMods = *currentModsPtr;
|
||||||
|
|
||||||
t.gui.push_id("edit tool text");
|
t.gui.push_id("edit tool text");
|
||||||
t.gui.text_label_centered("Edit Text");
|
t.gui.text_label_centered("Edit Text");
|
||||||
|
|
||||||
|
|
@ -264,6 +266,8 @@ uint8_t TextBoxEditTool::get_new_decoration_value() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBoxEditTool::set_styles_at_selection(TextBoxCanvasComponent& a) {
|
void TextBoxEditTool::set_styles_at_selection(TextBoxCanvasComponent& a) {
|
||||||
|
auto& currentMods = *currentModsPtr;
|
||||||
|
|
||||||
TextPosition start = std::min(a.cursor->selectionBeginPos, a.cursor->selectionEndPos);
|
TextPosition start = std::min(a.cursor->selectionBeginPos, a.cursor->selectionEndPos);
|
||||||
TextPosition end = std::max(a.cursor->selectionBeginPos, a.cursor->selectionEndPos);
|
TextPosition end = std::max(a.cursor->selectionBeginPos, a.cursor->selectionEndPos);
|
||||||
if(start == end)
|
if(start == end)
|
||||||
|
|
@ -325,7 +329,7 @@ void TextBoxEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::O
|
||||||
.autocorrect = true,
|
.autocorrect = true,
|
||||||
.multiline = true,
|
.multiline = true,
|
||||||
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_TEXT
|
.androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_TEXT
|
||||||
});
|
}, currentModsPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextBoxEditTool::edit_update(CanvasComponentContainer::ObjInfo* comp) {
|
bool TextBoxEditTool::edit_update(CanvasComponentContainer::ObjInfo* comp) {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class TextBoxEditTool : public DrawingProgramEditToolBase {
|
||||||
|
|
||||||
std::unordered_map<std::string, std::pair<RichText::TextBox::Cursor, RichText::TextData>> undoHeldData;
|
std::unordered_map<std::string, std::pair<RichText::TextBox::Cursor, RichText::TextData>> undoHeldData;
|
||||||
|
|
||||||
RichText::TextStyleModifier::ModifierMap currentMods;
|
std::shared_ptr<RichText::TextStyleModifier::ModifierMap> currentModsPtr = std::make_shared<RichText::TextStyleModifier::ModifierMap>();
|
||||||
|
|
||||||
std::vector<std::string> sortedFontList;
|
std::vector<std::string> sortedFontList;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,13 @@ extern "C" {
|
||||||
|
|
||||||
#include "MainProgram.hpp"
|
#include "MainProgram.hpp"
|
||||||
|
|
||||||
|
template <typename T> std::optional<T> shared_ptr_to_opt(const std::shared_ptr<T> o) {
|
||||||
|
if(o)
|
||||||
|
return *o;
|
||||||
|
else
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
InputManager::InputManager(MainProgram& initMain):
|
InputManager::InputManager(MainProgram& initMain):
|
||||||
main(initMain) {
|
main(initMain) {
|
||||||
frame_reset({0, 0});
|
frame_reset({0, 0});
|
||||||
|
|
@ -88,7 +95,7 @@ InputManager::InputManager(MainProgram& initMain):
|
||||||
keyAssignments = defaultKeyAssignments;
|
keyAssignments = defaultKeyAssignments;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
void InputManager::set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
||||||
Text::TextBoxInfo textBoxInfo;
|
Text::TextBoxInfo textBoxInfo;
|
||||||
textBoxInfo.textBox = nTextBox;
|
textBoxInfo.textBox = nTextBox;
|
||||||
textBoxInfo.cursor = nCursor;
|
textBoxInfo.cursor = nCursor;
|
||||||
|
|
@ -100,7 +107,7 @@ void InputManager::set_rich_text_box_input_front(const std::shared_ptr<RichText:
|
||||||
text.update_accepting_input(main.window.sdlWindow);
|
text.update_accepting_input(main.window.sdlWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
void InputManager::set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr<RichText::TextStyleModifier::ModifierMap>& nModMap) {
|
||||||
Text::TextBoxInfo textBoxInfo;
|
Text::TextBoxInfo textBoxInfo;
|
||||||
textBoxInfo.textBox = nTextBox;
|
textBoxInfo.textBox = nTextBox;
|
||||||
textBoxInfo.cursor = nCursor;
|
textBoxInfo.cursor = nCursor;
|
||||||
|
|
@ -123,7 +130,7 @@ void InputManager::Text::add_text_to_textbox(const std::string& inputText) {
|
||||||
if(!textBoxes.empty() && !inputText.empty()) {
|
if(!textBoxes.empty() && !inputText.empty()) {
|
||||||
auto& frontTextBox = textBoxes.front();
|
auto& frontTextBox = textBoxes.front();
|
||||||
do_textbox_operation_with_undo([&]() {
|
do_textbox_operation_with_undo([&]() {
|
||||||
frontTextBox.textBox->process_text_input(*frontTextBox.cursor, inputText, frontTextBox.modMap);
|
frontTextBox.textBox->process_text_input(*frontTextBox.cursor, inputText, shared_ptr_to_opt(frontTextBox.modMap));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -859,7 +866,7 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
||||||
|
|
||||||
std::shared_ptr<RichText::TextBox> textBox = text.textBoxes.empty() ? nullptr : text.textBoxes.front().textBox;
|
std::shared_ptr<RichText::TextBox> textBox = text.textBoxes.empty() ? nullptr : text.textBoxes.front().textBox;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> cursor = text.textBoxes.empty() ? nullptr : text.textBoxes.front().cursor;
|
std::shared_ptr<RichText::TextBox::Cursor> cursor = text.textBoxes.empty() ? nullptr : text.textBoxes.front().cursor;
|
||||||
std::optional<RichText::TextStyleModifier::ModifierMap> modMap = text.textBoxes.empty() ? std::nullopt : text.textBoxes.front().modMap;
|
std::optional<RichText::TextStyleModifier::ModifierMap> modMap = text.textBoxes.empty() ? shared_ptr_to_opt(text.textBoxes.front().modMap) : std::nullopt;
|
||||||
|
|
||||||
switch(kPress) {
|
switch(kPress) {
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
|
|
@ -1043,10 +1050,10 @@ void InputManager::process_text_paste(const std::string& plainClipboardStr) {
|
||||||
if(lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(plainClipboardStr))
|
if(lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(plainClipboardStr))
|
||||||
text.textBoxes.front().textBox->process_rich_text_input(*text.textBoxes.front().cursor, lastCopiedRichText.value());
|
text.textBoxes.front().textBox->process_rich_text_input(*text.textBoxes.front().cursor, lastCopiedRichText.value());
|
||||||
else
|
else
|
||||||
text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, text.textBoxes.front().modMap);
|
text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, shared_ptr_to_opt(text.textBoxes.front().modMap));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, text.textBoxes.front().modMap);
|
text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, shared_ptr_to_opt(text.textBoxes.front().modMap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,8 +158,8 @@ struct InputManager {
|
||||||
int androidInputType;
|
int androidInputType;
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap = std::nullopt);
|
void set_rich_text_box_input_front(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr<RichText::TextStyleModifier::ModifierMap>& nModMap = nullptr);
|
||||||
void set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::optional<RichText::TextStyleModifier::ModifierMap>& nModMap = std::nullopt);
|
void set_rich_text_box_input_back(const std::shared_ptr<RichText::TextBox>& nTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& nCursor, bool isRichTextBox, const std::shared_ptr<SCollision::AABB<float>>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr<RichText::TextStyleModifier::ModifierMap>& nModMap = nullptr);
|
||||||
void remove_rich_text_box_input(const std::shared_ptr<RichText::TextBox>& nTextBox);
|
void remove_rich_text_box_input(const std::shared_ptr<RichText::TextBox>& nTextBox);
|
||||||
|
|
||||||
struct Text {
|
struct Text {
|
||||||
|
|
@ -176,7 +176,7 @@ struct InputManager {
|
||||||
std::shared_ptr<RichText::TextBox> textBox;
|
std::shared_ptr<RichText::TextBox> textBox;
|
||||||
std::shared_ptr<RichText::TextBox::Cursor> cursor;
|
std::shared_ptr<RichText::TextBox::Cursor> cursor;
|
||||||
std::shared_ptr<SCollision::AABB<float>> rect;
|
std::shared_ptr<SCollision::AABB<float>> rect;
|
||||||
std::optional<RichText::TextStyleModifier::ModifierMap> modMap;
|
std::shared_ptr<RichText::TextStyleModifier::ModifierMap> modMap;
|
||||||
TextInputProperties textInputProperties;
|
TextInputProperties textInputProperties;
|
||||||
UndoManager textboxUndo;
|
UndoManager textboxUndo;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue