Don't trigger text alignment for editboxes

This commit is contained in:
Jupeyy 2020-11-15 07:01:53 +01:00
parent d31397ade4
commit 51a31774f8
4 changed files with 24 additions and 22 deletions

View file

@ -42,6 +42,8 @@
#include "menus.h" #include "menus.h"
#include "skins.h" #include "skins.h"
#include <limits>
ColorRGBA CMenus::ms_GuiColor; ColorRGBA CMenus::ms_GuiColor;
ColorRGBA CMenus::ms_ColorTabbarInactiveOutgame; ColorRGBA CMenus::ms_ColorTabbarInactiveOutgame;
ColorRGBA CMenus::ms_ColorTabbarActiveOutgame; ColorRGBA CMenus::ms_ColorTabbarActiveOutgame;
@ -351,7 +353,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
for(int i = 1; i <= Len; i++) for(int i = 1; i <= Len; i++)
{ {
if(TextRender()->TextWidth(0, FontSize, pStr, i, -1.0f) - *Offset > MxRel) if(TextRender()->TextWidth(0, FontSize, pStr, i, std::numeric_limits<float>::max()) - *Offset > MxRel)
{ {
s_AtIndex = i - 1; s_AtIndex = i - 1;
break; break;
@ -473,11 +475,11 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
// check if the text has to be moved // check if the text has to be moved
if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || m_NumInputEvents)) if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || m_NumInputEvents))
{ {
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, -1.0f); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits<float>::max());
if(w - *Offset > Textbox.w) if(w - *Offset > Textbox.w)
{ {
// move to the left // move to the left
float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, -1.0f); float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, std::numeric_limits<float>::max());
do do
{ {
*Offset += minimum(wt - *Offset - Textbox.w, Textbox.w / 3); *Offset += minimum(wt - *Offset - Textbox.w, Textbox.w / 3);
@ -506,10 +508,8 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
// render the cursor // render the cursor
if(UI()->LastActiveItem() == pID && !JustGotActive) if(UI()->LastActiveItem() == pID && !JustGotActive)
{ {
float OffsetGlyph = TextRender()->GetGlyphOffsetX(FontSize, '|'); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits<float>::max());
Textbox.x += w;
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, -1);
Textbox.x += w + OffsetGlyph;
if((2 * time_get() / time_freq()) % 2) if((2 * time_get() / time_freq()) % 2)
{ {

View file

@ -441,7 +441,7 @@ int CUI::DoButton(const void *id, const char *text, int checked, const CUIRect *
return ret; return ret;
}*/ }*/
void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically) void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically)
{ {
float AlignedSize = 0; float AlignedSize = 0;
float MaxCharacterHeightInLine = 0; float MaxCharacterHeightInLine = 0;
@ -465,12 +465,12 @@ void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, in
} }
} }
void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically) void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically)
{ {
DoLabel(r, pText, Size * Scale(), Align, MaxWidth, AlignVertically); DoLabel(r, pText, Size * Scale(), Align, MaxWidth, AlignVertically);
} }
void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor) void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor)
{ {
float AlignedSize = 0; float AlignedSize = 0;
float MaxCharacterHeightInLine = 0; float MaxCharacterHeightInLine = 0;
@ -515,7 +515,7 @@ void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, cons
RectEl.m_TextOutlineColor = TextRender()->GetTextOutlineColor(); RectEl.m_TextOutlineColor = TextRender()->GetTextOutlineColor();
} }
void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor) void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor)
{ {
bool NeedsRecreate = false; bool NeedsRecreate = false;
bool ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor(); bool ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor();

View file

@ -258,11 +258,11 @@ public:
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY); int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
// TODO: Refactor: Remove this? // TODO: Refactor: Remove this?
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1, int AlignVertically = 1); void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1);
void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1, int AlignVertically = 1); void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1);
void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL); void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL); void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
}; };
#endif #endif

View file

@ -35,6 +35,8 @@
#include "auto_map.h" #include "auto_map.h"
#include "editor.h" #include "editor.h"
#include <limits>
static const char *VANILLA_IMAGES[] = { static const char *VANILLA_IMAGES[] = {
"bg_cloud1", "bg_cloud1",
"bg_cloud2", "bg_cloud2",
@ -352,7 +354,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
for(int i = 1; i <= Len; i++) for(int i = 1; i <= Len; i++)
{ {
if(TextRender()->TextWidth(0, FontSize, pStr, i, -1.0f) - *Offset > MxRel) if(TextRender()->TextWidth(0, FontSize, pStr, i, std::numeric_limits<float>::max()) - *Offset > MxRel)
{ {
s_AtIndex = i - 1; s_AtIndex = i - 1;
break; break;
@ -451,11 +453,11 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
// check if the text has to be moved // check if the text has to be moved
if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || Input()->NumEvents())) if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || Input()->NumEvents()))
{ {
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, -1.0f); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, std::numeric_limits<float>::max());
if(w - *Offset > Textbox.w) if(w - *Offset > Textbox.w)
{ {
// move to the left // move to the left
float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, -1.0f); float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, std::numeric_limits<float>::max());
do do
{ {
*Offset += minimum(wt - *Offset - Textbox.w, Textbox.w / 3); *Offset += minimum(wt - *Offset - Textbox.w, Textbox.w / 3);
@ -473,18 +475,18 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
UI()->ClipEnable(pRect); UI()->ClipEnable(pRect);
Textbox.x -= *Offset; Textbox.x -= *Offset;
UI()->DoLabel(&Textbox, pDisplayStr, FontSize, -1, Textbox.w * 2.0f); UI()->DoLabel(&Textbox, pDisplayStr, FontSize, -1, std::numeric_limits<float>::max());
// render the cursor // render the cursor
if(UI()->LastActiveItem() == pID && !JustGotActive) if(UI()->LastActiveItem() == pID && !JustGotActive)
{ {
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, Textbox.w * 2.0f); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, std::numeric_limits<float>::max());
Textbox = *pRect; Textbox = *pRect;
Textbox.VSplitLeft(2.0f, 0, &Textbox); Textbox.VSplitLeft(2.0f, 0, &Textbox);
Textbox.x += (w - *Offset - TextRender()->TextWidth(0, FontSize, "|", -1, Textbox.w * 2.0f) / 2); Textbox.x += (w - *Offset - TextRender()->TextWidth(0, FontSize, "|", -1, std::numeric_limits<float>::max()) / 2);
if((2 * time_get() / time_freq()) % 2) // make it blink if((2 * time_get() / time_freq()) % 2) // make it blink
UI()->DoLabel(&Textbox, "|", FontSize, -1, Textbox.w * 2.0f); UI()->DoLabel(&Textbox, "|", FontSize, -1, std::numeric_limits<float>::max());
} }
UI()->ClipDisable(); UI()->ClipDisable();