Imgui: text line horizontal align

Created on 16 Dec 2015  路  6Comments  路  Source: ocornut/imgui

I want centered message on window
how ?

Most helpful comment

You have to do it manually at the moment (using CalcTextSize + SetCursorPosX + Text).
There are internal api doing it but they aren't finalised.

All 6 comments

You have to do it manually at the moment (using CalcTextSize + SetCursorPosX + Text).
There are internal api doing it but they aren't finalised.

Closing this. I hope to add better alignment primitives in the future.

thanks for the method !

Is this not in the API yet?

No it isn't yet.

void TextCenter(std::string text) {
float font_size = ImGui::GetFontSize() * text.size() / 2;
ImGui::SameLine(
ImGui::GetWindowSize().x / 2 -
font_size + (font_size / 2)
);

ImGui::Text(text.c_str());

}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DarkLinux picture DarkLinux  路  3Comments

bizehao picture bizehao  路  3Comments

the-lay picture the-lay  路  3Comments

spaderthomas picture spaderthomas  路  3Comments

noche-x picture noche-x  路  3Comments