remove nonstandard type aliases

This commit is contained in:
scawful
2025-01-19 20:16:40 -05:00
parent fa33be3463
commit 809282edad
35 changed files with 367 additions and 357 deletions

View File

@@ -1,116 +0,0 @@
#ifndef YAZE_APP_CORE_CONSTANTS_H
#define YAZE_APP_CORE_CONSTANTS_H
#define TAB_ITEM(w) if (ImGui::BeginTabItem(w)) {
#define END_TAB_ITEM() \
ImGui::EndTabItem(); \
}
#define MENU_ITEM(w) if (ImGui::MenuItem(w))
#define MENU_ITEM2(w, v) if (ImGui::MenuItem(w, v))
#define BUTTON_COLUMN(w) \
ImGui::TableNextColumn(); \
ImGui::Button(w);
#define TEXT_COLUMN(w) \
ImGui::TableNextColumn(); \
ImGui::Text(w);
#define BEGIN_TABLE(l, n, f) if (ImGui::BeginTable(l, n, f, ImVec2(0, 0))) {
#define SETUP_COLUMN(l) ImGui::TableSetupColumn(l);
#define TABLE_HEADERS() \
ImGui::TableHeadersRow(); \
ImGui::TableNextRow();
#define NEXT_COLUMN() ImGui::TableNextColumn();
#define END_TABLE() \
ImGui::EndTable(); \
}
#define HOVER_HINT(string) \
if (ImGui::IsItemHovered()) ImGui::SetTooltip(string);
#define PRINT_IF_ERROR(expression) \
{ \
auto error = expression; \
if (!error.ok()) { \
std::cout << error.ToString() << std::endl; \
} \
}
#define EXIT_IF_ERROR(expression) \
{ \
auto error = expression; \
if (!error.ok()) { \
std::cout << error.ToString() << std::endl; \
return EXIT_FAILURE; \
} \
}
#define RETURN_VOID_IF_ERROR(expression) \
{ \
auto error = expression; \
if (!error.ok()) { \
std::cout << error.ToString() << std::endl; \
return; \
} \
}
#define RETURN_IF_ERROR(expression) \
{ \
auto error = expression; \
if (!error.ok()) { \
return error; \
} \
}
#define ASSIGN_OR_RETURN(type_variable_name, expression) \
ASSIGN_OR_RETURN_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
type_variable_name, expression)
#define ASSIGN_OR_RETURN_IMPL(error_or_value, type_variable_name, expression) \
auto error_or_value = expression; \
if (!error_or_value.ok()) { \
return error_or_value.status(); \
} \
type_variable_name = std::move(*error_or_value);
#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression) \
ASSIGN_OR_LOG_ERROR_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
type_variable_name, expression)
#define ASSIGN_OR_LOG_ERROR_IMPL(error_or_value, type_variable_name, \
expression) \
auto error_or_value = expression; \
if (!error_or_value.ok()) { \
std::cout << error_or_value.status().ToString() << std::endl; \
} \
type_variable_name = std::move(*error_or_value);
#define APPEND_NUMBER(expression, number) \
APPEND_NUMBER_INNER(expression, number)
#define APPEND_NUMBER_INNER(expression, number) expression##number
#define TEXT_WITH_SEPARATOR(text) \
ImGui::Text(text); \
ImGui::Separator();
#define TABLE_BORDERS_RESIZABLE \
ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable
#define CLEAR_AND_RETURN_STATUS(status) \
if (!status.ok()) { \
auto temp = status; \
status = absl::OkStatus(); \
return temp; \
}
using ushort = unsigned short;
using uint = unsigned int;
using uchar = unsigned char;
#endif

View File

