Compare commits
No commits in common. "fe2e237a7008c94cab317eab0cf6e83b9ad2411a" and "603d3165bb0b9b3fe6fcdb0ca1afc613b5387274" have entirely different histories.
fe2e237a70
...
603d3165bb
|
@ -1,7 +1,6 @@
|
|||
#include <imgui/imgui.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include "../misc.h"
|
||||
#include "../group_panel.h"
|
||||
#include "../filters.h"
|
||||
#include "ok_buttons_fragment.h"
|
||||
|
@ -14,8 +13,7 @@ static inline void render_priority_filter(PriorityFilter* filter);
|
|||
static inline void render_group_filter(GroupFilter* filter);
|
||||
static std::unique_ptr<Filter> render_add_filter_popup();
|
||||
|
||||
static void render_filter(Filter* filter, std::string* title, bool* request_removal,
|
||||
auto move_up, auto move_down, bool can_move_up, bool can_move_down) {
|
||||
static void render_filter(Filter* filter, std::string* title, bool* request_removal) {
|
||||
ImGui::PushID(filter);
|
||||
ImGui::BeginGroupPanel();
|
||||
|
||||
|
@ -44,15 +42,6 @@ static void render_filter(Filter* filter, std::string* title, bool* request_remo
|
|||
*request_removal = true;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::ArrowButton("##up", ImGuiDir_Up, can_move_up)) {
|
||||
move_up();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::ArrowButton("##down", ImGuiDir_Down, can_move_down)) {
|
||||
move_down();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::SameLine();
|
||||
bool disabled = filter->disabled();
|
||||
|
@ -75,7 +64,7 @@ static void render_filter(Filter* filter, std::string* title, bool* request_remo
|
|||
}
|
||||
|
||||
if (filter->error()) {
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("(%s)", filter->error()->c_str());
|
||||
}
|
||||
|
||||
|
@ -106,8 +95,8 @@ static inline void render_integer_filter(IntegerFilter* filter) {
|
|||
};
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text("%s is%s:", head, filter->inverted ? " not" : "");
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::Text("%s is%s", head, filter->inverted ? " not" : "");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputScalar("##int", ImGuiDataType_U64, &filter->other)) {
|
||||
filter->updated();
|
||||
}
|
||||
|
@ -123,48 +112,46 @@ static inline void render_string_filter(StringFilter* filter) {
|
|||
};
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text("%s %s:", head, filter->exact_match
|
||||
ImGui::Text("%s %s", head, filter->exact_match
|
||||
? (filter->inverted ? "is not" : "is")
|
||||
: (filter->inverted ? "doesn't have" : "has"));
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputText("##str", &filter->other)) {
|
||||
filter->updated();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void render_buffer_filter(BufferFilter* filter) {
|
||||
auto add_checkbox = [&](const char* name, Buffer buffer) {
|
||||
if (ImGui::CheckboxFlags(name, &filter->wanted, static_cast<unsigned int>(buffer))) {
|
||||
auto update_if_needed = [&](bool updated) {
|
||||
if (updated) {
|
||||
filter->updated();
|
||||
}
|
||||
};
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::TextUnformatted("Buffer is:"); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
add_checkbox("Unknown", Buffer::Unknown); ImGui::SameLine();
|
||||
add_checkbox("Main", Buffer::Main); ImGui::SameLine();
|
||||
add_checkbox("System", Buffer::System); ImGui::SameLine();
|
||||
add_checkbox("Radio", Buffer::Radio); ImGui::SameLine();
|
||||
add_checkbox("Events", Buffer::Events); ImGui::SameLine();
|
||||
add_checkbox("Crash", Buffer::Crash);
|
||||
ImGui::TextUnformatted("Buffer is:"); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Unknown", &filter->wanted, static_cast<unsigned int>(Buffer::Unknown))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Main", &filter->wanted, static_cast<unsigned int>(Buffer::Main))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("System", &filter->wanted, static_cast<unsigned int>(Buffer::System))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Radio", &filter->wanted, static_cast<unsigned int>(Buffer::Radio))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Events", &filter->wanted, static_cast<unsigned int>(Buffer::Events))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Crash", &filter->wanted, static_cast<unsigned int>(Buffer::Crash)));
|
||||
}
|
||||
|
||||
static inline void render_priority_filter(PriorityFilter* filter) {
|
||||
auto add_checkbox = [&](const char* name, Priority priority) {
|
||||
if (ImGui::CheckboxFlags(name, &filter->wanted, static_cast<unsigned int>(priority))) {
|
||||
auto update_if_needed = [&](bool updated) {
|
||||
if (updated) {
|
||||
filter->updated();
|
||||
}
|
||||
};
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::TextUnformatted("Priority is:"); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
add_checkbox("Unknown", Priority::Unknown); ImGui::SameLine();
|
||||
add_checkbox("Verbose", Priority::Verbose); ImGui::SameLine();
|
||||
add_checkbox("Debug", Priority::Debug); ImGui::SameLine();
|
||||
add_checkbox("Info", Priority::Info); ImGui::SameLine();
|
||||
add_checkbox("Warning", Priority::Warn); ImGui::SameLine();
|
||||
add_checkbox("Error", Priority::Error); ImGui::SameLine();
|
||||
add_checkbox("Fatal", Priority::Fatal);
|
||||
ImGui::TextUnformatted("Priority is:"); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Unknown", &filter->wanted, static_cast<unsigned int>(Priority::Unknown))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Verbose", &filter->wanted, static_cast<unsigned int>(Priority::Verbose))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Debug", &filter->wanted, static_cast<unsigned int>(Priority::Debug))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Info", &filter->wanted, static_cast<unsigned int>(Priority::Info))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Warning", &filter->wanted, static_cast<unsigned int>(Priority::Warn))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Error", &filter->wanted, static_cast<unsigned int>(Priority::Error))); ImGui::SameLine();
|
||||
update_if_needed(ImGui::CheckboxFlags("Fatal", &filter->wanted, static_cast<unsigned int>(Priority::Fatal)));
|
||||
}
|
||||
|
||||
static inline void render_group_filter(GroupFilter* filter) {
|
||||
|
@ -173,28 +160,16 @@ static inline void render_group_filter(GroupFilter* filter) {
|
|||
filter->type = static_cast<GroupFilter::Type>(selected_type);
|
||||
}
|
||||
|
||||
std::vector<std::pair<size_t, size_t>> swaps_to_do;
|
||||
std::vector<size_t> removals_to_do;
|
||||
for (size_t i = 0; i < filter->filters.size(); i++) {
|
||||
for (std::vector<std::unique_ptr<Filter>>::iterator it = filter->filters.begin(); it != filter->filters.end();) {
|
||||
bool removal_requested = false;
|
||||
render_filter(filter->filters[i].get(), nullptr, &removal_requested, [&]() {
|
||||
swaps_to_do.push_back(std::make_pair(i, i - 1));
|
||||
}, [&]() {
|
||||
swaps_to_do.push_back(std::make_pair(i, i + 1));
|
||||
}, i != 0, i + 1 != filter->filters.size());
|
||||
|
||||
render_filter(it->get(), nullptr, &removal_requested);
|
||||
if (removal_requested) {
|
||||
removals_to_do.push_back(i);
|
||||
filter->filters.erase(it);
|
||||
filter->updated();
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
for (auto &[lhs, rhs] : swaps_to_do) {
|
||||
std::swap(filter->filters[lhs], filter->filters[rhs]);
|
||||
filter->updated();
|
||||
}
|
||||
for (size_t i : removals_to_do) {
|
||||
filter->filters.erase(filter->filters.begin() + static_cast<ssize_t>(i));
|
||||
filter->updated();
|
||||
}
|
||||
|
||||
if (ImGui::Button("+ add filter")) {
|
||||
ImGui::OpenPopup("add_filter");
|
||||
|
@ -235,26 +210,15 @@ void filters_fragment(Filters& inactive_filters) {
|
|||
ImGui::TextWrapped("You can use regex for strings by prepending \"regex:\". "
|
||||
"While editing titles, press Enter to use the new title or press Escape to keep the old one");
|
||||
|
||||
std::vector<std::pair<size_t, size_t>> swaps_to_do;
|
||||
std::vector<size_t> removals_to_do;
|
||||
for (size_t i = 0; i < inactive_filters.size(); i++) {
|
||||
for (Filters::iterator it = inactive_filters.begin(); it != inactive_filters.end();) {
|
||||
bool removal_requested = false;
|
||||
render_filter(inactive_filters[i].second.get(), &inactive_filters[i].first, &removal_requested, [&]() {
|
||||
swaps_to_do.push_back(std::make_pair(i, i - 1));
|
||||
}, [&]() {
|
||||
swaps_to_do.push_back(std::make_pair(i, i + 1));
|
||||
}, i != 0, i + 1 != inactive_filters.size());
|
||||
|
||||
render_filter(it->second.get(), &it->first, &removal_requested);
|
||||
if (removal_requested) {
|
||||
removals_to_do.push_back(i);
|
||||
inactive_filters.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
for (auto &[lhs, rhs] : swaps_to_do) {
|
||||
std::swap(inactive_filters[lhs], inactive_filters[rhs]);
|
||||
}
|
||||
for (size_t i : removals_to_do) {
|
||||
inactive_filters.erase(inactive_filters.begin() + static_cast<ssize_t>(i));
|
||||
}
|
||||
|
||||
if (ImGui::Button("+ add filter")) {
|
||||
ImGui::OpenPopup("add_filter");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
namespace ImGui { bool IsKeyPressed(ImGuiKeyChord key_chord, bool repeat); }; // forward declaration from ../misc.h
|
||||
#include "../misc.h"
|
||||
|
||||
void ok_buttons_fragment(bool* p_open, auto ok, auto apply);
|
||||
|
||||
|
|
13
misc.cpp
13
misc.cpp
|
@ -62,19 +62,6 @@ bool ImGui::Button(const char* label, bool enabled) {
|
|||
return res;
|
||||
}
|
||||
|
||||
bool ImGui::ArrowButton(const char* label, ImGuiDir dir, bool enabled) {
|
||||
if (!enabled) {
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
|
||||
bool res = ImGui::ArrowButton(label, dir);
|
||||
|
||||
if (!enabled) {
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ImGui::BeginWithCloseShortcut(const char* label, bool* p_open, ImGuiWindowFlags flags) {
|
||||
bool res = ImGui::Begin(label, p_open, flags);
|
||||
|
||||
|
|
2
misc.h
2
misc.h
|
@ -3,7 +3,6 @@
|
|||
#include <string>
|
||||
typedef int ImGuiWindowFlags; // forward declaration from imgui/imgui.h
|
||||
typedef int ImGuiKeyChord; // forward declaration from imgui/imgui.h
|
||||
typedef int ImGuiDir; // forward declaration from imgui/imgui.h
|
||||
|
||||
std::string quote(const std::string& str);
|
||||
void throw_system_error(int err, const char* what);
|
||||
|
@ -14,7 +13,6 @@ namespace ImGui {
|
|||
void TextUnformatted(const std::string& str);
|
||||
bool RedButton(const char* label);
|
||||
bool Button(const char* label, bool enabled);
|
||||
bool ArrowButton(const char* label, ImGuiDir dir, bool enabled);
|
||||
bool BeginWithCloseShortcut(const char* label, bool* p_open, ImGuiWindowFlags flags = 0);
|
||||
// don't spill __all__ of imgui_internal.h
|
||||
bool IsKeyPressed(ImGuiKeyChord key_chord, bool repeat = true);
|
||||
|
|
Loading…
Reference in New Issue