Skip to content

Commit 1f6bdc8

Browse files
committed
Rename to "Toast" and code cleanup
1 parent bb9f935 commit 1f6bdc8

File tree

5 files changed

+56
-57
lines changed

5 files changed

+56
-57
lines changed

src/common/ImGuiNotify.hpp src/common/ImGuiNotify.h

+52-52
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static const ImGuiWindowFlags NOTIFY_DEFAULT_TOAST_FLAGS =
5353
va_end(args); \
5454
}
5555

56-
enum class ToastNotificationType : uint8_t
56+
enum class ToastType : uint8_t
5757
{
5858
None,
5959
Success,
@@ -87,12 +87,12 @@ enum class ImNotifyToastPos : uint8_t
8787
/**
8888
* @brief A class for creating toast notifications with ImGui.
8989
*/
90-
class ToastNotification
90+
class Toast
9191
{
9292
private:
9393
ImGuiWindowFlags flags = NOTIFY_DEFAULT_TOAST_FLAGS;
9494

95-
ToastNotificationType type = ToastNotificationType::None;
95+
ToastType type = ToastType::None;
9696
char title[NOTIFY_MAX_MSG_LENGTH];
9797
char content[NOTIFY_MAX_MSG_LENGTH];
9898

@@ -137,9 +137,9 @@ class ToastNotification
137137
*
138138
* @param type The type of the toast notification.
139139
*/
140-
inline void setType(const ToastNotificationType& type)
140+
inline void setType(const ToastType& type)
141141
{
142-
IM_ASSERT(type < ToastNotificationType::COUNT);
142+
IM_ASSERT(type < ToastType::COUNT);
143143
this->type = type;
144144
};
145145

@@ -186,11 +186,11 @@ class ToastNotification
186186
{
187187
switch (this->type)
188188
{
189-
case ToastNotificationType::None: return nullptr;
190-
case ToastNotificationType::Success: return "Success";
191-
case ToastNotificationType::Warning: return "Warning";
192-
case ToastNotificationType::Error: return "Error";
193-
case ToastNotificationType::Info: return "Info";
189+
case ToastType::None: return nullptr;
190+
case ToastType::Success: return "Success";
191+
case ToastType::Warning: return "Warning";
192+
case ToastType::Error: return "Error";
193+
case ToastType::Info: return "Info";
194194
default: return nullptr;
195195
}
196196
}
@@ -203,7 +203,7 @@ class ToastNotification
203203
*
204204
* @return ImGuiToastType The type of the toast notification.
205205
*/
206-
inline ToastNotificationType getType() { return this->type; };
206+
inline ToastType getType() { return this->type; };
207207

208208
/**
209209
* @brief Get the color of the toast notification based on its type.
@@ -214,11 +214,11 @@ class ToastNotification
214214
{
215215
switch (this->type)
216216
{
217-
case ToastNotificationType::None: return {255, 255, 255, 255}; // White
218-
case ToastNotificationType::Success: return {0, 255, 0, 255}; // Green
219-
case ToastNotificationType::Warning: return {255, 255, 0, 255}; // Yellow
220-
case ToastNotificationType::Error: return {255, 0, 0, 255}; // Error
221-
case ToastNotificationType::Info: return {0, 157, 255, 255}; // Blue
217+
case ToastType::None: return {255, 255, 255, 255}; // White
218+
case ToastType::Success: return {0, 255, 0, 255}; // Green
219+
case ToastType::Warning: return {255, 255, 0, 255}; // Yellow
220+
case ToastType::Error: return {255, 0, 0, 255}; // Error
221+
case ToastType::Info: return {0, 157, 255, 255}; // Blue
222222
default: return {255, 255, 255, 255}; // White
223223
}
224224
}
@@ -232,11 +232,11 @@ class ToastNotification
232232
{
233233
switch (this->type)
234234
{
235-
case ToastNotificationType::None: return nullptr;
236-
case ToastNotificationType::Success: return ICON_MD_CHECK_CIRCLE; // Font Awesome 6
237-
case ToastNotificationType::Warning: return ICON_MD_ALERT; // Font Awesome 6
238-
case ToastNotificationType::Error: return ICON_MD_ALERT_DECAGRAM; // Font Awesome 6
239-
case ToastNotificationType::Info: return ICON_MD_INFORMATION; // Font Awesome 6
235+
case ToastType::None: return nullptr;
236+
case ToastType::Success: return ICON_MD_CHECK_CIRCLE; // Font Awesome 6
237+
case ToastType::Warning: return ICON_MD_ALERT; // Font Awesome 6
238+
case ToastType::Error: return ICON_MD_ALERT_DECAGRAM; // Font Awesome 6
239+
case ToastType::Info: return ICON_MD_INFORMATION; // Font Awesome 6
240240
default: return nullptr;
241241
}
242242
}
@@ -327,14 +327,14 @@ class ToastNotification
327327
// Constructors
328328

329329
/**
330-
* @brief Creates a new ToastNotification object with the specified type and dismiss time.
330+
* @brief Creates a new Toast object with the specified type and dismiss time.
331331
*
332332
* @param type The type of the toast.
333333
* @param dismissTime The time in milliseconds after which the toast should be dismissed. Default is NOTIFY_DEFAULT_DISMISS.
334334
*/
335-
ToastNotification(ToastNotificationType type, int dismissTime = NOTIFY_DEFAULT_DISMISS)
335+
Toast(ToastType type, int dismissTime = NOTIFY_DEFAULT_DISMISS)
336336
{
337-
IM_ASSERT(type < ToastNotificationType::COUNT);
337+
IM_ASSERT(type < ToastType::COUNT);
338338

339339
this->type = type;
340340
this->dismissTime = dismissTime;
@@ -346,55 +346,55 @@ class ToastNotification
346346
}
347347

348348
/**
349-
* @brief Constructor for creating an ToastNotification object with a specified type and message format.
349+
* @brief Constructor for creating an Toast object with a specified type and message format.
350350
*
351351
* @param type The type of the toast message.
352352
* @param format The format string for the message.
353353
* @param ... The variable arguments to be formatted according to the format string.
354354
*/
355-
ToastNotification(ToastNotificationType type, const char* format, ...)
356-
: ToastNotification(type)
355+
Toast(ToastType type, const char* format, ...)
356+
: Toast(type)
357357
{
358358
NOTIFY_FORMAT(this->setContent, format);
359359
}
360360

361-
/* @brief Constructor for creating an ToastNotification object with a specified type and std::string message.
361+
/* @brief Constructor for creating an Toast object with a specified type and std::string message.
362362
* @param dismissTime The time in milliseconds before the toast message is dismissed.
363363
* @param message The message to be displayed in the toast.
364364
*/
365-
ToastNotification(ToastNotificationType type, const std::string& message)
366-
: ToastNotification(type)
365+
Toast(ToastType type, const std::string& message)
366+
: Toast(type)
367367
{
368368
this->setContent(message);
369369
}
370370

371371
/**
372-
* @brief Constructor for creating a new ToastNotification object with a specified type, dismiss time, and content format.
372+
* @brief Constructor for creating a new Toast object with a specified type, dismiss time, and content format.
373373
*
374374
* @param type The type of the toast message.
375375
* @param dismissTime The time in milliseconds before the toast message is dismissed.
376376
* @param format The format string for the content of the toast message.
377377
* @param ... The variable arguments to be formatted according to the format string.
378378
*/
379-
ToastNotification(ToastNotificationType type, int dismissTime, const char* format, ...)
380-
: ToastNotification(type, dismissTime)
379+
Toast(ToastType type, int dismissTime, const char* format, ...)
380+
: Toast(type, dismissTime)
381381
{
382382
NOTIFY_FORMAT(this->setContent, format);
383383
}
384384

385-
/* @brief Constructor for creating an ToastNotification object with a specified type, dismiss time, and std::string message.
385+
/* @brief Constructor for creating an Toast object with a specified type, dismiss time, and std::string message.
386386
* @param type The type of the toast message.
387387
* @param dismissTime The time in milliseconds before the toast message is dismissed.
388388
* @param message The message to be displayed in the toast.
389389
*/
390-
ToastNotification(ToastNotificationType type, int dismissTime, const std::string& message)
391-
: ToastNotification(type, dismissTime)
390+
Toast(ToastType type, int dismissTime, const std::string& message)
391+
: Toast(type, dismissTime)
392392
{
393393
this->setContent(message);
394394
}
395395

396396
/**
397-
* @brief Constructor for creating a new ToastNotification object with a specified type, dismiss time, title format, content format and a button.
397+
* @brief Constructor for creating a new Toast object with a specified type, dismiss time, title format, content format and a button.
398398
*
399399
* @param type The type of the toast message.
400400
* @param dismissTime The time in milliseconds before the toast message is dismissed.
@@ -403,8 +403,8 @@ class ToastNotification
403403
* @param format The format string for the content of the toast message.
404404
* @param ... The variable arguments to be formatted according to the format string.
405405
*/
406-
ToastNotification(ToastNotificationType type, int dismissTime, const char* buttonLabel, const std::function<void()>& onButtonPress, const char* format, ...)
407-
: ToastNotification(type, dismissTime)
406+
Toast(ToastType type, int dismissTime, const char* buttonLabel, const std::function<void()>& onButtonPress, const char* format, ...)
407+
: Toast(type, dismissTime)
408408
{
409409
NOTIFY_FORMAT(this->setContent, format);
410410

@@ -415,13 +415,13 @@ class ToastNotification
415415

416416
namespace ImGui
417417
{
418-
inline std::vector<ToastNotification> notifications;
418+
inline std::vector<Toast> notifications;
419419

420420
/**
421421
* Inserts a new notification into the notification queue.
422422
* @param toast The notification to be inserted.
423423
*/
424-
inline void InsertNotification(const ToastNotification& toast)
424+
inline void InsertNotification(const Toast& toast)
425425
{
426426
notifications.push_back(toast);
427427
}
@@ -449,7 +449,7 @@ inline void RenderNotifications()
449449

450450
for (size_t i = 0; i < notifications.size(); ++i)
451451
{
452-
ToastNotification* currentToast = &notifications[i];
452+
Toast* currentToast = &notifications[i];
453453

454454
// Remove toast if expired
455455
if (currentToast->getPhase() == ImNotifyToastPhase::Expired)
@@ -623,24 +623,24 @@ inline void RenderNotifications()
623623
namespace sol_ToastNotification
624624
{
625625
// rename this to be more user friendly
626-
inline void ShowToast(const ToastNotification& toast)
626+
inline void ShowToast(const Toast& toast)
627627
{
628628
ImGui::InsertNotification(toast);
629629
}
630630

631631
inline void BindImNotifyToast(sol::table aTable)
632632
{
633-
aTable.new_usertype<ToastNotification>(
634-
"ToastNotification",
635-
sol::constructors<ToastNotification(ToastNotificationType),ToastNotification(ToastNotificationType, int),ToastNotification(ToastNotificationType,const std::string&),ToastNotification(ToastNotificationType,int,const std::string&)>(),
636-
"SetTitle", sol::resolve<void(const std::string&)>(&ToastNotification::setTitle),
637-
"SetContent", sol::resolve<void(const std::string&)>(&ToastNotification::setContent),
638-
"SetType", &ToastNotification::setType,
639-
"SetWindowFlags", &ToastNotification::setWindowFlags);
633+
aTable.new_usertype<Toast>(
634+
"Toast",
635+
sol::constructors<Toast(ToastType),Toast(ToastType, int),Toast(ToastType,const std::string&),Toast(ToastType,int,const std::string&)>(),
636+
"SetTitle", sol::resolve<void(const std::string&)>(&Toast::setTitle),
637+
"SetContent", sol::resolve<void(const std::string&)>(&Toast::setContent),
638+
"SetType", &Toast::setType,
639+
"SetWindowFlags", &Toast::setWindowFlags);
640640

641641
aTable.new_enum(
642-
"ToastNotificationType", "None", ToastNotificationType::None, "Success", ToastNotificationType::Success, "Warning", ToastNotificationType::Warning, "Error", ToastNotificationType::Error, "Info", ToastNotificationType::Info);
642+
"ToastType", "None", ToastType::None, "Success", ToastType::Success, "Warning", ToastType::Warning, "Error", ToastType::Error, "Info", ToastType::Info);
643643

644644
aTable.set_function("ShowToast", ShowToast);
645645
}
646-
} // namespace sol_ToastNotification
646+
} // namespace sol_Toast

src/overlay/Overlay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void Overlay::PostInitialize()
2323
else
2424
{
2525
const auto cOverlayBindCode = CET::Get().GetBindings().GetBindCodeForModBind(Bindings::GetOverlayToggleModBind());
26-
ImGui::InsertNotification({ToastNotificationType::Info, NOTIFY_DEFAULT_DISMISS, "CET Overlay Bind: %s", VKBindings::GetBindString(cOverlayBindCode).c_str()});
26+
ImGui::InsertNotification({ToastType::Info, NOTIFY_DEFAULT_DISMISS, "CET Overlay Bind: %s", VKBindings::GetBindString(cOverlayBindCode).c_str()});
2727
}
2828

2929
m_initialized = true;

src/scripting/LuaSandbox.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ static constexpr const char* s_cGlobalObjectsWhitelist[] = {
7676
"ImGuiCol",
7777
"ImGuiDir",
7878
"ImVec2",
79-
"ImVec4"
80-
};
79+
"ImVec4"};
8180

8281
static constexpr const char* s_cPostInitializeScriptingProtectedList[] = {
8382
// initialized by Scripting

src/stdafx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
#include "CETVersion.h"
7171
#include "common/Logging.h"
7272
#include "common/FontMaterialDesignIcons.h"
73-
#include "common/ImGuiNotify.hpp"
73+
#include "common/ImGuiNotify.h"
7474
#include "Options.h"
7575
#include "Paths.h"
7676
#include "PersistentState.h"

xmake.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ target("cyber_engine_tweaks")
6969
set_kind("shared")
7070
set_filename("cyber_engine_tweaks.asi")
7171
add_files("src/**.cpp")
72-
add_headerfiles("src/**.h", "src/**.hpp", "build/CETVersion.h")
72+
add_headerfiles("src/**.h", "build/CETVersion.h")
7373
add_includedirs("src/", "build/")
7474
add_syslinks("User32", "Version", "d3d11", "dxgi")
7575
add_packages("spdlog", "nlohmann_json", "minhook", "hopscotch-map", "imgui", "mem", "sol2", "tiltedcore", "sqlite3", "openrestry-luajit", "xbyak", "stb")

0 commit comments

Comments
 (0)