c++ - 如何在 ImGui 中更改 InputText 的文本颜色?
问题描述
我正在寻找如何更改“名称”打印上显示的文本的颜色,但我对如何做到这一点一无所知。我想让它变成绿色,感谢帮助或提示:D
// Name
ImGui::InputText("Name", selected_entry.name, 32);
解决方案
可以使用样式在全局范围内更改文本颜色
ImGuiStyle* style = &ImGui::GetStyle();
style->Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.00f);
单个小部件的颜色可以通过推送/弹出样式更改
char txt_green[] = "text green";
char txt_def[] = "text default";
// Particular widget styling
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0,255,0,255));
ImGui::InputText("##text1", txt_green, sizeof(txt_green));
ImGui::PopStyleColor();
...
// Use global style colors
ImGui::InputText("##text2", txt_def, sizeof(txt_def));
输出:
同样,如果您想为输入文本和标签使用不同的颜色,我建议您轻松使用两个小部件。
char txt_def[] = "text default";
ImGui::InputText("##Name", txt_def, sizeof(txt_def));
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255));
ImGui::Text("Name");
ImGui::PopStyleColor();
推荐阅读
- android - 重新启动 Android Studio 时选定的构建变体发生变化
- big-o - 你如何用大 O、theta、omega 表示以 100 (n) 为底的对数
- c++ - C++ 比较共享指针堆栈
- angular - Angular 6:如何将脚本捆绑到库项目中?
- mysql - 反应提交到 Flask POST 方法不写入数据库(使用 Axios)
- ios - 使用 iOS 版 Imagesharp 时如何修复 Null 引用错误?
- ios - 如何使用纬度和经度获取加号
- debugging - 如何获取内核函数的参数并将void指针转换为SystemTap中的char?
- r - 使用 `rgbif` 包从 `occ_search` 查询中排除国家
- javascript - 如何在播放视频时弹出模态