如何在Imgui中使用图标字体

 时间:2026-02-16 10:33:41

1、从github上搜索imgui,找到dear-imgui的下载处,下载源码并解压到硬盘任意目录中。如何在imgui中使用iconfont的说明就在源码目录中的misc/fonts/readme文件中。

如何在Imgui中使用图标字体

2、有若干icon font可供选择,如FontAwesome,Openfonticons等。

这一步需要下载juliettef的cionfontcppheaders,此头文件包含utf-8字体的头文件。

3、添加头文件iconfsfontawesome4.h。

在源文件中添加以下代码。

io.Fonts->AddFontDefault();

ImFontConfig config;

config.MergeMode = true;

config.GlyphMinAdvanceX = 16.0f; 

static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; 

io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf",16.0f, &config, icon_ranges);

这一步的目的是程序在启动时加载必须的字体文件。

4、下载fontawesome-webfont.ttf 字体文件,与编译后的exe文件放到同一目录下。添加以下代码

ImGui::Begin("mytoolbar", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize  | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus);

ImGui::Button(ICON_FA_SEARCH );

ImGui::SameLine();

ImGui::Button(ICON_FA_HOME);

ImGui::SameLine();

ImGui::Button(ICON_FA_PLAY_CIRCLE_O); ImGui::SameLine();

ImGui::Button(ICON_FA_LOCK); ImGui::SameLine();

ImGui::Button(ICON_FA_PLAY); ImGui::SameLine();

ImGui::Button(ICON_FA_PAUSE); ImGui::SameLine();

ImGui::Button(ICON_FA_STOP); ImGui::SameLine();

ImGui::Button(ICON_FA_TIMES_CIRCLE_O); ImGui::SameLine();

ImGui::Button(ICON_FA_KEY); ImGui::SameLine();

ImGui::Button(ICON_FA_USERS); ImGui::SameLine();

ImGui::Button(ICON_FA_FLOPPY_O); ImGui::SameLine();

ImGui::Button(ICON_FA_REFRESH); ImGui::SameLine();

ImGui::Button(ICON_FA_KEY); ImGui::SameLine();

ImGui::Button(ICON_FA_KEY); ImGui::SameLine();

ImGui::End();

即可创建一个带图形按钮的工具栏。

  • Egde浏览器中怎么获取“音量控制”
  • win 10更新后,有线网卡不能使用,时断时续
  • 剑与远征种族卡池单抽劵怎么获得
  • adb命令如何选择特定的手机进行操作?
  • Steam错误代码-2无法载入网页未知错误怎么解决
  • 热门搜索
    奥奇传说精灵大全图片 鬼片大全最恐怖片 necklace怎么读 五行属火的字大全 影视大全韩国在线观看 数字骂人顺口溜大全 低烧怎么退烧 长城资料简介 狮子林简介 播放器大全