Added Noto Sans as default font.
This commit is contained in:
@@ -161,6 +161,35 @@ int Application::run(int argc, char** argv)
|
||||
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)
|
||||
{
|
||||
switch (message.severity)
|
||||
@@ -271,7 +300,15 @@ bool Application::initImGui()
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user