Pressing enter on textbox creates a new grid/bookmark
This commit is contained in:
parent
1849ffc730
commit
06ef26a1e9
4 changed files with 30 additions and 24 deletions
|
|
@ -6,7 +6,7 @@ namespace GUIStuff {
|
||||||
|
|
||||||
template <typename T> class TextBox : public Element {
|
template <typename T> class TextBox : public Element {
|
||||||
public:
|
public:
|
||||||
void update(UpdateInputData& io, T* newData, const std::function<std::optional<T>(const std::string&)>& newFromStr, const std::function<std::string(const T&)> newToStr, bool newSingleLine, bool updateEveryEdit, const std::function<void()>& elemUpdate) {
|
void update(UpdateInputData& io, T* newData, const std::function<std::optional<T>(const std::string&)>& newFromStr, const std::function<std::string(const T&)> newToStr, bool newSingleLine, bool updateEveryEdit, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
data = newData;
|
data = newData;
|
||||||
fromStr = newFromStr;
|
fromStr = newFromStr;
|
||||||
toStr = newToStr;
|
toStr = newToStr;
|
||||||
|
|
@ -129,7 +129,7 @@ template <typename T> class TextBox : public Element {
|
||||||
force_update_textbox(true);
|
force_update_textbox(true);
|
||||||
}
|
}
|
||||||
if(elemUpdate)
|
if(elemUpdate)
|
||||||
elemUpdate();
|
elemUpdate(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -273,14 +273,14 @@ void GUIManager::checkbox(const std::string& id, bool* val, const std::function<
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_text_field(const std::string& id, const std::string& name, std::string* val, const std::function<void()>& elemUpdate) {
|
void GUIManager::input_text_field(const std::string& id, const std::string& name, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
left_to_right_line_layout([&]() {
|
left_to_right_line_layout([&]() {
|
||||||
text_label(name);
|
text_label(name);
|
||||||
input_text(id, val, elemUpdate);
|
input_text(id, val, elemUpdate);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_path_field(const std::string& id, const std::string& name, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void()>& elemUpdate) {
|
void GUIManager::input_path_field(const std::string& id, const std::string& name, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
left_to_right_line_layout([&]() {
|
left_to_right_line_layout([&]() {
|
||||||
text_label(name);
|
text_label(name);
|
||||||
input_path(id, val, fileTypeRestriction, elemUpdate);
|
input_path(id, val, fileTypeRestriction, elemUpdate);
|
||||||
|
|
@ -303,7 +303,7 @@ bool GUIManager::radio_button_field(const std::string& id, const std::string& na
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_color_component_255(const std::string& id, float* val, const std::function<void()>& elemUpdate) {
|
void GUIManager::input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
insert_element<TextBox<float>>()->update(*io, val,
|
insert_element<TextBox<float>>()->update(*io, val,
|
||||||
[&](const std::string& str) {
|
[&](const std::string& str) {
|
||||||
|
|
@ -322,7 +322,7 @@ void GUIManager::input_color_component_255(const std::string& id, float* val, co
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_text(const std::string& id, std::string* val, const std::function<void()>& elemUpdate) {
|
void GUIManager::input_text(const std::string& id, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
insert_element<TextBox<std::string>>()->update(*io, val,
|
insert_element<TextBox<std::string>>()->update(*io, val,
|
||||||
[&](const std::string& str) {
|
[&](const std::string& str) {
|
||||||
|
|
@ -399,7 +399,7 @@ bool GUIManager::text_button_wide(const std::string& id, const std::string& text
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void()>& elemUpdate) {
|
void GUIManager::input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
insert_element<TextBox<uint8_t>>()->update(*io, val,
|
insert_element<TextBox<uint8_t>>()->update(*io, val,
|
||||||
[&](const std::string& a) {
|
[&](const std::string& a) {
|
||||||
|
|
@ -419,7 +419,7 @@ void GUIManager::input_scalar(const std::string& id, uint8_t* val, uint8_t min,
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void()>& elemUpdate) {
|
void GUIManager::input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
insert_element<TextBox<std::filesystem::path>>()->update(*io, val,
|
insert_element<TextBox<std::filesystem::path>>()->update(*io, val,
|
||||||
[&](const std::string& a) {
|
[&](const std::string& a) {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class GUIManager {
|
||||||
Vector2f screen_pos_to_window_pos(const Vector2f& screenPos);
|
Vector2f screen_pos_to_window_pos(const Vector2f& screenPos);
|
||||||
Vector2f get_mouse_pos();
|
Vector2f get_mouse_pos();
|
||||||
|
|
||||||
void input_text_field(const std::string& id, const std::string& name, std::string* val, const std::function<void()>& elemUpdate = nullptr);
|
void input_text_field(const std::string& id, const std::string& name, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||||
|
|
||||||
void text_label_color(const std::string& val, const SkColor4f& color);
|
void text_label_color(const std::string& val, const SkColor4f& color);
|
||||||
void text_label_size(const std::string& val, float modifier);
|
void text_label_size(const std::string& val, float modifier);
|
||||||
|
|
@ -68,8 +68,8 @@ class GUIManager {
|
||||||
void scroll_bar_area(const std::string& uniqueId, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate);
|
void scroll_bar_area(const std::string& uniqueId, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate);
|
||||||
void scroll_bar_many_entries_area(const std::string& uniqueId, float entryHeight, size_t entryCount, const std::function<void(size_t elementIndex, bool listHovered)>& entryUpdate, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate = nullptr);
|
void scroll_bar_many_entries_area(const std::string& uniqueId, float entryHeight, size_t entryCount, const std::function<void(size_t elementIndex, bool listHovered)>& entryUpdate, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate = nullptr);
|
||||||
|
|
||||||
void input_color_component_255(const std::string& id, float* val, const std::function<void()>& elemUpdate = nullptr);
|
void input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||||
void input_text(const std::string& id, std::string* val, const std::function<void()>& elemUpdate = nullptr);
|
void input_text(const std::string& id, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||||
|
|
||||||
bool radio_button(const std::string& id, bool val, const std::function<void()>& elemUpdate = nullptr);
|
bool radio_button(const std::string& id, bool val, const std::function<void()>& elemUpdate = nullptr);
|
||||||
bool radio_button_field(const std::string& id, const std::string& name, bool val, const std::function<void()>& elemUpdate = nullptr);
|
bool radio_button_field(const std::string& id, const std::string& name, bool val, const std::function<void()>& elemUpdate = nullptr);
|
||||||
|
|
@ -79,8 +79,8 @@ class GUIManager {
|
||||||
|
|
||||||
void tab_list(const std::string& id, const std::vector<std::pair<std::string, std::string>>& tabNames, size_t& selectedTab, std::optional<size_t>& closedTab, const std::function<void()>& elemUpdate = nullptr);
|
void tab_list(const std::string& id, const std::vector<std::pair<std::string, std::string>>& tabNames, size_t& selectedTab, std::optional<size_t>& closedTab, const std::function<void()>& elemUpdate = nullptr);
|
||||||
|
|
||||||
void input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void()>& elemUpdate = nullptr);
|
void input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||||
void input_path_field(const std::string& id, const std::string& name, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void()>& elemUpdate = nullptr);
|
void input_path_field(const std::string& id, const std::string& name, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||||
|
|
||||||
void dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width = 200.0f, const std::function<void()>& hoverboxElemUpdate = nullptr);
|
void dropdown_select(const std::string& id, size_t* val, const std::vector<std::string>& selections, float width = 200.0f, const std::function<void()>& hoverboxElemUpdate = nullptr);
|
||||||
|
|
||||||
|
|
@ -109,13 +109,13 @@ class GUIManager {
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void input_generic(const std::string& id, T* val, const std::function<std::optional<T>(const std::string&)>& fromStr, const std::function<std::string(const T&)>& toStr, bool singleLine, bool updateEveryEdit, const std::function<void()>& elemUpdate = nullptr) {
|
template <typename T> void input_generic(const std::string& id, T* val, const std::function<std::optional<T>(const std::string&)>& fromStr, const std::function<std::string(const T&)>& toStr, bool singleLine, bool updateEveryEdit, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
insert_element<TextBox<T>>()->update(*io, val, fromStr, toStr, singleLine, updateEveryEdit, elemUpdate);
|
insert_element<TextBox<T>>()->update(*io, val, fromStr, toStr, singleLine, updateEveryEdit, elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void input_scalar(const std::string& id, T* val, T min, T max, int decimalPrecision = 0, const std::function<void()>& elemUpdate = nullptr) {
|
template <typename T> void input_scalar(const std::string& id, T* val, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
input_generic<T>(id, val,
|
input_generic<T>(id, val,
|
||||||
[&](const std::string& a) {
|
[&](const std::string& a) {
|
||||||
if(a.empty())
|
if(a.empty())
|
||||||
|
|
@ -140,9 +140,9 @@ class GUIManager {
|
||||||
}, true, false, elemUpdate);
|
}, true, false, elemUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void()>& elemUpdate);
|
void input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void(SelectionHelper&)>& elemUpdate);
|
||||||
|
|
||||||
template <typename TContainer, typename T> void input_scalar_fields(const std::string& id, const std::string& name, TContainer* val, size_t elemCount, T min, T max, int decimalPrecision = 0, const std::function<void()>& elemUpdate = nullptr) {
|
template <typename TContainer, typename T> void input_scalar_fields(const std::string& id, const std::string& name, TContainer* val, size_t elemCount, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
left_to_right_line_layout([&]() {
|
left_to_right_line_layout([&]() {
|
||||||
text_label(name);
|
text_label(name);
|
||||||
|
|
@ -152,7 +152,7 @@ class GUIManager {
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void input_color_hex(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
template <typename T> void input_color_hex(const std::string& id, T* val, bool selectAlpha, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
input_generic<T>(id, val,
|
input_generic<T>(id, val,
|
||||||
[&](const std::string& str) {
|
[&](const std::string& str) {
|
||||||
T def = {0.0f, 0.0f, 0.0f, 1.0f};
|
T def = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
@ -201,7 +201,7 @@ class GUIManager {
|
||||||
pop_id();
|
pop_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void input_scalar_field(const std::string& id, const std::string& name, T* val, T min, T max, int decimalPrecision = 0, const std::function<void()>& elemUpdate = nullptr) {
|
template <typename T> void input_scalar_field(const std::string& id, const std::string& name, T* val, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||||
left_to_right_line_layout([&]() {
|
left_to_right_line_layout([&]() {
|
||||||
text_label(name);
|
text_label(name);
|
||||||
input_scalar(id, val, min, max, decimalPrecision, elemUpdate);
|
input_scalar(id, val, min, max, decimalPrecision, elemUpdate);
|
||||||
|
|
@ -212,7 +212,7 @@ class GUIManager {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
left_to_right_line_layout([&]() {
|
left_to_right_line_layout([&]() {
|
||||||
text_label(name);
|
text_label(name);
|
||||||
input_scalar("0", val, min, max, decimalPrecision, elemUpdate);
|
input_scalar("0", val, min, max, decimalPrecision, nullptr);
|
||||||
});
|
});
|
||||||
slider_scalar("1", val, min, max, elemUpdate);
|
slider_scalar("1", val, min, max, elemUpdate);
|
||||||
pop_id();
|
pop_id();
|
||||||
|
|
|
||||||
|
|
@ -715,8 +715,11 @@ void Toolbar::grid_menu(bool justOpened) {
|
||||||
if(toDelete != ServerClientID{0, 0})
|
if(toDelete != ServerClientID{0, 0})
|
||||||
main.world->gridMan.remove_grid(toDelete);
|
main.world->gridMan.remove_grid(toDelete);
|
||||||
gui.left_to_right_line_layout([&]() {
|
gui.left_to_right_line_layout([&]() {
|
||||||
gui.input_text("grid text input", &gridMenu.newName);
|
bool addByEnter = false;
|
||||||
if(gui.svg_icon_button("grid add button", "data/icons/plus.svg", false, 25.0f)) {
|
gui.input_text("grid text input", &gridMenu.newName, [&](GUIStuff::SelectionHelper& s) {
|
||||||
|
addByEnter = s.selected && io->key.enter;
|
||||||
|
});
|
||||||
|
if(gui.svg_icon_button("grid add button", "data/icons/plus.svg", false, 25.0f) || (addByEnter && !gridMenu.newName.empty())) {
|
||||||
main.world->drawProg.modify_grid(main.world->gridMan.add_default_grid(gridMenu.newName));
|
main.world->drawProg.modify_grid(main.world->gridMan.add_default_grid(gridMenu.newName));
|
||||||
stop_displaying_grid_menu();
|
stop_displaying_grid_menu();
|
||||||
}
|
}
|
||||||
|
|
@ -797,9 +800,12 @@ void Toolbar::bookmark_menu(bool justOpened) {
|
||||||
main.world->bMan.remove_bookmark(toDelete);
|
main.world->bMan.remove_bookmark(toDelete);
|
||||||
bool bookmarkExists = std::find(main.world->bMan.sorted_names().begin(), main.world->bMan.sorted_names().end(), bookMenu.newName) != main.world->bMan.sorted_names().end();
|
bool bookmarkExists = std::find(main.world->bMan.sorted_names().begin(), main.world->bMan.sorted_names().end(), bookMenu.newName) != main.world->bMan.sorted_names().end();
|
||||||
gui.left_to_right_line_layout([&]() {
|
gui.left_to_right_line_layout([&]() {
|
||||||
gui.input_text("bookmark text input", &bookMenu.newName);
|
bool addByEnter = false;
|
||||||
|
gui.input_text("bookmark text input", &bookMenu.newName, [&](GUIStuff::SelectionHelper& s) {
|
||||||
|
addByEnter = s.selected && io->key.enter;
|
||||||
|
});
|
||||||
if(!bookmarkExists) {
|
if(!bookmarkExists) {
|
||||||
if(gui.svg_icon_button("bookmark add button", "data/icons/plus.svg", false, 25.0f) && !bookMenu.newName.empty())
|
if((gui.svg_icon_button("bookmark add button", "data/icons/plus.svg", false, 25.0f) || addByEnter) && !bookMenu.newName.empty())
|
||||||
main.world->bMan.add_bookmark(bookMenu.newName);
|
main.world->bMan.add_bookmark(bookMenu.newName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue