Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colored Words #262

Closed
Pastor111 opened this issue Jul 28, 2021 · 5 comments
Closed

Colored Words #262

Pastor111 opened this issue Jul 28, 2021 · 5 comments

Comments

@Pastor111
Copy link

Is there a way to change the color of a specific word in a text?

@SMACheats
Copy link

ye ImGui.TextColored(new Vector4(0.0f, 1.0f, 0.24f, 1.0f), "Your Text"); // Green

@rlalance
Copy link

Guys, please look into the API before asking such trivial questions LOL

@mellinoe
Copy link
Collaborator

mellinoe commented Jan 1, 2022

@SMACheats provided the closest feature here. As far as I know, there's no way to do "rich text" markup a la Unity's gui, e.g. ImGui.Text("hello <color=red>world</color>");. See this issue: ocornut/imgui#902. So your best bet is to use Text+TextColored and SameLine.

@mellinoe mellinoe closed this as completed Jan 1, 2022
@ClownedOpenSource
Copy link

FIX FOUND

        public static void ImGuiColorText(String Text, Color color)
        {
            ImGui.TextColored(ColorToVector4(color), Text);
        }

        private static Vector4 ColorToVector4(Color Color)
        {
            return new Vector4((float)Color.R / 255.0f, (float)Color.G / 255.0f, (float)Color.B / 255.0f, (float)Color.A / 255.0f);
        }

@guillaC
Copy link

guillaC commented Sep 7, 2023

You can also simply cast like this: ImGui.TextColored((Vector4)Color.Violet, "Hey");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants