mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
Don't trigger text alignment for editboxes
This commit is contained in:
parent
d31397ade4
commit
51a31774f8
|
@ -42,6 +42,8 @@
|
|||
#include "menus.h"
|
||||
#include "skins.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
ColorRGBA CMenus::ms_GuiColor;
|
||||
ColorRGBA CMenus::ms_ColorTabbarInactiveOutgame;
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
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
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
*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
|
||||
if(UI()->LastActiveItem() == pID && !JustGotActive)
|
||||
{
|
||||
float OffsetGlyph = TextRender()->GetGlyphOffsetX(FontSize, '|');
|
||||
|
||||
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, -1);
|
||||
Textbox.x += w + OffsetGlyph;
|
||||
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits<float>::max());
|
||||
Textbox.x += w;
|
||||
|
||||
if((2 * time_get() / time_freq()) % 2)
|
||||
{
|
||||
|
|
|
@ -441,7 +441,7 @@ int CUI::DoButton(const void *id, const char *text, int checked, const CUIRect *
|
|||
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 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);
|
||||
}
|
||||
|
||||
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 MaxCharacterHeightInLine = 0;
|
||||
|
@ -515,7 +515,7 @@ void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, cons
|
|||
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 ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor();
|
||||
|
|
|
@ -258,11 +258,11 @@ public:
|
|||
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
|
||||
|
||||
// TODO: Refactor: Remove this?
|
||||
void DoLabel(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, 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, 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 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 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, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "auto_map.h"
|
||||
#include "editor.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
static const char *VANILLA_IMAGES[] = {
|
||||
"bg_cloud1",
|
||||
"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++)
|
||||
{
|
||||
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;
|
||||
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
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
*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);
|
||||
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
|
||||
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.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
|
||||
UI()->DoLabel(&Textbox, "|", FontSize, -1, Textbox.w * 2.0f);
|
||||
UI()->DoLabel(&Textbox, "|", FontSize, -1, std::numeric_limits<float>::max());
|
||||
}
|
||||
UI()->ClipDisable();
|
||||
|
||||
|
|
Loading…
Reference in a new issue