Skip to content

Commit

Permalink
⬆ [ImGuiNotify]
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Nov 23, 2024
1 parent 61f30cf commit fe3bc7e
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 42 deletions.
11 changes: 6 additions & 5 deletions src/Cool/AppManager/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ void AppManager::update()
{
// Cache these colors for the frame, because we don't want to query the Theme all the time.
// They will be reused by a few things event outside of ImGui::Notify
ImGui::Notify::style().success = user_settings().color_themes.editor().get_color("Success").as_imvec4();
ImGui::Notify::style().warning = user_settings().color_themes.editor().get_color("Warning").as_imvec4();
ImGui::Notify::style().error = user_settings().color_themes.editor().get_color("Error").as_imvec4();
ImGui::Notify::style().info = user_settings().color_themes.editor().get_color("Accent").as_imvec4();
ImGuiNotify::get_style().color_success = user_settings().color_themes.editor().get_color("Success").as_imvec4();
ImGuiNotify::get_style().color_warning = user_settings().color_themes.editor().get_color("Warning").as_imvec4();
ImGuiNotify::get_style().color_error = user_settings().color_themes.editor().get_color("Error").as_imvec4();
ImGuiNotify::get_style().color_info = user_settings().color_themes.editor().get_color("Accent").as_imvec4();
ImGuiNotify::get_style().color_title_background = ImGui::GetStyleColorVec4(ImGuiCol_MenuBarBg);

ImGui::GetIO().ConfigDragClickToInputText = user_settings().single_click_to_input_in_drag_widgets;
prepare_windows(_window_manager);
Expand Down Expand Up @@ -243,7 +244,7 @@ void AppManager::imgui_render(IApp& app)
// Windows
app.imgui_windows();
imgui_windows();
ImGui::Notify::render_windows();
ImGuiNotify::render_windows();

ImGui::PopStyleVar();
ImGui::PopFont();
Expand Down
12 changes: 5 additions & 7 deletions src/Cool/DebugOptions/TestNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ TestNotification::TestNotification()
void TestNotification::imgui()
{
if (ImGui::Button("Send "))
ImGui::Notify::add({.type = _type, .content = std::to_string(i++)});
ImGuiNotify::send({.type = _type, .content = std::to_string(i++)});
if (ImGui::Button("Error"))
ImGui::Notify::add({.type = ImGui::Notify::ToastType::Error, .content = "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello"});
ImGuiNotify::send({.type = ImGuiNotify::Type::Error, .content = "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello"});
if (ImGui::Button("Warning"))
ImGui::Notify::add({.type = ImGui::Notify::ToastType::Warning, .content = "Hello"});
ImGuiNotify::send({.type = ImGuiNotify::Type::Warning, .title = "Warning", .content = "Hello"});
if (ImGui::Button("Success"))
ImGui::Notify::add({.type = ImGui::Notify::ToastType::Success, .content = "Hello"});
ImGuiNotify::send({.type = ImGuiNotify::Type::Success, .content = "Hello"});
if (ImGui::Button("Info"))
ImGui::Notify::add({.type = ImGui::Notify::ToastType::Info, .content = "Hello"});
if (ImGui::Button("None"))
ImGui::Notify::add({.type = ImGui::Notify::ToastType::None, .content = "Hello"});
ImGuiNotify::send({.type = ImGuiNotify::Type::Info, .content = "Hello"});
}

} // namespace Cool
6 changes: 3 additions & 3 deletions src/Cool/DebugOptions/TestNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class TestNotification {
void imgui();

private:
std::string _message{"Hello"};
ImGui::Notify::ToastType _type{ImGui::Notify::ToastType::Success};
int i{0};
std::string _message{"Hello"};
ImGuiNotify::Type _type{ImGuiNotify::Type::Success};
int i{0};
};

} // namespace Cool
2 changes: 1 addition & 1 deletion src/Cool/Exporter/Exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Exporter {

void set_shared_aspect_ratio(SharedAspectRatio& shared_aspect_ratio) { _gui.set_shared_aspect_ratio(shared_aspect_ratio); }

[[nodiscard]] auto export_image_immediately(Time time, Time delta_time, Polaroid const& polaroid, std::function<void(std::filesystem::path const& exported_image_path)> const& on_image_exported) -> bool;
auto export_image_immediately(Time time, Time delta_time, Polaroid const& polaroid, std::function<void(std::filesystem::path const& exported_image_path)> const& on_image_exported) -> bool;

private:
ExporterGui _gui{};
Expand Down
12 changes: 6 additions & 6 deletions src/Cool/Exporter/ExporterU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ auto export_image(img::Size size, Time time, Time delta_time, Polaroid const& po

void notification_after_export_success(std::filesystem::path const& path, bool is_video)
{
ImGui::Notify::add({
.type = ImGui::Notify::ToastType::Success,
ImGuiNotify::send({
.type = ImGuiNotify::Type::Success,
.title = "Export Success",
.custom_imgui_content = [=]() {
ImGui::TextUnformatted(Cool::File::file_name(path).string().c_str());
Expand All @@ -40,17 +40,17 @@ void notification_after_export_success(std::filesystem::path const& path, bool i

void notification_after_export_failure()
{
ImGui::Notify::add({
.type = ImGui::Notify::ToastType::Error,
ImGuiNotify::send({
.type = ImGuiNotify::Type::Error,
.title = "Export Failed",
.content = "Maybe you are not allowed to save files in this folder?",
});
}

void notification_after_export_interrupted()
{
ImGui::Notify::add({
.type = ImGui::Notify::ToastType::Warning,
ImGuiNotify::send({
.type = ImGuiNotify::Type::Warning,
.title = "Export Cancelled",
});
}
Expand Down
20 changes: 10 additions & 10 deletions src/Cool/ImGui/ImGuiExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool slider_uint32(const char* label, uint32_t* v, uint32_t v_min, uint32_t v_ma

void warning_text(const char* text)
{
ImGui::TextColored(ImGui::Notify::style().warning, "%s", text);
ImGui::TextColored(ImGuiNotify::get_style().color_warning, "%s", text);
}

bool begin_popup_context_menu_from_button(const char* label, ImGuiPopupFlags popup_flags)
Expand Down Expand Up @@ -621,19 +621,19 @@ static auto highlight_color(float opacity) -> ImVec4
return col;
}

void background(std::function<void()> const& widget, ImVec4 color)
void background(ImVec4 color, std::function<void()> const& widget)
{
ImDrawList& draw_list = *ImGui::GetWindowDrawList();
draw_list.ChannelsSplit(2); // Allows us to draw the highlight rectangle behind the widget,
draw_list.ChannelsSetCurrent(1); // even though the widget is drawn first.
const auto rectangle_start_pos = ImGui::GetCursorScreenPos(); // We must draw them in that order because we need to know the height of the widget before drawing the rectangle.
draw_list.ChannelsSplit(2); // Allows us to draw the background rectangle behind the widget,
draw_list.ChannelsSetCurrent(1); // even though the widget is drawn first.
ImVec2 const rectangle_start_pos = ImGui::GetCursorScreenPos(); // We must draw them in that order because we need to know the height of the widget before drawing the rectangle.

widget();

const auto rectangle_end_pos = ImVec2(
auto const rectangle_end_pos = ImVec2{
rectangle_start_pos.x + ImGui::GetContentRegionAvail().x,
ImGui::GetCursorScreenPos().y
);
ImGui::GetCursorScreenPos().y,
};
draw_list.ChannelsSetCurrent(0);
draw_list.AddRectFilled(
rectangle_start_pos,
Expand All @@ -646,8 +646,8 @@ void background(std::function<void()> const& widget, ImVec4 color)
void highlight(std::function<void()> const& widget, float opacity)
{
background(
widget,
highlight_color(opacity)
highlight_color(opacity),
widget
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cool/ImGui/ImGuiExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ auto hue_wheel(const char* label, float* hue, float radius = 25.f) -> bool;

/// Renders `widget` with a colored background.
/// `widget` must be a function that draws some ImGui widgets.
void background(std::function<void()> const& widget, ImVec4 color);
void background(ImVec4 color, std::function<void()> const& widget);

/// Renders `widget` with a highlighted background.
/// `widget` must be a function that draws some ImGui widgets.
Expand Down
12 changes: 6 additions & 6 deletions src/Cool/Log/MessageConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ static auto color(MessageSeverity severity) -> ImVec4
switch (severity)
{
case MessageSeverity::Info:
return ImGui::Notify::style().success;
return ImGuiNotify::get_style().color_success;
case MessageSeverity::Warning:
return ImGui::Notify::style().warning;
return ImGuiNotify::get_style().color_warning;
case MessageSeverity::Error:
return ImGui::Notify::style().error;
return ImGuiNotify::get_style().color_error;
default:
Log::Debug::error("MessageConsole::color", "Unknown enum value");
return ImVec4{0, 0, 0, 0};
Expand All @@ -132,7 +132,7 @@ static auto color(MessageSeverity severity) -> ImVec4
static auto fade_out_if(bool condition, ImVec4 color) -> ImVec4
{
if (condition)
color.w = 0.75f;
color = ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled);

return color;
}
Expand Down Expand Up @@ -218,8 +218,8 @@ void MessageConsole::imgui_window()

// Menu bar
ImGuiExtras::background(
[&]() { imgui_menu_bar(); },
ImVec4{0.3f, 0.3f, 0.3f, 0.5f}
ImGuiNotify::get_style().color_title_background,
[&]() { imgui_menu_bar(); }
);
ImGui::Separator();

Expand Down
4 changes: 2 additions & 2 deletions src/Cool/Window/internal/WindowFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void imgui_load_fonts()
config.MergeMode = true;
config.PixelSnapH = true;
config.GlyphOffset = ImVec2{-4.f, +1.f};
// config.GlyphMinAdvanceX = font_size; // Use if you want to make the icon monospaced
// config.GlyphMinAdvanceX = icons_size; // Use if you want to make the icons monospaced
static const ImWchar icon_ranges[] = {BEGIN_RANGE_ICOMOON, END_RANGE_ICOMOON, 0}; // NOLINT(*-avoid-c-arrays)
static const ImWchar icon_ranges_for_info[] = {INFO_RANGE_ICOMOON, INFO_RANGE_ICOMOON + 1, 0}; // NOLINT(*-avoid-c-arrays)

Expand Down Expand Up @@ -88,7 +88,7 @@ static void imgui_load_fonts()
auto const path = Cool::Path::cool_res() / "fonts/Satoshi/Fonts/Satoshi-Regular.otf";
Font::regular() = io.Fonts->AddFontFromFileTTF(path.string().c_str(), font_size);
merge_icons_into_current_font();
ImGui::Notify::add_icons_to_current_font(icons_size);
ImGuiNotify::add_icons_to_current_font(icons_size, ImVec2{0.f, 0.f});
}

io.Fonts->Build();
Expand Down

0 comments on commit fe3bc7e

Please sign in to comment.