Set display name field now clamps to 31 unicode characters
Added ability to set max length in line editors by characters in addition to bytes left other widgets (comboboxes/spinners) using the bytes, but it can easily be changed over reviewed by Richardmaster
parent
e27ac0abf7
commit
ae623c8068
|
|
@ -484,7 +484,7 @@ void LLComboBox::createLineEditor(const LLComboBox::Params& p)
|
|||
LLLineEditor::Params params = p.combo_editor;
|
||||
params.rect(text_entry_rect);
|
||||
params.default_text(LLStringUtil::null);
|
||||
params.max_length_bytes(mMaxChars);
|
||||
params.max_length.bytes(mMaxChars);
|
||||
params.commit_callback.function(boost::bind(&LLComboBox::onTextCommit, this, _2));
|
||||
params.keystroke_callback(boost::bind(&LLComboBox::onTextEntry, this, _1));
|
||||
params.commit_on_focus_lost(false);
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ template class LLLineEditor* LLView::getChild<class LLLineEditor>(
|
|||
//
|
||||
|
||||
LLLineEditor::Params::Params()
|
||||
: max_length_bytes("max_length", 254),
|
||||
: max_length(""),
|
||||
keystroke_callback("keystroke_callback"),
|
||||
prevalidate_callback("prevalidate_callback"),
|
||||
background_image("background_image"),
|
||||
|
|
@ -108,7 +108,8 @@ LLLineEditor::Params::Params()
|
|||
|
||||
LLLineEditor::LLLineEditor(const LLLineEditor::Params& p)
|
||||
: LLUICtrl(p),
|
||||
mMaxLengthBytes(p.max_length_bytes),
|
||||
mMaxLengthBytes(p.max_length.bytes),
|
||||
mMaxLengthChars(p.max_length.chars),
|
||||
mCursorPos( 0 ),
|
||||
mScrollHPos( 0 ),
|
||||
mTextPadLeft(p.text_pad_left),
|
||||
|
|
@ -313,6 +314,12 @@ void LLLineEditor::setMaxTextLength(S32 max_text_length)
|
|||
mMaxLengthBytes = max_len;
|
||||
}
|
||||
|
||||
void LLLineEditor::setMaxTextChars(S32 max_text_chars)
|
||||
{
|
||||
S32 max_chars = llmax(0, max_text_chars);
|
||||
mMaxLengthChars = max_chars;
|
||||
}
|
||||
|
||||
void LLLineEditor::getTextPadding(S32 *left, S32 *right)
|
||||
{
|
||||
*left = mTextPadLeft;
|
||||
|
|
@ -358,6 +365,16 @@ void LLLineEditor::setText(const LLStringExplicit &new_text)
|
|||
}
|
||||
mText.assign(truncated_utf8);
|
||||
|
||||
if (mMaxLengthChars)
|
||||
{
|
||||
LLWString truncated_wstring = utf8str_to_wstring(truncated_utf8);
|
||||
if (truncated_wstring.size() > (U32)mMaxLengthChars)
|
||||
{
|
||||
truncated_wstring = truncated_wstring.substr(0, mMaxLengthChars);
|
||||
}
|
||||
mText.assign(wstring_to_utf8str(truncated_wstring));
|
||||
}
|
||||
|
||||
if (all_selected)
|
||||
{
|
||||
// ...keep whole thing selected
|
||||
|
|
@ -798,6 +815,7 @@ void LLLineEditor::addChar(const llwchar uni_char)
|
|||
}
|
||||
|
||||
S32 cur_bytes = mText.getString().size();
|
||||
|
||||
S32 new_bytes = wchar_utf8_length(new_c);
|
||||
|
||||
BOOL allow_char = TRUE;
|
||||
|
|
@ -807,6 +825,14 @@ void LLLineEditor::addChar(const llwchar uni_char)
|
|||
{
|
||||
allow_char = FALSE;
|
||||
}
|
||||
else if (mMaxLengthChars)
|
||||
{
|
||||
S32 wide_chars = mText.getWString().size();
|
||||
if ((wide_chars + 1) > mMaxLengthChars)
|
||||
{
|
||||
allow_char = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (allow_char)
|
||||
{
|
||||
|
|
@ -1107,6 +1133,13 @@ void LLLineEditor::pasteHelper(bool is_primary)
|
|||
clean_string = clean_string.substr(0, wchars_that_fit);
|
||||
LLUI::reportBadKeystroke();
|
||||
}
|
||||
|
||||
U32 available_chars = mMaxLengthChars - mText.getWString().size();
|
||||
|
||||
if (available_chars < clean_string.size())
|
||||
{
|
||||
clean_string = clean_string.substr(0, available_chars);
|
||||
}
|
||||
|
||||
mText.insert(getCursor(), clean_string);
|
||||
setCursor( getCursor() + (S32)clean_string.length() );
|
||||
|
|
|
|||
|
|
@ -59,11 +59,19 @@ public:
|
|||
|
||||
typedef boost::function<void (LLLineEditor* caller)> keystroke_callback_t;
|
||||
|
||||
struct MaxLength : public LLInitParam::Choice<MaxLength>
|
||||
{
|
||||
Alternative<S32> bytes, chars;
|
||||
|
||||
MaxLength() : bytes("max_length_bytes", 254),
|
||||
chars("max_length_chars", 0)
|
||||
{}
|
||||
};
|
||||
|
||||
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
|
||||
{
|
||||
Optional<std::string> default_text;
|
||||
Optional<S32> max_length_bytes;
|
||||
|
||||
Optional<MaxLength> max_length;
|
||||
Optional<keystroke_callback_t> keystroke_callback;
|
||||
|
||||
Optional<LLTextValidate::validate_func_t, LLTextValidate::ValidateTextNamedFuncs> prevalidate_callback;
|
||||
|
|
@ -214,6 +222,7 @@ public:
|
|||
void setKeystrokeCallback(callback_t callback, void* user_data);
|
||||
|
||||
void setMaxTextLength(S32 max_text_length);
|
||||
void setMaxTextChars(S32 max_text_chars);
|
||||
// Manipulate left and right padding for text
|
||||
void getTextPadding(S32 *left, S32 *right);
|
||||
void setTextPadding(S32 left, S32 right);
|
||||
|
|
@ -277,6 +286,7 @@ protected:
|
|||
LLViewBorder* mBorder;
|
||||
const LLFontGL* mGLFont;
|
||||
S32 mMaxLengthBytes; // Max length of the UTF8 string in bytes
|
||||
S32 mMaxLengthChars; // Maximum number of characters in the string
|
||||
S32 mCursorPos; // I-beam is just after the mCursorPos-th character.
|
||||
S32 mScrollHPos; // Horizontal offset from the start of mText. Used for scrolling.
|
||||
LLFrameTimer mScrollTimer;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ LLMultiSliderCtrl::LLMultiSliderCtrl(const LLMultiSliderCtrl::Params& p)
|
|||
params.name("MultiSliderCtrl Editor");
|
||||
params.rect(text_rect);
|
||||
params.font(p.font);
|
||||
params.max_length_bytes(MAX_STRING_LENGTH);
|
||||
params.max_length.bytes(MAX_STRING_LENGTH);
|
||||
params.commit_callback.function(LLMultiSliderCtrl::onEditorCommit);
|
||||
params.prevalidate_callback(&LLTextValidate::validateFloat);
|
||||
params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM);
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
|
|||
{
|
||||
params.font(p.font);
|
||||
}
|
||||
params.max_length_bytes(MAX_STRING_LENGTH);
|
||||
params.max_length.bytes(MAX_STRING_LENGTH);
|
||||
params.commit_callback.function((boost::bind(&LLSpinCtrl::onEditorCommit, this, _2)));
|
||||
|
||||
if( mPrecision>0 )//should accept float numbers
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ LLFolderView::LLFolderView(const Params& p)
|
|||
params.name("ren");
|
||||
params.rect(rect);
|
||||
params.font(getLabelFontForStyle(LLFontGL::NORMAL));
|
||||
params.max_length_bytes(DB_INV_ITEM_NAME_STR_LEN);
|
||||
params.max_length.bytes(DB_INV_ITEM_NAME_STR_LEN);
|
||||
params.commit_callback.function(boost::bind(&LLFolderView::commitRename, this, _2));
|
||||
params.prevalidate_callback(&LLTextValidate::validateASCIIPrintableNoPipe);
|
||||
params.commit_on_focus_lost(true);
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ LLLocationInputCtrl::LLLocationInputCtrl(const LLLocationInputCtrl::Params& p)
|
|||
LLLineEditor::Params params = p.combo_editor;
|
||||
params.rect(text_entry_rect);
|
||||
params.default_text(LLStringUtil::null);
|
||||
params.max_length_bytes(p.max_chars);
|
||||
params.max_length.bytes(p.max_chars);
|
||||
params.keystroke_callback(boost::bind(&LLLocationInputCtrl::onTextEntry, this, _1));
|
||||
params.commit_on_focus_lost(false);
|
||||
params.follows.flags(FOLLOWS_ALL);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ LLToastAlertPanel::LLToastAlertPanel( LLNotificationPtr notification, bool modal
|
|||
LLNotificationFormPtr form = mNotification->getForm();
|
||||
std::string edit_text_name;
|
||||
std::string edit_text_contents;
|
||||
S32 edit_text_max_chars = 0;
|
||||
bool is_password = false;
|
||||
|
||||
LLToastPanel::setBackgroundVisible(FALSE);
|
||||
|
|
@ -115,6 +116,7 @@ LLToastAlertPanel::LLToastAlertPanel( LLNotificationPtr notification, bool modal
|
|||
{
|
||||
edit_text_contents = (*it)["value"].asString();
|
||||
edit_text_name = (*it)["name"].asString();
|
||||
edit_text_max_chars = (*it)["max_length_chars"].asInteger();
|
||||
}
|
||||
else if (type == "password")
|
||||
{
|
||||
|
|
@ -253,6 +255,7 @@ LLToastAlertPanel::LLToastAlertPanel( LLNotificationPtr notification, bool modal
|
|||
mLineEditor->setName(edit_text_name);
|
||||
mLineEditor->reshape(leditor_rect.getWidth(), leditor_rect.getHeight());
|
||||
mLineEditor->setRect(leditor_rect);
|
||||
mLineEditor->setMaxTextChars(edit_text_max_chars);
|
||||
mLineEditor->setText(edit_text_contents);
|
||||
|
||||
// decrease limit of line editor of teleport offer dialog to avoid truncation of
|
||||
|
|
|
|||
|
|
@ -3197,7 +3197,7 @@ Press reset to make it the same as your username.
|
|||
|
||||
Change your display name?
|
||||
<form name="form">
|
||||
<input name="display_name" type="text">
|
||||
<input name="display_name" max_length_chars="31" type="text">
|
||||
[DISPLAY_NAME]
|
||||
</input>
|
||||
<button
|
||||
|
|
|
|||
Loading…
Reference in New Issue