How can I change text color of my InputText in ImGui?
Asked Answered
Q

1

10

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


Quip answered 17/5, 2020 at 14:39 Comment(2)
q.v. github.com/ocornut/imgui/issues/2144Irina
I changed the title because of the 2 current answers have nothing at all to do with ImGui which is the topic of the question.Trigonous
M
19

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:

Manxman answered 13/7, 2021 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.