9

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


Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
Suarez
  • 93
  • 1
  • 1
  • 4

1 Answers1

17

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:

color text inputs

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

Output:

Naveen
  • 459
  • 4
  • 10