Textbox input runs callbacks
This commit is contained in:
parent
f90cf5b026
commit
d89aabff81
13 changed files with 59 additions and 13 deletions
|
|
@ -120,6 +120,7 @@ void DrawCamera::update_main(World& w) {
|
|||
.move = {0, 0}
|
||||
};
|
||||
w.drawProg.drawTool->input_mouse_motion_callback(motion);
|
||||
w.main.g.gui.set_to_layout();
|
||||
}
|
||||
if(w.main.input.key(InputManager::KEY_CAMERA_ROTATE_CLOCKWISE).held && !w.main.input.text.is_accepting_input()) {
|
||||
c.rotate_about(c.from_space(w.main.window.size.cast<float>() * 0.5f), w.main.deltaTime);
|
||||
|
|
@ -128,6 +129,7 @@ void DrawCamera::update_main(World& w) {
|
|||
.move = {0, 0}
|
||||
};
|
||||
w.drawProg.drawTool->input_mouse_motion_callback(motion);
|
||||
w.main.g.gui.set_to_layout();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -533,6 +533,7 @@ void DrawingProgram::switch_to_tool(DrawingProgramToolType newToolType, bool for
|
|||
drawTool->switch_tool(newToolType);
|
||||
drawTool = DrawingProgramToolBase::allocate_tool_type(*this, newToolType);
|
||||
world.main.toolbar.rightClickPopupLocation = std::nullopt;
|
||||
world.main.g.gui.set_to_layout();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ void EditTool::switch_tool(DrawingProgramToolType newTool) {
|
|||
|
||||
oldData = nullptr;
|
||||
objInfoBeingEdited = nullptr;
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
pointHandles.clear();
|
||||
pointDragging = nullptr;
|
||||
|
|
@ -250,6 +251,7 @@ void EditTool::edit_start(CanvasComponentContainer::ObjInfo* comp, bool initUndo
|
|||
oldData = comp->obj->get_comp().get_data_copy();
|
||||
undoAfterEditDone = initUndoAfterEditDone;
|
||||
compEditTool->edit_start(*this, objInfoBeingEdited, prevData);
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
|
||||
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
auto commit_update_func = [&, comp] { comp->obj->commit_update(drawP); };
|
||||
auto commit_update_and_layout_func = [&, comp] {
|
||||
comp->obj->commit_update(drawP);
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
};
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
gui.new_id("edit tool ellipse", [&] {
|
||||
|
|
@ -30,7 +35,7 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
});
|
||||
}, commit_update_and_layout_func);
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
left_to_right_line_layout(gui, [&] {
|
||||
//if(gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
|
|
@ -39,7 +44,7 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f, {.onEdit = commit_update_func});
|
||||
left_to_right_line_layout(gui, [&] {
|
||||
//if(gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
|
|
|
|||
|
|
@ -18,16 +18,22 @@ void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp());
|
||||
auto commit_update_and_layout_func = [&, comp] {
|
||||
comp->obj->commit_update(drawP);
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
};
|
||||
auto commit_update_func = [&, comp] { comp->obj->commit_update(drawP); };
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("edit tool rectangle", [&] {
|
||||
text_label_centered(gui, "Edit Rectangle");
|
||||
slider_scalar_field(gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f);
|
||||
slider_scalar_field(gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f, { .onEdit = commit_update_func });
|
||||
radio_button_selector(gui, "Fill selector", &a.d.fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
});
|
||||
}, commit_update_and_layout_func);
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
left_to_right_line_layout(gui, [&] {
|
||||
//if(gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
|
|
@ -36,7 +42,7 @@ void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f, { .onEdit = commit_update_func });
|
||||
left_to_right_line_layout(gui, [&] {
|
||||
//if(gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
|
|
|
|||
|
|
@ -123,6 +123,16 @@ void GUIHolder::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
|||
gui.input_key_callback(key);
|
||||
}
|
||||
|
||||
void GUIHolder::input_text_key_callback() {
|
||||
gui.run_post_callback_func();
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
void GUIHolder::input_text_input_callback() {
|
||||
gui.run_post_callback_func();
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
void GUIHolder::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
gui.input_mouse_button_callback(button);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ class GUIHolder {
|
|||
void update();
|
||||
void draw(SkCanvas* canvas, bool skiaAA);
|
||||
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
void input_text_key_callback();
|
||||
void input_text_input_callback();
|
||||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
|
|
|
|||
|
|
@ -348,6 +348,7 @@ void GUIManager::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
|||
for(ElementContainer* e : orderedElements)
|
||||
e->elem->input_key_callback(key);
|
||||
run_post_callback_func();
|
||||
layout_if_necessary();
|
||||
}
|
||||
|
||||
void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) {
|
||||
|
|
@ -378,6 +379,7 @@ void GUIManager::mouse_callback(const Vector2f& mousePos, const std::function<vo
|
|||
f(e, false);
|
||||
}
|
||||
run_post_callback_func();
|
||||
layout_if_necessary();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,12 +126,13 @@ void InputManager::remove_rich_text_box_input(const std::shared_ptr<RichText::Te
|
|||
text.update_accepting_input(main.window.sdlWindow);
|
||||
}
|
||||
|
||||
void InputManager::Text::add_text_to_textbox(const std::string& inputText) {
|
||||
if(!textBoxes.empty() && !inputText.empty()) {
|
||||
auto& frontTextBox = textBoxes.front();
|
||||
do_textbox_operation_with_undo([&]() {
|
||||
void InputManager::add_text_to_textbox(const std::string& inputText) {
|
||||
if(!text.textBoxes.empty() && !inputText.empty()) {
|
||||
auto& frontTextBox = text.textBoxes.front();
|
||||
text.do_textbox_operation_with_undo([&]() {
|
||||
frontTextBox.textBox->process_text_input(*frontTextBox.cursor, inputText, shared_ptr_to_opt(frontTextBox.modMap));
|
||||
});
|
||||
main.input_text_input_callback();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -990,8 +991,10 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
|||
break;
|
||||
}
|
||||
|
||||
if(text.is_accepting_input())
|
||||
if(text.is_accepting_input()) {
|
||||
main.input_text_key_callback();
|
||||
return;
|
||||
}
|
||||
|
||||
auto f = keyAssignments.find({make_generic_key_mod(kMod), kPress});
|
||||
if(f != keyAssignments.end()) {
|
||||
|
|
|
|||
|
|
@ -156,8 +156,6 @@ struct InputManager {
|
|||
struct Text {
|
||||
bool is_accepting_input();
|
||||
|
||||
void add_text_to_textbox(const std::string& inputText);
|
||||
|
||||
void add_textbox_undo(const RichText::TextBox::Cursor& prevCursor, const RichText::TextData& prevRichText);
|
||||
void do_textbox_operation_with_undo(const std::function<void()>& func);
|
||||
|
||||
|
|
@ -275,6 +273,8 @@ struct InputManager {
|
|||
void touch_finger_do_mouse_up(const SDL_TouchFingerEvent& f);
|
||||
void touch_finger_do_mouse_motion(const SDL_TouchFingerEvent& f);
|
||||
|
||||
void add_text_to_textbox(const std::string& inputText);
|
||||
|
||||
void backend_drop_file_event(const SDL_DropEvent& e);
|
||||
void backend_drop_text_event(const SDL_DropEvent& e);
|
||||
void backend_mouse_button_up_update(const SDL_MouseButtonEvent& e);
|
||||
|
|
|
|||
|
|
@ -354,6 +354,14 @@ void MainProgram::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
|||
world->input_key_callback(key);
|
||||
}
|
||||
|
||||
void MainProgram::input_text_key_callback() {
|
||||
g.input_text_key_callback();
|
||||
}
|
||||
|
||||
void MainProgram::input_text_input_callback() {
|
||||
g.input_text_input_callback();
|
||||
}
|
||||
|
||||
void MainProgram::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
g.input_mouse_button_callback(button);
|
||||
if(world)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,8 @@ class MainProgram {
|
|||
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
void input_text_key_callback();
|
||||
void input_text_input_callback();
|
||||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
|
|
|
|||
|
|
@ -558,6 +558,9 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
|
|||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
mS.m->update(); // Run update once to make sure that callbacks dont crash
|
||||
|
||||
#ifdef NDEBUG
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
|
|
@ -749,7 +752,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
mS.m->input.backend_key_up_update(event->key);
|
||||
break;
|
||||
case SDL_EVENT_TEXT_INPUT:
|
||||
mS.m->input.text.add_text_to_textbox(event->text.text);
|
||||
mS.m->input.add_text_to_textbox(event->text.text);
|
||||
break;
|
||||
case SDL_EVENT_DROP_FILE:
|
||||
mS.m->update_scale_and_density();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue