Added Noto Sans as default font.
This commit is contained in:
parent
cd40148961
commit
ce328ac761
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.ttf filter=lfs diff=lfs merge=lfs -text
|
BIN
data/data/fonts/NotoSans-Regular.ttf
(Stored with Git LFS)
Normal file
BIN
data/data/fonts/NotoSans-Regular.ttf
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -161,6 +161,35 @@ int Application::run(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::loadFont(const fs::path& path)
|
||||||
|
{
|
||||||
|
ImGuiIO& imguiIO = ImGui::GetIO();
|
||||||
|
|
||||||
|
std::unique_ptr<mijin::Stream> fontFile;
|
||||||
|
if (const mijin::StreamError error = mFS.open(path, mijin::FileOpenMode::READ, fontFile);
|
||||||
|
error != mijin::StreamError::SUCCESS)
|
||||||
|
{
|
||||||
|
msgError("Error opening font file {}: {}.", path.generic_string(), mijin::errorName(error));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mijin::TypelessBuffer data;
|
||||||
|
if (const mijin::StreamError readError = fontFile->readRest(data); readError != mijin::StreamError::SUCCESS)
|
||||||
|
{
|
||||||
|
msgError("Error reading font data from {}: {}.", path.generic_string(), mijin::errorName(readError));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// by default ImGui takes ownership of the data, that's now what we want
|
||||||
|
ImFontConfig config;
|
||||||
|
config.FontDataOwnedByAtlas = false;
|
||||||
|
imguiIO.Fonts->AddFontFromMemoryTTF(data.data(), static_cast<int>(data.byteSize()), 20, &config);
|
||||||
|
|
||||||
|
// but in that case Build() has to be run before the data gets deleted
|
||||||
|
imguiIO.Fonts->Build();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Application::handleMessage(const Message& message)
|
void Application::handleMessage(const Message& message)
|
||||||
{
|
{
|
||||||
switch (message.severity)
|
switch (message.severity)
|
||||||
@ -271,7 +300,15 @@ bool Application::initImGui()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init font
|
// init font
|
||||||
imguiIO.Fonts->AddFontDefault();
|
if (imguiIO.Fonts->Fonts.empty())
|
||||||
|
{
|
||||||
|
static const char* const DEFAULT_FONT = "/data/fonts/NotoSans-Regular.ttf";
|
||||||
|
if (!loadFont(DEFAULT_FONT))
|
||||||
|
{
|
||||||
|
imguiIO.Fonts->AddFontDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,14 @@ public:
|
|||||||
ImGuiWindowFlags getMainWindowFlags() const { return mMainWindowFlags; }
|
ImGuiWindowFlags getMainWindowFlags() const { return mMainWindowFlags; }
|
||||||
|
|
||||||
void setMainWindowFlags(ImGuiWindowFlags flags) { mMainWindowFlags = flags; }
|
void setMainWindowFlags(ImGuiWindowFlags flags) { mMainWindowFlags = flags; }
|
||||||
|
|
||||||
void requestQuit() { mRunning = false; }
|
void requestQuit() { mRunning = false; }
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int run(int argc, char* argv[]);
|
int run(int argc, char* argv[]);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
bool loadFont(const fs::path& path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
virtual std::string getFolderName() = 0;
|
virtual std::string getFolderName() = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user