imgui Study
描述
学习游戏引擎看到这个模块,就入门学习了一下。是一个比较轻量级的入门GUI模块。
使用方法
在win下,工程中只需要导入下面的代码:
编写imgui.cmake:
set(imgui_SOURCE_DIR_ ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
file(GLOB imgui_sources CONFIGURE_DEPENDS "${imgui_SOURCE_DIR_}/*.cpp")
file(GLOB imgui_sourcesh CONFIGURE_DEPENDS "${imgui_SOURCE_DIR_}/*.h")
add_library(imgui STATIC ${imgui_sources} ${imgui_sourcesh})
编写cmakelist:
if(NOT TARGET imgui)
include(imgui.cmake)
set_target_properties(imgui PROPERTIES FOLDER 3rdparty/imgui)
endif()
然后其他地方可以这个库了。
贴几个例子吧:
static bool open = true;
if (open) {
ImGui::Begin("my windows", &open, ImGuiWindowFlags_None); //新建一个窗口
{
if (ImGui::Button("button")) { // 加一个按钮
//std::cout << "button" << std::endl;
}
static int a = 0;
ImGui::RadioButton("radioButton", &a, 1); //单选按钮
ImGui::RadioButton("radioButton1", &a, 2);
ImGui::RadioButton("radioButton2", &a, 3);
//std::cout << a << std::endl;
static bool b = true;
ImGui::Checkbox("checkbox", &b); // 多选按钮
std::cout << b << std::endl;
ImGui::Text("i am text"); //文本
ImGui::BulletText("i am text"); // 前面有排版点的文本
HelpMarker("this is a HelpMarker"); //问号说明
static float c = 0.f;
ImGui::SliderFloat3(u8"sliderfloat中文", &c, 0.f1.f); //滑块
static int d = 0;
//ImGui::SliderInt("sliderint", &d, 0, 100);
}
ImGui::End();
}
ImGui::GetForegroundDrawList()->AddLine(ImVec2(500, 200ImVec2(500, 600), IM_COL32(255, 43, 255, 255), 1.5f); // 画一个线
ImGui::GetForegroundDrawList()->AddText(ImVec2(500, 500IM_COL32(255, 43, 255, 255), u8"中文"); //加文本
ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\msyh.ttc", 18.0f, NULL, io.Fonts->GetGlyphRangesChineseFull()); //修改字体
ImGui::StyleColorsLight(); //修改颜色