c++控制台界面库_c++控制台显示图片

一个零依赖的C++ 图形用户界面库

《开源精选》是我们分享Github、Gitee等开源社区中优质项目的栏目,包括技术、学习、实用与各种有趣的内容。本期推荐的是一个零依赖的C++ 图形用户界面库——ImGui。

Dear ImGui 是一个基于 C++ 的零依赖图形用户界面库,它特别适合集成到游戏引擎(用于工具)、实时 3D 应用程序、全屏应用程序、嵌入式应用程序或操作系统功能非标准的控制台平台上的任何应用程序中。


功能特性

  • ImGui的核心是独立包含在几个与平台无关的文件中,您可以在应用程序或者引擎中轻松编译存储库根文件夹中的所有文件(imgui*.cppimgui*.h)。
  • ImGui不需要特定的构建过程,您可以将 .cpp 文件添加到现有项目中。
  • ImGui可以渲染从后端传递的鼠标键盘游戏手柄输入等各种设置。
  • /backends文件夹中提供了各种图形 api 和渲染平台的后端,以及/examples文件夹中的示例应用程序。

示例代码

代码①:设置:深色样式(左),浅色样式(右)

ImGui::Text("Hello, world %d", );
if (ImGui::Button("Save"))
    MySaveFunction();
ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);

结果:

代码②:创建一个名为“My First Tool”的窗口,带有一个菜单栏。

// Create a window called "My First Tool", with a menu bar.
ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar())
{
    if (ImGui::BeginMenu("File"))
    {
        if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }
        if (ImGui::MenuItem("Save", "Ctrl+S"))   { /* Do stuff */ }
        if (ImGui::MenuItem("Close", "Ctrl+W"))  { my_tool_active = false; }
        ImGui::EndMenu();
    }
    ImGui::EndMenuBar();
}

// Edit a color (stored as ~4 floats)
ImGui::ColorEdit4("Color", my_color);

// Plot some values
const float my_values[] = { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f };
ImGui::PlotLines("Frame Times", my_values, IM_ARRAYSIZE(my_values));

// Display contents in a scrolling region
ImGui::TextColored(ImVec4(1,1,0,1), "Important Stuff");
ImGui::BeginChild("Scrolling");
for (int n = 0; n < ; n++)
    ImGui::Text("%04d: Some text", n);
ImGui::EndChild();
ImGui::End();

结果:

演示:调用 ImGui::ShowDemoWindow() 函数将创建一个演示窗口,展示各种功能和示例。该代码始终可参考 imgui_demo.cpp

项目展示


—END—

开源协议:Apache2.0

开源地址:
https://github.com/ocornut/imgui

原文链接:,转发请注明来源!