Merge pull request #104 from fedddddd/dev

Dev
This commit is contained in:
fed 2021-12-20 19:58:39 +01:00 committed by GitHub
commit 5cff45142c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 3 deletions

2
.gitmodules vendored
View File

@ -42,4 +42,4 @@
url = https://github.com/madler/zlib.git
[submodule "deps/imgui"]
path = deps/imgui
url = https://github.com/ocornut/imgui.git
url = https://github.com/fedddddd/imgui.git

2
deps/imgui vendored

@ -1 +1 @@
Subproject commit 0cdc4a956530cbe64a4e319446f8d9d2d7d149ee
Subproject commit f791ff33702d55603d182b586a2850418ec49e3d

View File

@ -20,6 +20,7 @@ namespace gui
namespace
{
utils::concurrency::container<std::vector<std::function<void()>>> on_frame_callbacks;
utils::concurrency::container<std::vector<notification_t>> notifications;
ID3D11Device* device;
ID3D11DeviceContext* device_context;
@ -58,8 +59,52 @@ namespace gui
enabled_menus[name] = !enabled_menus[name];
}
void show_notifications()
{
static auto window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove;
notifications.access([](std::vector<notification_t>& notifications_)
{
auto index = 0;
for (auto i = notifications_.begin(); i != notifications_.end(); ++i)
{
const auto now = std::chrono::high_resolution_clock::now();
if (now - i->creation_time >= i->duration)
{
notifications_.erase(i--);
continue;
}
const auto title = i->title.size() <= 34
? i->title
: i->title.substr(0, 31) + "...";
const auto text = i->text.size() <= 34
? i->text
: i->text.substr(0, 31) + "...";
ImGui::SetNextWindowSizeConstraints(ImVec2(250, 50), ImVec2(250, 50));
ImGui::SetNextWindowBgAlpha(0.6f);
ImGui::Begin(utils::string::va("Notification #%i", index), nullptr, window_flags);
ImGui::SetWindowPos(ImVec2(10, 30.f + static_cast<float>(index) * 60.f));
ImGui::SetWindowSize(ImVec2(250, 0));
ImGui::Text(title.data());
ImGui::Text(text.data());
ImGui::End();
index++;
}
});
}
void gui_draw()
{
show_notifications();
on_frame_callbacks.access([](std::vector<std::function<void()>>& callbacks)
{
for (const auto& callback : callbacks)
@ -180,6 +225,20 @@ namespace gui
return enabled_menus[name];
}
void notification(const std::string& title, const std::string& text, const std::chrono::milliseconds duration)
{
notification_t notification{};
notification.title = title;
notification.text = text;
notification.duration = duration;
notification.creation_time = std::chrono::high_resolution_clock::now();
notifications.access([notification](std::vector<notification_t>& notifications_)
{
notifications_.insert(notifications_.begin(), notification);
});
}
class component final : public component_interface
{
public:

View File

@ -2,6 +2,14 @@
namespace gui
{
struct notification_t
{
std::string title;
std::string text;
std::chrono::milliseconds duration{};
std::chrono::high_resolution_clock::time_point creation_time{};
};
extern std::unordered_map<std::string, bool> enabled_menus;
bool gui_key_event(const int local_client_num, const int key, const int down);
@ -10,4 +18,5 @@ namespace gui
void on_frame(const std::function<void()>& callback);
bool is_menu_open(const std::string& name);
void notification(const std::string& title, const std::string& text, const std::chrono::milliseconds duration = 3s);
}

View File

@ -81,6 +81,7 @@ namespace asset_list
if (ImGui::Button(asset_name))
{
utils::string::set_clipboard_data(asset_name);
gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", asset_name));
}
}, true);

View File

@ -466,7 +466,6 @@ namespace entity_list
}
catch (...)
{
}
}
@ -568,6 +567,7 @@ namespace entity_list
}
catch (...)
{
gui::notification("Error", utils::string::va("^1error setting field '%s'!", name.data()));
}
});
}
@ -589,6 +589,7 @@ namespace entity_list
}
catch (...)
{
gui::notification("Error", utils::string::va("^1error setting field '%s'!", name.data()));
}
});
}
@ -789,6 +790,7 @@ namespace entity_list
if (ImGui::Button(field.first.data()))
{
utils::string::set_clipboard_data(field.first);
gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", field.first.data()));
}
ImGui::SameLine();
@ -796,6 +798,7 @@ namespace entity_list
if (ImGui::Button(field.second.data()))
{
utils::string::set_clipboard_data(field.second);
gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", field.second.data()));
}
}