简体   繁体   中英

How can I change text color of my InputText in ImGui? (unanswered)

I am looking to figure out how I can change the color of the text displayed on the "Name" print, but I am pretty much clueless on how to do so. I would like to make it green, help or tips are appreciated:D

// Name
            ImGui::InputText("Name", selected_entry.name, 32);


Globally the text color can be changed using style

ImGuiStyle* style = &ImGui::GetStyle();
style->Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.00f);

Color of a single widget alone can be changed by push/pop styles

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));

Output:

彩色文本输入

Again if you want separate colors for input text and label i would suggest to go with two widgets easily.

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();

输出:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM