Revision 0a32fd63
Added by david.sorber over 2 years ago
| src/main.cpp | ||
|---|---|---|
|
// pwmgr main
|
||
|
// Dear ImGui: standalone example application for SDL2 + SDL_Renderer
|
||
|
// (SDL is a cross-platform general purpose library for handling windows, inputs,
|
||
|
// OpenGL/Vulkan/Metal graphics context creation, etc.)
|
||
|
|
||
|
// Learn about Dear ImGui:
|
||
|
// - FAQ https://dearimgui.com/faq
|
||
|
// - Getting Started https://dearimgui.com/getting-started
|
||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||
|
// - Introduction, links and more at the top of imgui.cpp
|
||
|
|
||
|
//
|
||
|
// TODO: consider switching to the below
|
||
|
// Important to understand: SDL_Renderer is an _optional_ component of SDL2.
|
||
|
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and
|
||
|
// SDL+OpenGL on Linux/OSX.
|
||
| ... | ... | |
|
#include <cstdio>
|
||
|
#include <cstdint>
|
||
|
#include <iostream>
|
||
|
//#include <ostream>
|
||
|
#include <map>
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
| ... | ... | |
|
#endif
|
||
|
|
||
|
const std::string APP_NAME("pwmgr");
|
||
|
|
||
|
const std::string VERSION("v0.0.1");
|
||
|
|
||
|
const std::string BOLD{"\033[1m"};
|
||
| ... | ... | |
|
|
||
|
#define ERROR_MSG BOLD << RED << "ERROR: " << ENDC
|
||
|
|
||
|
|
||
|
Catalog catalog;
|
||
|
|
||
|
|
||
|
static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS = ImGuiInputTextFlags_AllowTabInput;
|
||
|
static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS =
|
||
|
ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_ReadOnly;
|
||
|
|
||
|
int catalogFilterCallback(ImGuiInputTextCallbackData* data)
|
||
|
{
|
||
|
if (data->BufTextLen > 0)
|
||
|
{
|
||
|
std::cout << "BUFFER: " << data->Buf << std::endl;
|
||
|
// Lowercase the buffer in place
|
||
|
for (uint32_t idx = 0; idx < data->BufTextLen; ++idx)
|
||
|
{
|
||
|
if ((data->Buf[idx] >= 'A') && (data->Buf[idx] <= 'Z'))
|
||
|
{
|
||
|
data->Buf[idx] |= 32;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Debuggery
|
||
|
// std::cout << "BUFFER: " << data->Buf << std::endl;
|
||
|
|
||
|
// Now filter the catalog
|
||
|
catalog.filter(data->Buf);
|
||
|
}
|
||
|
else
|
||
| ... | ... | |
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
||
|
//IM_ASSERT(font != nullptr);
|
||
|
|
||
|
// Our state
|
||
|
bool show_demo_window = false;
|
||
|
bool show_another_window = false;
|
||
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||
|
// GUI state
|
||
|
|
||
|
// Main loop
|
||
|
bool done = false;
|
||
| ... | ... | |
|
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
|
||
|
#endif
|
||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||
|
ImGui::Begin("inner window", nullptr,
|
||
|
ImGui::Begin("inner_window", nullptr,
|
||
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_MenuBar);
|
||
|
|
||
|
|
||
| ... | ... | |
|
|
||
|
for (auto& iter : catalog)
|
||
|
{
|
||
|
// ImGuiInputTextFlags_ReadOnly
|
||
|
if (iter.visible() &&
|
||
|
ImGui::CollapsingHeader(iter.getKey().c_str()))
|
||
|
{
|
||
|
// ImGui::Text("%s", iter.second.c_str());
|
||
|
ImGui::InputTextMultiline(
|
||
|
iter.getLcKey().c_str(),
|
||
|
const_cast<char*>(iter.getValue().c_str()),
|
||
|
iter.getValue().size(),
|
||
|
ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 4),
|
||
|
iter.getValueBuffer(),
|
||
|
iter.getValueBufferSize(),
|
||
|
ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 4),
|
||
|
MULTILINE_TEXT_FLAGS);
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
ImGui::BeginChild("item view",
|
||
|
ImVec2(0, -ImGui::GetFrameHeightWithSpacing()));
|
||
|
|
||
|
|
||
|
// ImGui::Text("MyObject: %d", selected);
|
||
|
char str0[128]{};
|
||
|
ImGui::InputText("Filter", str0,
|
||
|
IM_ARRAYSIZE(str0),
|
||
|
char filterBuffer[128]{};
|
||
|
ImGui::InputText("Filter", filterBuffer,
|
||
|
IM_ARRAYSIZE(filterBuffer),
|
||
|
ImGuiInputTextFlags_CallbackEdit,
|
||
|
catalogFilterCallback);
|
||
|
|
||
|
ImGui::Separator();
|
||
|
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
|
||
|
{
|
||
|
if (ImGui::BeginTabItem("Description"))
|
||
|
if (ImGui::BeginTabItem("Options"))
|
||
|
{
|
||
|
ImGui::TextWrapped(
|
||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing "
|
||
| ... | ... | |
|
ImGui::EndTabItem();
|
||
|
}
|
||
|
|
||
|
if (ImGui::BeginTabItem("Details"))
|
||
|
if (ImGui::BeginTabItem("About"))
|
||
|
{
|
||
|
ImGui::Text("ID: 0123456789");
|
||
|
ImGui::Text("%s version: %s", APP_NAME.c_str(),
|
||
|
VERSION.c_str());
|
||
|
ImGui::Text("Compiled on: %s ", __TIMESTAMP__);
|
||
|
ImGui::Text("Created by: dsorber");
|
||
|
ImGui::EndTabItem();
|
||
|
}
|
||
|
ImGui::EndTabBar();
|
||
Improved filtering and added parsing input from a plaintext file.