summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bookmouse.cpp125
-rw-r--r--src/bookmouse.hpp18
-rw-r--r--src/bookmouse_time.cpp70
-rw-r--r--src/bookmouse_time.hpp32
-rw-r--r--src/demo.cpp62
-rw-r--r--src/file_dialog.cpp129
-rw-r--r--src/file_dialog.hpp97
-rw-r--r--src/image.cpp4
-rw-r--r--src/imgui_context.cpp5
-rw-r--r--src/imgui_context.hpp51
10 files changed, 552 insertions, 41 deletions
diff --git a/src/bookmouse.cpp b/src/bookmouse.cpp
index 1f6fa00..2e13b4e 100644
--- a/src/bookmouse.cpp
+++ b/src/bookmouse.cpp
@@ -1,18 +1,25 @@
#include "bookmouse.hpp"
+#include "bookmouse_time.hpp"
+#include "file_dialog.hpp"
+
#include <SDL_opengl.h>
+#include <atomic>
#include <fud_array.hpp>
+#include <fud_directory.hpp>
#include <spdlog/spdlog.h>
-
-#include <atomic>
+#include <vector>
namespace bookmouse {
+using fud::FudStatus;
+
constexpr const char* OpenDialogHandle = "Open File";
Bookmouse::Bookmouse() :
m_sdlContext{}, m_mainWindow{m_sdlContext}, m_glContext{m_mainWindow},
- m_imgui{m_glContext, m_sdlContext, m_mainWindow}
+ m_imgui{m_glContext, m_sdlContext, m_mainWindow},
+ m_directory{m_directoryName}
{
/*
* Load Fonts
@@ -92,23 +99,30 @@ void Bookmouse::updateState()
{
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
ImGui::SetNextWindowSize(m_imgui.getIO().DisplaySize);
- auto stateResult = ImGui::Begin(
+ auto stateResult = ImBegin(
"My First Tool",
&m_running, // Is this right?
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_MenuBar);
IM_ASSERT(stateResult);
- if (ImguiMenuBar menuBar{}) {
+ // m_imgui.getIO().AddKeyEvent()
+
+ if (ImGui::IsKeyPressed(ImGuiKey_O) && m_imgui.getIO().KeyCtrl && !m_openDialog) {
+ m_openDialog = true;
+ }
+
+ if (ImMenuBar menuBar{}) {
IM_ASSERT(menuBar);
menuing();
}
if (m_openDialog) {
m_openDialog = false;
+ m_getContents = true;
ImGui::OpenPopup(OpenDialogHandle);
}
- if (ImguiPopupModal popup{OpenDialogHandle}) {
+ if (ImPopupModal popup{OpenDialogHandle}) {
IM_ASSERT(popup);
openDialog();
}
@@ -121,20 +135,20 @@ void Bookmouse::updateState()
float samples[100];
for (int idx = 0; idx < 100; idx++) {
auto num = static_cast<float>(idx);
- auto time = static_cast<float>(ImGui::GetTime());
+ auto time = static_cast<float>(ImGetTime());
samples[idx] = sinf(num * 0.2f + time * 1.5f);
}
ImGui::PlotLines("Samples", samples, 100);
// Display contents in a scrolling region
ImGui::TextColored(ImVec4(1, 1, 0, 1), "Important Stuff");
- ImGui::Text("%04d: Some text", 42);
- ImGui::End();
+ ImText("%04d: Some text", 42);
+ ImEnd();
}
void Bookmouse::menuing()
{
- if (ImguiMenu menu{"File"}) {
+ if (ImMenu menu{"File"}) {
IM_ASSERT(menu);
if (ImGui::MenuItem("Open Archive", "Ctrl+O")) { /* Do stuff */
m_openDialog = true;
@@ -144,7 +158,7 @@ void Bookmouse::menuing()
}
}
- if (ImguiMenu menu{"Help"}) {
+ if (ImMenu menu{"Help"}) {
IM_ASSERT(menu);
if (ImGui::MenuItem("About")) {
spdlog::debug("About");
@@ -153,9 +167,92 @@ void Bookmouse::menuing()
}
}
-void Bookmouse::openDialog() {
- ImGui::Text("Hello from another window!");
- if (ImGui::Button("Close Me")) {
+void Bookmouse::openDialog()
+{
+ if (m_fileDialog == nullptr) {
+ m_fileDialog = std::make_unique<FileDialog>(m_directoryName, m_timeFormat);
+ if (!m_fileDialog->valid()) {
+ m_openDialog = false;
+ ImGui::CloseCurrentPopup();
+ }
+ }
+}
+
+void Bookmouse::openDialog2()
+{
+ if (m_getContents) {
+ m_getContents = false;
+
+ m_directoryName = fud::String{"./"};
+ m_directory = fud::Directory{m_directoryName};
+
+ auto directoryStatsResult = m_directory.info();
+ if (directoryStatsResult.isError()) {
+ m_openDialog = false;
+ ImGui::CloseCurrentPopup();
+ }
+ auto directoryStats = directoryStatsResult.getOkay();
+
+ size_t count{0};
+ m_directoryContents.reserve(directoryStats.links);
+
+ while (true && count < SIZE_MAX) {
+ auto dirEntryResult = m_directory.getNextEntry();
+ if (dirEntryResult.isError()) {
+ break;
+ }
+
+ auto dirEntryOpt = dirEntryResult.getOkay();
+ if (dirEntryOpt == std::nullopt) {
+ break;
+ }
+
+ if (dirEntryOpt->inode == directoryStats.inode) {
+ continue;
+ }
+
+ m_directoryContents.emplace_back(std::move(*dirEntryOpt));
+ auto status = m_directoryContents.back().formatTime(m_timeFormat);
+ if (status != FudStatus::Success) {
+ spdlog::error("Could not convert time: {}", fud::FudStatusToString(status));
+ }
+ }
+ }
+
+ ImText("%s %zu", m_directory.name().c_str(), m_directoryContents.size());
+ if (ImTable table{"Entries", 4, ImGuiTableFlags_Borders}) {
+ auto colFlags = ImGuiSelectableFlags_NoAutoClosePopups;
+ IM_ASSERT(table);
+ ImNextColumn();
+ ImSelectable("T", &m_typeSelected, colFlags);
+ ImNextColumn();
+ ImSelectable("Name", &m_nameSelectede, colFlags);
+ ImNextColumn();
+ ImSelectable("Size", &m_sizeSelected, colFlags);
+ ImNextColumn();
+ ImSelectable("Date", &m_dateSelected, colFlags);
+ for (auto& entry : m_directoryContents) {
+ ImNextRow();
+ const char entryLetter = DirEntryTypeToChar(entry.entryType);
+ ImNextColumn();
+ ImText("%c", entryLetter);
+ ImNextColumn();
+ ImSelectable(entry.name.c_str(), &entry.selected, colFlags | ImGuiSelectableFlags_SpanAllColumns);
+ ImNextColumn();
+ ImText("%zu\n", entry.isDirectory() ? entry.links : entry.size);
+ ImNextColumn();
+ ImText("%s", entry.niceTime.c_str());
+ }
+ }
+
+ if (ImButton("Accept")) {
+ m_openDialog = false;
+ ImGui::CloseCurrentPopup();
+ }
+
+ ImSameLine();
+
+ if (ImButton("Cancel")) {
m_openDialog = false;
ImGui::CloseCurrentPopup();
}
diff --git a/src/bookmouse.hpp b/src/bookmouse.hpp
index 95cbd61..29a6caf 100644
--- a/src/bookmouse.hpp
+++ b/src/bookmouse.hpp
@@ -1,6 +1,7 @@
#ifndef BOOKMOUSE_HPP
#define BOOKMOUSE_HPP
+#include "file_dialog.hpp"
#include "archive.hpp"
#include "gl_context.hpp"
#include "imgui_context.hpp"
@@ -8,6 +9,7 @@
#include "sdl_main_window.hpp"
#include <memory>
+#include <vector>
namespace bookmouse {
@@ -34,6 +36,7 @@ class Bookmouse {
void menuing();
void openDialog();
+ void openDialog2();
void setArchive(std::unique_ptr<Archive>&& archive);
@@ -42,9 +45,24 @@ class Bookmouse {
GlContext m_glContext;
ImguiContext m_imgui;
+ TimeFormat m_timeFormat{"%Y-%m-%d %H:%M"};
+
bool m_running{true};
bool m_openDialog{false};
+ std::unique_ptr<FileDialog> m_fileDialog{nullptr};
+
+ bool m_getContents{false};
+ fud::String m_directoryName{"./"};
+ fud::Directory m_directory;
+
+ bool m_typeSelected{false};
+ bool m_nameSelectede{false};
+ bool m_sizeSelected{false};
+ bool m_dateSelected{false};
+
+ std::vector<DialogEntry> m_directoryContents{};
+
std::unique_ptr<Archive> m_archive{nullptr};
PageLayout m_pageLayout{PageLayout::Single};
diff --git a/src/bookmouse_time.cpp b/src/bookmouse_time.cpp
new file mode 100644
index 0000000..c779168
--- /dev/null
+++ b/src/bookmouse_time.cpp
@@ -0,0 +1,70 @@
+#include "bookmouse_time.hpp"
+
+#include <vector>
+
+namespace bookmouse {
+
+using fud::FudStatus;
+using fud::Result;
+
+TimeFormat::TimeFormat(const char* format) : m_format{format}, m_sizeNeeded{m_format.length()}
+{
+ if (m_format.utf8Valid()) {
+ m_utf8Valid = true;
+ }
+}
+
+TimeFormat::TimeFormat(const fud::String& format) : m_format{format}, m_sizeNeeded{m_format.length()}
+{
+ if (m_format.utf8Valid()) {
+ m_utf8Valid = true;
+ }
+}
+
+fud::Result<fud::String, fud::FudStatus> TimeFormat::format(const TimeInfo& timeInfo)
+{
+ using RetType = fud::Result<fud::String, fud::FudStatus>;
+
+ if (!m_utf8Valid || m_format.length() < 1) {
+ return RetType::error(FudStatus::ObjectInvalid);
+ }
+
+ std::vector<char> output;
+ size_t resultSize = 0;
+ constexpr size_t maxSize = 1024;
+ while (resultSize == 0 && m_sizeNeeded <= maxSize) {
+ output.resize(m_sizeNeeded);
+
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#elif defined __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
+
+ resultSize = std::strftime(output.data(), output.size(), m_format.c_str(), &timeInfo);
+
+#if defined __clang__
+#pragma clang diagnostic pop
+#elif defined __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
+
+ if (resultSize == 0) {
+ if (m_sizeNeeded <= 512) {
+ m_sizeNeeded *= 2;
+ } else {
+ m_sizeNeeded = maxSize;
+ }
+ }
+ }
+ if (resultSize == 0) {
+ return RetType::error(FudStatus::Failure);
+ }
+
+ return RetType::okay(fud::String(output.data()));
+}
+
+} // namespace bookmouse
diff --git a/src/bookmouse_time.hpp b/src/bookmouse_time.hpp
new file mode 100644
index 0000000..5bd15a9
--- /dev/null
+++ b/src/bookmouse_time.hpp
@@ -0,0 +1,32 @@
+#ifndef BOOKMOUSE_TIME_HPP
+#define BOOKMOUSE_TIME_HPP
+
+#include <fud_status.hpp>
+#include <fud_result.hpp>
+#include <fud_string.hpp>
+
+#include <ctime>
+
+namespace bookmouse {
+
+using TimeInfo = struct tm;
+
+class TimeFormat {
+public:
+ explicit TimeFormat(const char* format);
+ explicit TimeFormat(const fud::String& format);
+
+ fud::Result<fud::String, fud::FudStatus> format(const TimeInfo& timeInfo);
+
+ // fud::FudStatus setFormatString(const fud::String& format);
+
+private:
+ fud::String m_format;
+ size_t m_sizeNeeded;
+ bool m_utf8Valid{false};
+};
+
+
+} // namespace bookmouse
+
+#endif
diff --git a/src/demo.cpp b/src/demo.cpp
index 433dd5d..14bd8d5 100644
--- a/src/demo.cpp
+++ b/src/demo.cpp
@@ -20,20 +20,34 @@
namespace bookmouse {
// Simple helper function to load an image into a OpenGL texture with common settings
-bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_texture, int* out_width, int* out_height)
+bool LoadTextureFromMemory( // force newline
+ const void* data,
+ size_t data_size,
+ GLuint* out_texture,
+ int* out_width,
+ int* out_height)
{
// Load from file
int width = 0;
int height = 0;
int channelsInFile = 4;
- unsigned char*
- image_data = stbi_load_from_memory((const unsigned char*)data, (int)data_size, &width, &height, nullptr, 4);
+ unsigned char* image_data = stbi_load_from_memory( // force
+ (const unsigned char*)data,
+ (int)data_size,
+ &width,
+ &height,
+ nullptr,
+ 4);
if (image_data == nullptr) {
spdlog::error("Failed to get data from");
return false;
}
- spdlog::info("Got result: {} pixels per row of {} scanlines with {} channels", width, height, channelsInFile);
+ spdlog::info( // force
+ "Got result: {} pixels per row of {} scanlines with {} channels",
+ width,
+ height,
+ channelsInFile);
// Create a OpenGL texture identifier
GLuint imageTexture;
@@ -46,7 +60,16 @@ bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_textu
// Upload pixels into texture
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
+ glTexImage2D( // force
+ GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ width,
+ height,
+ 0,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ image_data);
stbi_image_free(image_data);
*out_texture = imageTexture;
@@ -57,12 +80,16 @@ bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_textu
}
// Open and read a file, then forward to LoadTextureFromMemory()
-bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int* out_width, int* out_height)
+bool LoadTextureFromFile( // force
+ const fud::String& filename,
+ GLuint* out_texture,
+ int* out_width,
+ int* out_height)
{
fud::CBinaryFile inFile{filename, fud::CFileMode::ReadOnly};
auto fileResult = inFile.open();
- using fud::FileStatus;
- if (fileResult == FileStatus::Error) {
+ using fud::FudStatus;
+ if (fileResult == FudStatus::Failure) {
spdlog::error("can't open {}", filename.c_str());
// return err(ImageError::FileError);
return false;
@@ -70,7 +97,10 @@ bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int*
auto fileSizeResult = inFile.size();
if (fileSizeResult.isError()) {
- spdlog::error("bad file size {} {}", filename.c_str(), FileStatusToString(fileSizeResult.getError()));
+ spdlog::error( // force
+ "bad file size {} {}",
+ filename.c_str(),
+ FudStatusToString(fileSizeResult.getError()));
return false;
}
auto fileSize = fileSizeResult.getOkay();
@@ -86,12 +116,14 @@ bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int*
fileData.resize(fileSize);
auto readResult = inFile.read(fileData.data(), fileSize, fileSize);
- if (readResult.status != FileStatus::Success) {
- spdlog::error("bad read {} {}", filename.c_str(), FileStatusToString(readResult.status));
+ if (readResult.status != FudStatus::Success) {
+ spdlog::error( // force
+ "bad read {} {}", filename.c_str(), FudStatusToString(readResult.status));
return false;
}
- bool ret = LoadTextureFromMemory(fileData.data(), fileSize, out_texture, out_width, out_height);
+ bool ret = LoadTextureFromMemory( // force
+ fileData.data(), fileSize, out_texture, out_width, out_height);
return ret;
}
@@ -109,7 +141,8 @@ int demo(const fud::String& m_filename)
int my_image_width = 0;
int my_image_height = 0;
GLuint my_image_texture = 0;
- bool ret = LoadTextureFromFile(m_filename, &my_image_texture, &my_image_width, &my_image_height);
+ bool ret = LoadTextureFromFile( // force
+ m_filename, &my_image_texture, &my_image_width, &my_image_height);
IM_ASSERT(ret);
// Our state
@@ -119,8 +152,7 @@ int demo(const fud::String& m_filename)
// Main loop
bool done = false;
- while (!done)
- {
+ while (!done) {
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your
// inputs.
diff --git a/src/file_dialog.cpp b/src/file_dialog.cpp
new file mode 100644
index 0000000..faab3e7
--- /dev/null
+++ b/src/file_dialog.cpp
@@ -0,0 +1,129 @@
+#include "file_dialog.hpp"
+#include "imgui_context.hpp"
+
+#include <imgui/imgui.h>
+
+#include <spdlog/spdlog.h>
+
+namespace bookmouse {
+
+using fud::FudStatus;
+
+DialogEntry::DialogEntry(fud::DirectoryEntry&& entry) :
+ fud::DirectoryEntry(std::move(entry)), timeInfo{}, niceTime{}, selected{false}, valid{false}, gotTime{false}
+{
+ auto timeInfoPtr = localtime_r(&this->modificationTime, &timeInfo);
+ if (timeInfoPtr == nullptr) {
+ return;
+ }
+
+ valid = true;
+}
+
+FudStatus DialogEntry::formatTime(TimeFormat& format)
+{
+ if (!valid) {
+ return FudStatus::ObjectInvalid;
+ }
+
+ auto result = format.format(this->timeInfo);
+ if (result.isError())
+ {
+ return result.getError();
+ }
+
+ this->niceTime = result.getOkay();
+
+ return FudStatus::Success;
+}
+
+FileDialog::FileDialog(
+ const fud::String& directoryName,
+ TimeFormat& timeFormat) : m_directoryName{directoryName},
+ m_directory{directoryName},
+ m_timeFormat{timeFormat}
+{
+ auto status = getDirectoryContents();
+ if (status != FudStatus::Success) {
+ return;
+ }
+}
+
+FudStatus FileDialog::getDirectoryContents() {
+ auto directoryStatsResult = m_directory.info();
+ if (directoryStatsResult.isError()) {
+ return directoryStatsResult.getError();
+ }
+ auto directoryStats = directoryStatsResult.getOkay();
+
+ size_t count{0};
+ m_directoryContents.reserve(directoryStats.links);
+
+ while (true && count < SIZE_MAX) {
+ auto dirEntryResult = m_directory.getNextEntry();
+ if (dirEntryResult.isError()) {
+ break;
+ }
+
+ auto dirEntryOpt = dirEntryResult.getOkay();
+ if (dirEntryOpt == std::nullopt) {
+ break;
+ }
+
+ if (dirEntryOpt->inode == directoryStats.inode) {
+ continue;
+ }
+
+ m_directoryContents.emplace_back(std::move(*dirEntryOpt));
+ auto status = m_directoryContents.back().formatTime(m_timeFormat);
+ if (status != FudStatus::Success) {
+ spdlog::error("Could not convert time: {}", fud::FudStatusToString(status));
+ }
+ }
+
+ return FudStatus::Success;
+}
+
+FilePickerResult FileDialog::pickFiles()
+{
+ ImText("%s %zu", m_directory.name().c_str(), m_directoryContents.size());
+ if (ImTable table{"Entries", 4, ImGuiTableFlags_Borders}) {
+ auto colFlags = ImGuiSelectableFlags_NoAutoClosePopups;
+ IM_ASSERT(table);
+ ImNextColumn();
+ ImSelectable("T", &m_typeSelected, colFlags);
+ ImNextColumn();
+ ImSelectable("Name", &m_nameSelectede, colFlags);
+ ImNextColumn();
+ ImSelectable("Size", &m_sizeSelected, colFlags);
+ ImNextColumn();
+ ImSelectable("Date", &m_dateSelected, colFlags);
+ for (auto& entry : m_directoryContents) {
+ ImNextRow();
+ const char entryLetter = DirEntryTypeToChar(entry.entryType);
+ ImNextColumn();
+ ImText("%c", entryLetter);
+ ImNextColumn();
+ ImSelectable(entry.name.c_str(), &entry.selected, colFlags | ImGuiSelectableFlags_SpanAllColumns);
+ ImNextColumn();
+ ImText("%zu\n", entry.isDirectory() ? entry.links : entry.size);
+ ImNextColumn();
+ ImText("%s", entry.niceTime.c_str());
+ }
+ }
+
+ if (ImButton("Accept")) {
+ return FilePickerResult::error(FudStatus::NotImplemented);
+ }
+
+ ImSameLine();
+
+ if (ImButton("Cancel")) {
+ return FilePickerResult::error(FudStatus::NotImplemented);
+ }
+
+
+ return FilePickerResult::error(FudStatus::NotImplemented);
+}
+
+} // namespace bookmouse
diff --git a/src/file_dialog.hpp b/src/file_dialog.hpp
new file mode 100644
index 0000000..9709ec0
--- /dev/null
+++ b/src/file_dialog.hpp
@@ -0,0 +1,97 @@
+#ifndef FILE_DIALOG_HPP
+#define FILE_DIALOG_HPP
+
+#include <fud_status.hpp>
+#include <fud_string.hpp>
+#include <fud_directory.hpp>
+
+#include "bookmouse_time.hpp"
+#include <vector>
+
+namespace bookmouse {
+
+using DirEntryType = fud::DirectoryEntryType;
+struct DialogEntry : public fud::DirectoryEntry {
+ TimeInfo timeInfo;
+ fud::String niceTime;
+ bool selected;
+ bool valid;
+ bool gotTime;
+
+ DialogEntry() = default;
+ DialogEntry(fud::DirectoryEntry&& entry);
+
+ fud::FudStatus formatTime(TimeFormat& format);
+};
+
+constexpr char DirEntryTypeToChar(DirEntryType entryType)
+{
+ char entryLetter = 'D';
+ switch (entryType) {
+ case DirEntryType::Directory:
+ entryLetter = 'D';
+ break;
+ case DirEntryType::RegularFile:
+ entryLetter = 'F';
+ break;
+ case DirEntryType::Character:
+ entryLetter = 'F';
+ break;
+ case DirEntryType::UnixSocket:
+ entryLetter = 'S';
+ break;
+ case DirEntryType::NamedPipe:
+ entryLetter = 'P';
+ break;
+ case DirEntryType::SymbolicLink:
+ entryLetter = 'L';
+ break;
+ case DirEntryType::Block:
+ entryLetter = 'B';
+ break;
+ case DirEntryType::Unknown:
+ default:
+ entryLetter = '?';
+ break;
+ }
+ return entryLetter;
+}
+
+using FilePickerResult = fud::Result<
+ std::vector<DialogEntry>,
+ fud::FudStatus>;
+
+class FileDialog {
+
+public:
+ FileDialog(
+ const fud::String& directoryName,
+ TimeFormat& timeFormat);
+
+ FilePickerResult pickFiles();
+
+ constexpr bool valid() const {
+ return m_valid;
+ }
+
+private:
+ fud::FudStatus getDirectoryContents();
+
+ fud::String m_directoryName;
+ fud::Directory m_directory;
+ TimeFormat& m_timeFormat;
+
+ std::vector<DialogEntry> m_directoryContents{};
+
+ bool m_valid{false};
+
+ bool m_typeSelected{false};
+ bool m_nameSelectede{false};
+ bool m_sizeSelected{false};
+ bool m_dateSelected{false};
+
+};
+
+} // namespace bookmouse
+
+#endif
diff --git a/src/image.cpp b/src/image.cpp
index 786c4ba..d73e86e 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -25,8 +25,8 @@ ImageResult JpegImage::output() const
ImageOutput image{};
fud::CBinaryFile inFile{m_filename, fud::CFileMode::ReadOnly};
auto fileResult = inFile.open();
- using fud::FileStatus;
- if (fileResult == FileStatus::Error) {
+ using fud::FudStatus;
+ if (fileResult == FudStatus::Failure) {
spdlog::error("can't open {}\n", m_filename.c_str());
return err(ImageError::FileError);
}
diff --git a/src/imgui_context.cpp b/src/imgui_context.cpp
index f45b22b..99ecd3f 100644
--- a/src/imgui_context.cpp
+++ b/src/imgui_context.cpp
@@ -47,6 +47,11 @@ const ImGuiIO& ImguiContext::getIO() const
return ImGui::GetIO();
}
+ImGuiIO& ImguiContext::getIO()
+{
+ return ImGui::GetIO();
+}
+
bool ImguiContext::processEvent(SDL_Event& event) const
{
return ImGui_ImplSDL2_ProcessEvent(&event);
diff --git a/src/imgui_context.hpp b/src/imgui_context.hpp
index 413bd0b..fa04fb2 100644
--- a/src/imgui_context.hpp
+++ b/src/imgui_context.hpp
@@ -16,6 +16,8 @@ class ImguiContext {
const ImGuiIO& getIO() const;
+ ImGuiIO& getIO();
+
void setIOFlag(ImGuiConfigFlags_ flag) const;
bool processEvent(SDL_Event& event) const;
void startFrame() const;
@@ -74,29 +76,58 @@ class ConditionalRaii {
} \
};
-STRUCT_FUNCTOR_ARGS(ImguiBeginMenuBar, Imgui::BeginMenuBar)
-STRUCT_FUNCTOR(ImguiEndMenuBar, Imgui::EndMenuBar)
+STRUCT_FUNCTOR_ARGS(ImBeginMenuBar, Imgui::BeginMenuBar)
+STRUCT_FUNCTOR(ImEndMenuBar, Imgui::EndMenuBar)
-using ImguiMenuBar = ConditionalRaii<ImguiBeginMenuBar, ImguiEndMenuBar>;
+using ImMenuBar = ConditionalRaii<ImBeginMenuBar, ImEndMenuBar>;
-STRUCT_FUNCTOR_ARGS(ImguiBeginMenu, Imgui::BeginMenu)
-STRUCT_FUNCTOR(ImguiEndMenu, Imgui::EndMenu)
+STRUCT_FUNCTOR_ARGS(ImBeginMenu, Imgui::BeginMenu)
+STRUCT_FUNCTOR(ImEndMenu, Imgui::EndMenu)
-using ImguiMenu = ConditionalRaii<ImguiBeginMenu, ImguiEndMenu>;
+using ImMenu = ConditionalRaii<ImBeginMenu, ImEndMenu>;
-STRUCT_FUNCTOR_ARGS(ImguiBeginPopupModal, Imgui::BeginPopupModal)
+STRUCT_FUNCTOR_ARGS(ImBeginPopupModal, Imgui::BeginPopupModal)
// N.B. EndPopup is needed for BeginPopupModal
-STRUCT_FUNCTOR(ImguiEndPopupModal, Imgui::EndPopup)
+STRUCT_FUNCTOR(ImEndPopupModal, Imgui::EndPopup)
+
+using ImPopupModal = ConditionalRaii<ImBeginPopupModal, ImEndPopupModal>;
+
+STRUCT_FUNCTOR_ARGS(ImBeginTable, Imgui::BeginTable)
+STRUCT_FUNCTOR(ImEndTable, Imgui::EndTable)
-using ImguiPopupModal = ConditionalRaii<ImguiBeginPopupModal, ImguiEndPopupModal>;
+using ImTable = ConditionalRaii<ImBeginTable, ImEndTable>;
-// STRUCT_FUNCTOR_ARGS(Imgui
+// STRUCT_FUNCTOR_ARGS(Im
#undef Imgui
#undef STRUCT_FUNCTOR
#undef STRUCT_FUNCTOR_ARGS
+constexpr auto ImBegin = ImGui::Begin;
+constexpr auto ImEnd = ImGui::End;
+
+inline void ImSameLine(float xOffset = 0.0, float spacing = 0.0)
+{
+ ImGui::SameLine(xOffset, spacing);
+}
+
+#define ImText ImGui::Text
+
+inline bool ImButton(const char* label, const ImVec2& size = ImVec2(0, 0))
+{
+ return ImGui::Button(label, size);
+}
+
+constexpr auto ImGetTime = ImGui::GetTime;
+inline void ImNextRow(ImGuiTableRowFlags row_flags = 0, float min_row_height = 0.0f)
+{
+ ImGui::TableNextRow(row_flags, min_row_height);
+}
+constexpr auto ImNextColumn = ImGui::TableNextColumn;
+
+#define ImSelectable ImGui::Selectable
+
} // namespace bookmouse
#endif