@@ -5,13 +5,13 @@
#include <unordered_set>
#include <vector>
#include "app/core/constants.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "app/core/platform/file_dialog.h"
#include "app/gui/icons.h"
#include "imgui/imgui.h"
#include "util/macro.h"
namespace yaze {
namespace core {
@@ -27,54 +27,54 @@ static const float FONT_SIZE_DEFAULT = 16.0f;
static const float FONT_SIZE_DROID_SANS = 18.0f;
static const float ICON_FONT_SIZE = 18.0f;
namespace {
std::string SetFontPath(const std::string& font_path) {
#ifdef __APPLE__
#if TARGET_OS_IOS == 1
const std::string kBundlePath = GetBundleResourcePath();
return kBundlePath + font_path;
const std::string kBundlePath = GetBundleResourcePath();
return kBundlePath + font_path;
#else
return absl::StrCat(GetBundleResourcePath(), "Contents/Resources/font/",
font_path);
return absl::StrCat(GetBundleResourcePath(), "Contents/Resources/font/",
font_path);
#endif
#else
return absl::StrCat("assets/font/", font_path);
return absl::StrCat("assets/font/", font_path);
#endif
}
absl::Status LoadFont(const FontConfig& font_config) {
ImGuiIO& io = ImGui::GetIO();
std::string actual_font_path = SetFontPath(font_config.font_path);
// Check if the file exists with std library first, since ImGui IO will assert
// if the file does not exist
if (!std::filesystem::exists(actual_font_path)) {
return absl::InternalError(
absl::StrFormat("Font file %s does not exist", actual_font_path));
}
ImGuiIO& io = ImGui::GetIO();
std::string actual_font_path = SetFontPath(font_config.font_path);
// Check if the file exists with std library first, since ImGui IO will assert
// if the file does not exist
if (!std::filesystem::exists(actual_font_path)) {
return absl::InternalError(
absl::StrFormat("Font file %s does not exist", actual_font_path));
}
if (!io.Fonts->AddFontFromFileTTF(actual_font_path.data(), font_config.font_size)) {
return absl::InternalError(
absl::StrFormat("Failed to load font from %s", actual_font_path));
}
return absl::OkStatus();
if (!io.Fonts->AddFontFromFileTTF(actual_font_path.data(),
font_config.font_size)) {
return absl::InternalError(
absl::StrFormat("Failed to load font from %s", actual_font_path));
}
return absl::OkStatus();
}
absl::Status AddIconFont() {
ImGuiIO& io = ImGui::GetIO();
static const ImWchar icons_ranges[] = { ICON_MIN_MD, 0xf900, 0 };
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.GlyphOffset.y = 5.0f;
icons_config.GlyphMinAdvanceX = 13.0f;
icons_config.PixelSnapH = true;
std::string icon_font_path = SetFontPath(FONT_ICON_FILE_NAME_MD);
if (!io.Fonts->AddFontFromFileTTF(icon_font_path.c_str(), ICON_FONT_SIZE,
ImGuiIO& io = ImGui::GetIO();
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.GlyphOffset.y = 5.0f;
icons_config.GlyphMinAdvanceX = 13.0f;
icons_config.PixelSnapH = true;
std::string icon_font_path = SetFontPath(FONT_ICON_FILE_NAME_MD);
if (!io.Fonts->AddFontFromFileTTF(icon_font_path.c_str(), ICON_FONT_SIZE,
&icons_config, icons_ranges)) {
return absl::InternalError("Failed to add icon fonts");
}
return absl::OkStatus();
return absl::InternalError("Failed to add icon fonts");
}
return absl::OkStatus();
}
absl::Status AddJapaneseFont() {
@@ -86,8 +86,8 @@ absl::Status AddJapaneseFont() {
japanese_font_config.PixelSnapH = true;
std::string japanese_font_path = SetFontPath(NOTO_SANS_JP);
if (!io.Fonts->AddFontFromFileTTF(japanese_font_path.data(), ICON_FONT_SIZE,
&japanese_font_config,
io.Fonts->GetGlyphRangesJapanese())) {
&japanese_font_config,
io.Fonts->GetGlyphRangesJapanese())) {
return absl::InternalError("Failed to add Japanese fonts");
}
return absl::OkStatus();
@@ -96,7 +96,7 @@ absl::Status AddJapaneseFont() {
} // namespace
absl::Status LoadPackageFonts() {
ImGuiIO &io = ImGui::GetIO();
ImGuiIO& io = ImGui::GetIO();
// Icon configuration
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
@@ -114,45 +114,46 @@ absl::Status LoadPackageFonts() {
icons_config.PixelSnapH = true;
// List of fonts to be loaded
std::vector<const char *> font_paths = {
std::vector<const char*> font_paths = {
KARLA_REGULAR, ROBOTO_MEDIUM, COUSINE_REGULAR, IBM_PLEX_JP, DROID_SANS};
// Load fonts with associated icon and Japanese merges
for (const auto &font_path : font_paths) {
for (const auto& font_path : font_paths) {
float font_size =
(font_path == DROID_SANS) ? FONT_SIZE_DROID_SANS : FONT_SIZE_DEFAULT;
FontConfig font_config = { font_path, font_size };
RETURN_IF_ERROR(LoadFont(font_config));
FontConfig font_config = {font_path, font_size};
RETURN_IF_ERROR(LoadFont(font_config));
// Merge icon set
RETURN_IF_ERROR(AddIconFont());
RETURN_IF_ERROR(AddIconFont());
// Merge Japanese font
RETURN_IF_ERROR(AddJapaneseFont());
RETURN_IF_ERROR(AddJapaneseFont());
}
return absl::OkStatus();
}
absl::Status ReloadPackageFont(const FontConfig& config) {
ImGuiIO& io = ImGui::GetIO();
std::string actual_font_path = SetFontPath(config.font_path);
if (!io.Fonts->AddFontFromFileTTF(actual_font_path.data(), config.font_size)) {
return absl::InternalError(
absl::StrFormat("Failed to load font from %s", actual_font_path));
}
RETURN_IF_ERROR(AddIconFont());
RETURN_IF_ERROR(AddJapaneseFont());
ImGuiIO& io = ImGui::GetIO();
std::string actual_font_path = SetFontPath(config.font_path);
if (!io.Fonts->AddFontFromFileTTF(actual_font_path.data(),
config.font_size)) {
return absl::InternalError(
absl::StrFormat("Failed to load font from %s", actual_font_path));
}
RETURN_IF_ERROR(AddIconFont());
RETURN_IF_ERROR(AddJapaneseFont());
return absl::OkStatus();
}
#ifdef _WIN32
#include <Windows.h>
int CALLBACK EnumFontFamExProc(const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
int CALLBACK EnumFontFamExProc(const LOGFONT* lpelfe, const TEXTMETRIC* lpntme,
DWORD FontType, LPARAM lParam) {
// Step 3: Load the font into ImGui
ImGuiIO &io = ImGui::GetIO();
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF(lpelfe->lfFaceName, 16.0f);
return 1;
@@ -175,8 +176,8 @@ void LoadSystemFonts() {
RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &valueCount,
&maxValueNameSize, &maxValueDataSize, NULL, NULL);
char *valueName = new char[maxValueNameSize + 1]; // +1 for null terminator
BYTE *valueData = new BYTE[maxValueDataSize + 1]; // +1 for null terminator
char* valueName = new char[maxValueNameSize + 1]; // +1 for null terminator
BYTE* valueData = new BYTE[maxValueDataSize + 1]; // +1 for null terminator
// Enumerate all font entries
for (DWORD i = 0; i < valueCount; i++) {
@@ -193,7 +194,7 @@ void LoadSystemFonts() {
valueData, &valueDataSize) == ERROR_SUCCESS) {
if (valueType == REG_SZ) {
// Add the font file path to the vector
std::string fontPath(reinterpret_cast<char *>(valueData),
std::string fontPath(reinterpret_cast<char*>(valueData),
valueDataSize);
fontPaths.push_back(fontPath);
@@ -207,7 +208,7 @@ void LoadSystemFonts() {
RegCloseKey(hKey);
}
ImGuiIO &io = ImGui::GetIO();
ImGuiIO& io = ImGui::GetIO();
// List of common font face names
static const std::unordered_set<std::string> commonFontFaceNames = {
@@ -226,7 +227,7 @@ void LoadSystemFonts() {
"Tahoma",
"Lucida Console"};
for (auto &fontPath : fontPaths) {
for (auto& fontPath : fontPaths) {
// Check if the font path has a "C:\" prefix
if (fontPath.substr(0, 2) != "C:") {
// Add "C:\Windows\Fonts\" prefix to the font path

View File

@@ -3,10 +3,10 @@
#include <fstream>
#include <string>
#include "app/core/constants.h"
#include "app/gui/icons.h"
#include "imgui/imgui.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
#include "util/macro.h"
namespace yaze {
@@ -184,5 +184,4 @@ std::string ResourceLabelManager::CreateOrGetLabel(
return labels_[type][key];
}
} // namespace yaze