[wpigui] Add icon support

This commit is contained in:
Peter Johnson
2020-12-23 13:05:25 -08:00
parent 6b567e0066
commit 7ac39b10f7
3 changed files with 41 additions and 0 deletions

View File

@@ -208,6 +208,14 @@ bool gui::Initialize(const char* title, int width, int height) {
glfwSetWindowMaximizeCallback(gContext->window, WindowMaximizeCallback);
glfwSetWindowPosCallback(gContext->window, WindowPosCallback);
// Set icons
if (!gContext->icons.empty()) {
glfwSetWindowIcon(gContext->window, gContext->icons.size(),
gContext->icons.data());
for (auto&& icon : gContext->icons) stbi_image_free(icon.pixels);
gContext->icons.clear();
}
// Setup Dear ImGui style
SetStyle(static_cast<Style>(gContext->style));
@@ -304,6 +312,16 @@ void gui::AddLateExecute(std::function<void()> execute) {
GLFWwindow* gui::GetSystemWindow() { return gContext->window; }
bool gui::AddIcon(const unsigned char* data, int len) {
// Load from memory
GLFWimage image;
image.pixels =
stbi_load_from_memory(data, len, &image.width, &image.height, nullptr, 4);
if (!data) return false;
gContext->icons.emplace_back(std::move(image));
return true;
}
int gui::AddFont(
const char* name,
std::function<ImFont*(ImGuiIO& io, float size, const ImFontConfig* cfg)>