Use SetCursorPosX() instead of SameLine() to center text

pull/430/head
Alessandro Toia 4 years ago
parent b77517501c
commit c479694735

@ -498,14 +498,14 @@ void HudElements::show_fps_limit(){
}
void HudElements::custom_header(){
ImGui::TableAutoHeaders();
ImGui::TableNextRow();
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TableAutoHeaders();
std::string text = HUDElements.params->custom_header;
center_text(text);
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.colors.text, "%s",text.c_str());
ImGui::Text("\n");
ImGui::PopFont();
ImGui::NewLine();
}
void HudElements::graphs(){

@ -220,9 +220,7 @@ void right_aligned_text(ImVec4& col, float off_x, const char *fmt, ...)
void center_text(std::string& text)
{
float font_size = ImGui::GetFontSize() * text.size() / 2;
ImGui::SameLine(ImGui::GetWindowSize().x / 2 -font_size + (font_size /1.4));
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2 )- (ImGui::CalcTextSize(text.c_str()).x / 2));
}
float get_ticker_limited_pos(float pos, float tw, float& left_limit, float& right_limit)

Loading…
Cancel
Save