From c039536b26d7db358995d89c24e83b783d7c094b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 3 Apr 2026 15:53:08 -0300 Subject: [PATCH] Added `input-mode` to UITextInput and deprecated UITextInputPassword to simplify the implementation. Added Http::setDefaultUserAgent. --- docs/articles/cssspecification.md | 35 +++-- include/eepp/network/http.hpp | 4 + include/eepp/ui.hpp | 1 - include/eepp/ui/css/propertydefinition.hpp | 1 + include/eepp/ui/htmltextinput.hpp | 2 + include/eepp/ui/uitextinput.hpp | 23 ++++ include/eepp/ui/uitextinputpassword.hpp | 50 ------- src/eepp/network/http.cpp | 15 ++- src/eepp/ui/css/stylesheetspecification.cpp | 1 + src/eepp/ui/htmlinput.cpp | 3 +- src/eepp/ui/htmltextinput.cpp | 13 +- src/eepp/ui/uilistbox.cpp | 2 +- src/eepp/ui/uitextinput.cpp | 136 ++++++++++++++++++-- src/eepp/ui/uitextinputpassword.cpp | 134 ------------------- src/eepp/ui/uiwidgetcreator.cpp | 5 +- src/examples/ui_html/ui_html.cpp | 3 + src/tests/test_all/test.cpp | 2 +- src/tests/unit_tests/uihtml_tests.cpp | 11 +- 18 files changed, 211 insertions(+), 230 deletions(-) delete mode 100644 include/eepp/ui/uitextinputpassword.hpp delete mode 100644 src/eepp/ui/uitextinputpassword.cpp diff --git a/docs/articles/cssspecification.md b/docs/articles/cssspecification.md index 9bd779d5e..abd20f914 100644 --- a/docs/articles/cssspecification.md +++ b/docs/articles/cssspecification.md @@ -906,7 +906,7 @@ Sets the hint font shadow offset. * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside text or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword), EE::UI::UIPushButton (PushButton), EE::UI::UIToolti + EE::UI::UIPushButton (PushButton), EE::UI::UIToolti (Tooltip) * Data Type: [vector2-length](#vector2-length-data-type) * Default offset: `1dp 1dp` @@ -990,6 +990,19 @@ in which these items are displayed/sorted inside the button. --- +### input-mode + +Sets the input mode of the element. + +* Applicable to: EE::UI::UITextInput (TextInput) +* Data Type: [string-list](#string-list-data-type) +* Value List: + * `normal`: Normal text input. + * `password`: Password text input (bullets). +* Default value: `normal` + +--- + ### layout-gravity The layout gravity defines how the element gravitates against its parent (when possible). Gravity @@ -1742,8 +1755,7 @@ Sets the text selection background color on a text element that supports text se * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput - (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword) + (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList) * Data Type: [color](#color-data-type) * Default color: `#323232` @@ -1756,7 +1768,7 @@ Sets the text selection color on a text element that supports text selection. * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside text or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword), EE::UI::UIPushButton (PushButton) + EE::UI::UIPushButton (PushButton) * Data Type: [color](#color-data-type) * Default color: `white` @@ -1918,8 +1930,7 @@ code implementation, but it's available as an option. * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword), EE::UI::UITooltip (Tooltip), EE::UI::UITab (Tab), - EE::UI::UITextEdit (TextEdit) + EE::UI::UITooltip (Tooltip), EE::UI::UITab (Tab), EE::UI::UITextEdit (TextEdit) * Data Type: [string](#string-data-type) * Default value: _No value_ @@ -1954,8 +1965,7 @@ Enables/disables text selection in any element that contains text. * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword), EE::UI::UITooltip (Tooltip), EE::UI::UITab (Tab), - EE::UI::UITextEdit (TextEdit) + EE::UI::UITooltip (Tooltip), EE::UI::UITab (Tab), EE::UI::UITextEdit (TextEdit) * Data Type: [boolean](#boolean-data-type) * Default value: `true` for TextEdit, TextInput. `false` for any other element. @@ -1968,8 +1978,7 @@ Sets the text shadow color. * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside text or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword), EE::UI::UIPushButton (PushButton), EE::UI::UIToolti - (Tooltip) + EE::UI::UIPushButton (PushButton), EE::UI::UITooltip (Tooltip) * Data Type: [color](#color-data-type) * Default color: `#323232E6` @@ -1982,8 +1991,7 @@ Sets the text shadow offset. * Applicable to: EE::UI::UITextView (TextView) and any element that holds inside text or extends from a TextView. EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), EE::UI::UITextInput (TextInput), EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList), - EE::UI::UITextInputPassword (TextInputPassword), EE::UI::UIPushButton (PushButton), EE::UI::UIToolti - (Tooltip) + EE::UI::UIPushButton (PushButton), EE::UI::UITooltip (Tooltip) * Data Type: [vector2-length](#vector2-length-data-type) * Default offset: `1dp 1dp` @@ -2355,8 +2363,7 @@ Enables/disables word-wrap in the text view element. * Applicable to: EE::UI::UITextVIew (TextView), EE::UI::UITextInput (TextInput), EE::UI::UICheckBox (CheckBox), EE::UI::UIRadioButton (RadioButton), - EE::UI::UIListBoxItem (ListBox::item), EE::UI::UITextInputPassword (TextInputPassword), - EE::UI::UIDropDownList (DropDownList). + EE::UI::UIListBoxItem (ListBox::item), EE::UI::UIDropDownList (DropDownList). * Data Type: [boolean](#boolean-data-type) * Default value: `false` diff --git a/include/eepp/network/http.hpp b/include/eepp/network/http.hpp index 49caaa640..513576302 100644 --- a/include/eepp/network/http.hpp +++ b/include/eepp/network/http.hpp @@ -396,6 +396,10 @@ class EE_API Http : NonCopyable { URI mProxy; ///< Proxy information }; + static void setDefaultUserAgent( const std::string& userAgent ); + + static std::string getDefaultUserAgent(); + /** @brief Default constructor */ Http(); diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index 3cdb6e307..1d27b6b43 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -147,7 +147,6 @@ #include #include #include -#include #include #include #include diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index 891dc6bbe..e02c7a5c0 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -237,6 +237,7 @@ enum class PropertyId : Uint32 { Type = String::hash( "type" ), Rows = String::hash( "rows" ), Cols = String::hash( "cols" ), + InputMode = String::hash( "input-mode" ), }; enum class PropertyType : Uint32 { diff --git a/include/eepp/ui/htmltextinput.hpp b/include/eepp/ui/htmltextinput.hpp index 29e529c0d..247ed9da0 100644 --- a/include/eepp/ui/htmltextinput.hpp +++ b/include/eepp/ui/htmltextinput.hpp @@ -33,6 +33,8 @@ class EE_API HTMLTextInput : public UITextInput { void setHtmlSize( Uint32 size ); protected: + HTMLTextInput( const std::string& tag ); + Uint32 mHtmlSize{ 20 }; bool mPacking{ false }; }; diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index d873824dc..4fa7c5e69 100644 --- a/include/eepp/ui/uitextinput.hpp +++ b/include/eepp/ui/uitextinput.hpp @@ -15,8 +15,12 @@ class UIMenuItem; class EE_API UITextInput : public UITextView, public TextDocument::Client { public: + enum class TextInputMode { Normal, Password }; + static UITextInput* New(); + static UITextInput* NewPassword(); + static UITextInput* NewWithTag( const std::string& tag ); virtual ~UITextInput(); @@ -119,6 +123,14 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { void setSelectAllDocOnTabNavigate( bool selectAllDocOnTabNavigate ); + UITextInput* setMode( TextInputMode mode ); + + TextInputMode getMode() const; + + const String& getBulletCharacter() const; + + void setBulletCharacter( const String& bulletCharacter ); + Client::Type getTextDocumentClientType() { return TextDocument::Client::Core; } protected: @@ -145,6 +157,9 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { Uint64 mLastExecuteEventId{ 0 }; String::HashType mLastCmdHash{ 0 }; HintDisplay mHintDisplay{ HintDisplay::Always }; + TextInputMode mMode{ TextInputMode::Normal }; + Text* mPassCache{ nullptr }; + String mBulletCharacter{ "●" }; UITextInput(); @@ -180,6 +195,8 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { virtual void onFontChanged(); + virtual void onFontStyleChanged(); + void onThemeLoaded(); virtual void onCursorPosChange(); @@ -190,6 +207,12 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { virtual void updateText(); + virtual void updatePass(); + + virtual void updateFontStyleConfig(); + + virtual Text& getVisibleTextCache(); + virtual void selCurInit( const Int32& init ); virtual void selCurEnd( const Int32& end ); diff --git a/include/eepp/ui/uitextinputpassword.hpp b/include/eepp/ui/uitextinputpassword.hpp deleted file mode 100644 index e4fef8936..000000000 --- a/include/eepp/ui/uitextinputpassword.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef EE_UICUITEXTINPUTPASSWORD_HPP -#define EE_UICUITEXTINPUTPASSWORD_HPP - -#include - -namespace EE { namespace UI { - -class EE_API UITextInputPassword : public UITextInput { - public: - static UITextInputPassword* New(); - - virtual ~UITextInputPassword(); - - virtual void draw(); - - virtual const String& getText() const; - - virtual UITextView* setText( const String& text ); - - const Text& getPassCache() const; - - const String& getBulletCharacter() const; - - void setBulletCharacter( const String& bulletCharacter ); - - protected: - UITextInputPassword(); - - Text mPassCache; - Vector2f mHintAlignOffset; - String mBulletCharacter; - - void updateText(); - - void updatePass( const String& pass ); - - void updateFontStyleConfig(); - - virtual void onStateChange(); - - virtual void onFontChanged(); - - virtual void onFontStyleChanged(); - - virtual Text& getVisibleTextCache(); -}; - -}} // namespace EE::UI - -#endif diff --git a/src/eepp/network/http.cpp b/src/eepp/network/http.cpp index b6a9a24d5..fbc190245 100644 --- a/src/eepp/network/http.cpp +++ b/src/eepp/network/http.cpp @@ -27,6 +27,17 @@ namespace EE { namespace Network { #define PACKET_BUFFER_SIZE ( 16384 ) +static std::string sDefaultUserAgent = "Mozilla/5.0 (Linux; x86_64) eepp-network/1.0 " + "Chrome/146.0.0.0 AppleWebKit/537.36 Safari/537.36"; + +void Http::setDefaultUserAgent( const std::string& userAgent ) { + sDefaultUserAgent = userAgent; +} + +std::string Http::getDefaultUserAgent() { + return sDefaultUserAgent; +} + std::string Http::Request::statusToString( Http::Request::Status status ) { switch ( status ) { case Connected: @@ -220,7 +231,7 @@ std::string Http::Request::prepareTunnel( const Http& http ) { setField( "Host", String::format( "%s:%d", http.getHostName().c_str(), http.getPort() ) ); setField( "Proxy-Connection", "Keep-Alive" ); - setField( "User-Agent", "eepp-network" ); + setField( "User-Agent", sDefaultUserAgent ); for ( FieldTable::const_iterator i = mFields.begin(); i != mFields.end(); ++i ) out << i->first << ": " << i->second << "\r\n"; @@ -1278,7 +1289,7 @@ Http::Request Http::prepareFields( const Http::Request& request ) { Request toSend( request ); if ( !toSend.hasField( "User-Agent" ) ) - toSend.setField( "User-Agent", "eepp-network" ); + toSend.setField( "User-Agent", sDefaultUserAgent ); if ( !toSend.hasField( "Accept" ) ) toSend.setField( "Accept", "*/*" ); diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index 4268c5867..e8248fe6e 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -418,6 +418,7 @@ void StyleSheetSpecification::registerDefaultProperties() { registerProperty( "type", "text" ).setType( PropertyType::String ); registerProperty( "rows", "2" ).setType( PropertyType::NumberInt ); registerProperty( "cols", "20" ).setType( PropertyType::NumberInt ); + registerProperty( "input-mode", "normal" ).setType( PropertyType::String ); registerProperty( "inner-widget-orientation", "widgeticontextbox" ) .setType( PropertyType::String ); diff --git a/src/eepp/ui/htmlinput.cpp b/src/eepp/ui/htmlinput.cpp index 6984cf610..cf3926c24 100644 --- a/src/eepp/ui/htmlinput.cpp +++ b/src/eepp/ui/htmlinput.cpp @@ -6,7 +6,6 @@ #include #include #include -#include namespace EE { namespace UI { @@ -118,7 +117,7 @@ void HTMLInput::createChildWidget() { } else if ( mInputType == "number" ) { mChildWidget = UISpinBox::New(); } else if ( mInputType == "password" ) { - mChildWidget = UITextInputPassword::New(); + mChildWidget = HTMLTextInput::New()->setMode( UITextInput::TextInputMode::Password ); } else if ( mInputType == "radio" ) { mChildWidget = UIRadioButton::New(); } else { diff --git a/src/eepp/ui/htmltextinput.cpp b/src/eepp/ui/htmltextinput.cpp index 111b40adf..05a6fd588 100644 --- a/src/eepp/ui/htmltextinput.cpp +++ b/src/eepp/ui/htmltextinput.cpp @@ -9,7 +9,9 @@ HTMLTextInput* HTMLTextInput::New() { return eeNew( HTMLTextInput, () ); } -HTMLTextInput::HTMLTextInput() : UITextInput( "textinput" ) { +HTMLTextInput::HTMLTextInput() : HTMLTextInput( "textinput" ) {} + +HTMLTextInput::HTMLTextInput( const std::string& tag ) : UITextInput( tag ) { mHtmlSize = 20; mWidthPolicy = SizePolicy::WrapContent; mHeightPolicy = SizePolicy::WrapContent; @@ -84,14 +86,9 @@ void HTMLTextInput::onAutoSize() { setInternalPixelsWidth( width ); } } - if ( mHeightPolicy == SizePolicy::WrapContent && getFont() ) { - Float height = getFont()->getFontHeight( getFontSize() ) + mPaddingPx.Top + - mPaddingPx.Bottom; - if ( height > 0 ) { - setInternalPixelsHeight( height ); - } - } + UITextInput::onAutoSize(); + mPacking = false; } diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index a26e8b101..a77fd9ffc 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -39,7 +39,7 @@ UIListBox::UIListBox( const std::string& tag ) : mVisibleFirst( 0 ), mVisibleLast( 0 ), mSmoothScroll( true ) { - setFlags( UI_AUTO_PADDING ); + setFlags( UI_AUTO_PADDING | UI_LOADS_ITS_CHILDREN ); auto cb = [this]( const Event* ) { containerResize(); }; diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 580a8cc66..eac38591f 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -22,6 +23,10 @@ UITextInput* UITextInput::New() { return eeNew( UITextInput, () ); } +UITextInput* UITextInput::NewPassword() { + return ( eeNew( UITextInput, () ) )->setMode( TextInputMode::Password ); +} + UITextInput* UITextInput::NewWithTag( const std::string& tag ) { return eeNew( UITextInput, ( tag ) ); } @@ -73,6 +78,7 @@ UITextInput::UITextInput() : UITextInput( "textinput" ) {} UITextInput::~UITextInput() { eeSAFE_DELETE( mHintCache ); + eeSAFE_DELETE( mPassCache ); } Uint32 UITextInput::getType() const { @@ -132,19 +138,41 @@ void UITextInput::draw() { if ( mVisible && 0.f != mAlpha ) { UINode::draw(); - if ( mTextCache.getTextWidth() ) { - drawSelection( mTextCache ); - mTextCache.setAlign( getFlags() ); - mTextCache.draw( + Text& textCache = getVisibleTextCache(); + if ( textCache.getTextWidth() ) { + drawSelection( textCache ); + + if ( isClipped() ) { + clipSmartEnable( mScreenPos.x + mPaddingPx.Left, mScreenPos.y + mPaddingPx.Top, + mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right, + mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); + } + + textCache.setAlign( getFlags() ); + textCache.draw( std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, Vector2f::One, 0.f, getBlendMode() ); + + if ( isClipped() ) { + clipSmartDisable(); + } } else if ( !mHintCache->getString().empty() && ( mHintDisplay == HintDisplay::Always || hasFocus() ) ) { + if ( isClipped() ) { + clipSmartEnable( mScreenPos.x + mPaddingPx.Left, mScreenPos.y + mPaddingPx.Top, + mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right, + mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); + } + mHintCache->draw( std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, Vector2f::One, 0.f, getBlendMode() ); + + if ( isClipped() ) { + clipSmartDisable(); + } } } @@ -287,7 +315,90 @@ const String& UITextInput::getText() const { void UITextInput::wrapText( const Uint32& ) {} -void UITextInput::updateText() {} +UITextInput* UITextInput::setMode( TextInputMode mode ) { + if ( mMode != mode ) { + mMode = mode; + if ( mMode == TextInputMode::Password ) { + if ( !mPassCache ) { + mPassCache = Text::New(); + updateFontStyleConfig(); + } + updatePass(); + } + invalidateDraw(); + } + return this; +} + +UITextInput::TextInputMode UITextInput::getMode() const { + return mMode; +} + +const String& UITextInput::getBulletCharacter() const { + return mBulletCharacter; +} + +void UITextInput::setBulletCharacter( const String& bulletCharacter ) { + mBulletCharacter = bulletCharacter; + updatePass(); +} + +void UITextInput::updateText() { + if ( mMode == TextInputMode::Password ) + updatePass(); +} + +void UITextInput::updatePass() { + if ( !mPassCache ) + return; + + const String& pass = mTextCache.getString(); + + if ( mBulletCharacter.size() == 1 && mPassCache->getFont() && + mPassCache->getFont()->getType() == FontType::TTF && + !static_cast( mPassCache->getFont() ) + ->hasGlyph( mBulletCharacter.front() ) ) { + mBulletCharacter = "•"; + } + + String newTxt; + newTxt.reserve( pass.size() ); + for ( size_t i = 0; i < pass.size(); i++ ) + newTxt += mBulletCharacter; + + mPassCache->setString( newTxt ); +} + +void UITextInput::updateFontStyleConfig() { + if ( mPassCache ) { + mPassCache->setFontSize( mFontStyleConfig.CharacterSize ); + mPassCache->setFont( mFontStyleConfig.getFont() ); + mPassCache->setFillColor( mFontStyleConfig.getFontColor() ); + mPassCache->setShadowColor( mFontStyleConfig.getFontShadowColor() ); + mPassCache->setOutlineColor( mFontStyleConfig.getOutlineColor() ); + mPassCache->setOutlineThickness( mFontStyleConfig.getOutlineThickness() ); + } +} + +void UITextInput::onFontChanged() { + UITextView::onFontChanged(); + if ( getHintFont() == NULL ) { + setHintFont( getFont() ); + } + updateFontStyleConfig(); + invalidateDraw(); +} + +void UITextInput::onFontStyleChanged() { + updateFontStyleConfig(); + invalidateDraw(); +} + +Text& UITextInput::getVisibleTextCache() { + if ( mMode == TextInputMode::Password && mPassCache ) + return *mPassCache; + return mTextCache; +} Uint32 UITextInput::onMouseDown( const Vector2i& position, const Uint32& flags ) { int endPos = selCurEnd(); @@ -471,6 +582,8 @@ std::string UITextInput::getPropertyString( const PropertyDefinition* propertyDe return getHintOutlineColor().toHexString(); case PropertyId::HintDisplay: return mHintDisplay == HintDisplay::Always ? "always" : "focus"; + case PropertyId::InputMode: + return mMode == TextInputMode::Password ? "password" : "normal"; default: return UITextView::getPropertyString( propertyDef, propertyIndex ); } @@ -492,7 +605,8 @@ std::vector UITextInput::getPropertiesImplemented() const { PropertyId::HintFontStyle, PropertyId::HintStrokeWidth, PropertyId::HintStrokeColor, - PropertyId::HintDisplay }; + PropertyId::HintDisplay, + PropertyId::InputMode }; props.insert( props.end(), local.begin(), local.end() ); return props; } @@ -549,6 +663,10 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { ? HintDisplay::Focus : HintDisplay::Always ); break; + case PropertyId::InputMode: + setMode( String::iequals( "password", attribute.asString() ) ? TextInputMode::Password + : TextInputMode::Normal ); + break; default: return UITextView::applyProperty( attribute ); } @@ -568,12 +686,6 @@ UIWidget* UITextInput::setPadding( const Rectf& padding ) { return this; } -void UITextInput::onFontChanged() { - if ( getHintFont() == NULL ) { - setHintFont( getFont() ); - } -} - const String& UITextInput::getHint() const { return mHintCache->getString(); } diff --git a/src/eepp/ui/uitextinputpassword.cpp b/src/eepp/ui/uitextinputpassword.cpp deleted file mode 100644 index 525b7d0a0..000000000 --- a/src/eepp/ui/uitextinputpassword.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include - -namespace EE { namespace UI { - -UITextInputPassword* UITextInputPassword::New() { - return eeNew( UITextInputPassword, () ); -} - -UITextInputPassword::UITextInputPassword() : - UITextInput( "textinputpassword" ), mBulletCharacter( "●" ) { - updateFontStyleConfig(); -} - -UITextInputPassword::~UITextInputPassword() {} - -void UITextInputPassword::draw() { - if ( mVisible && 0.f != mAlpha ) { - UINode::draw(); - - if ( mPassCache.getTextWidth() ) { - drawSelection( mPassCache ); - - if ( isClipped() ) { - clipSmartEnable( mScreenPos.x + mPaddingPx.Left, mScreenPos.y + mPaddingPx.Top, - mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right, - mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); - } - - mPassCache.setAlign( getFlags() ); - mPassCache.draw( - std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, - std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); - - if ( isClipped() ) { - clipSmartDisable(); - } - } else if ( !mHintCache->getString().empty() ) { - if ( isClipped() ) { - clipSmartEnable( mScreenPos.x + mPaddingPx.Left, mScreenPos.y + mPaddingPx.Top, - mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right, - mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); - } - - mHintCache->draw( - std::trunc( mScreenPos.x ) + (int)mHintAlignOffset.x + (int)mPaddingPx.Left, - std::trunc( mScreenPos.y ) + (int)mHintAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); - - if ( isClipped() ) { - clipSmartDisable(); - } - } - } - - drawWaitingCursor(); -} - -Text& UITextInputPassword::getVisibleTextCache() { - return mPassCache; -} - -void UITextInputPassword::updateText() { - updatePass( mTextCache.getString() ); -} - -void UITextInputPassword::updatePass( const String& pass ) { - if ( mBulletCharacter.size() == 1 && mPassCache.getFont()->getType() == FontType::TTF && - !static_cast( mPassCache.getFont() ) - ->hasGlyph( mBulletCharacter.front() ) ) { - mBulletCharacter = "•"; - } - - String newTxt; - newTxt.reserve( pass.size() ); - for ( size_t i = 0; i < pass.size(); i++ ) - newTxt += mBulletCharacter; - - mPassCache.setString( newTxt ); -} - -UITextView* UITextInputPassword::setText( const String& text ) { - UITextInput::setText( text ); - - updatePass( text ); - - return this; -} - -const Text& UITextInputPassword::getPassCache() const { - return mPassCache; -} - -const String& UITextInputPassword::getBulletCharacter() const { - return mBulletCharacter; -} - -void UITextInputPassword::setBulletCharacter( const String& bulletCharacter ) { - mBulletCharacter = bulletCharacter; -} - -void UITextInputPassword::updateFontStyleConfig() { - mPassCache.setFontSize( mFontStyleConfig.CharacterSize ); - mPassCache.setFont( mFontStyleConfig.getFont() ); - mPassCache.setFillColor( mFontStyleConfig.getFontColor() ); - mPassCache.setShadowColor( mFontStyleConfig.getFontShadowColor() ); - mPassCache.setOutlineColor( mFontStyleConfig.getOutlineColor() ); - mPassCache.setOutlineThickness( mFontStyleConfig.getOutlineThickness() ); -} - -void UITextInputPassword::onStateChange() { - updateFontStyleConfig(); - UITextInput::onStateChange(); -} - -void UITextInputPassword::onFontChanged() { - updateFontStyleConfig(); - UITextInput::onFontChanged(); -} - -void UITextInputPassword::onFontStyleChanged() { - updateFontStyleConfig(); - UITextInput::onFontStyleChanged(); -} - -const String& UITextInputPassword::getText() const { - return UITextView::getText(); -} - -}} // namespace EE::UI diff --git a/src/eepp/ui/uiwidgetcreator.cpp b/src/eepp/ui/uiwidgetcreator.cpp index 0ce808a28..c55e372c3 100644 --- a/src/eepp/ui/uiwidgetcreator.cpp +++ b/src/eepp/ui/uiwidgetcreator.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -86,7 +85,7 @@ void UIWidgetCreator::createBaseWidgetList() { registeredWidget["tabwidget"] = UITabWidget::New; registeredWidget["textedit"] = UITextEdit::New; registeredWidget["textinput"] = UITextInput::New; - registeredWidget["textinputpassword"] = UITextInputPassword::New; + registeredWidget["textinputpassword"] = UITextInput::NewPassword; registeredWidget["loader"] = UILoader::New; registeredWidget["selectbutton"] = UISelectButton::New; registeredWidget["window"] = UIWindow::New; @@ -122,7 +121,7 @@ void UIWidgetCreator::createBaseWidgetList() { // Aliases registeredWidget["hbox"] = UILinearLayout::NewHorizontal; registeredWidget["vbox"] = UILinearLayout::NewVertical; - registeredWidget["inputpassword"] = UITextInputPassword::New; + registeredWidget["inputpassword"] = UITextInput::NewPassword; registeredWidget["viewpagerhorizontal"] = UIViewPager::NewHorizontal; registeredWidget["viewpagervertical"] = UIViewPager::NewHorizontal; registeredWidget["vslider"] = UISlider::NewHorizontal; diff --git a/src/examples/ui_html/ui_html.cpp b/src/examples/ui_html/ui_html.cpp index 333da1d39..ef774c6cc 100644 --- a/src/examples/ui_html/ui_html.cpp +++ b/src/examples/ui_html/ui_html.cpp @@ -7,6 +7,9 @@ EE_MAIN_FUNC int main( int, char** ) { Log::instance()->setLogToStdOut( true ); Log::instance()->setLiveWrite( true ); + Http::setDefaultUserAgent( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like " + "Gecko) Chrome/146.0.0.0 Safari/537.36" ); + auto win = app.getWindow(); auto ui = app.getUI(); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index c52669ed2..7a9f5ba63 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -718,7 +718,7 @@ void EETest::createNewUI() { UITextInput* textInput = UITextInput::New(); textInput->setPosition( 50, 210 )->setSize( 200, 0 )->setParent( container ); - UITextInputPassword* textInputPass = UITextInputPassword::New(); + UITextInput* textInputPass = UITextInput::NewPassword(); textInputPass->setPosition( 50, 245 )->setSize( 200, 0 )->setParent( container ); UIListBox* listBox = UIListBox::New(); diff --git a/src/tests/unit_tests/uihtml_tests.cpp b/src/tests/unit_tests/uihtml_tests.cpp index 13618feb8..ddd89bfb9 100644 --- a/src/tests/unit_tests/uihtml_tests.cpp +++ b/src/tests/unit_tests/uihtml_tests.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -241,6 +240,7 @@ UTEST( HTMLInput, sizeAttribute ) { + )html" ); @@ -249,12 +249,14 @@ UTEST( HTMLInput, sizeAttribute ) { auto c2 = sceneNode->getRoot()->find( "i2" )->asType(); auto c3 = sceneNode->getRoot()->find( "i3" )->asType(); auto cp = sceneNode->getRoot()->find( "i_pwd" )->asType(); + auto cm = sceneNode->getRoot()->find( "i_mode_pwd" )->asType(); auto cc = sceneNode->getRoot()->find( "i_chk" )->asType(); ASSERT_TRUE( c1 != nullptr ); ASSERT_TRUE( c2 != nullptr ); ASSERT_TRUE( c3 != nullptr ); ASSERT_TRUE( cp != nullptr ); + ASSERT_TRUE( cm != nullptr ); ASSERT_TRUE( cc != nullptr ); auto i1 = c1->getChildWidget()->asType(); @@ -273,7 +275,12 @@ UTEST( HTMLInput, sizeAttribute ) { EXPECT_NEAR( i2->getPixelsSize().getWidth(), i3->getPixelsSize().getWidth(), 1.f ); EXPECT_TRUE( cp->getChildWidget()->isType( UI_TYPE_TEXTINPUT ) ); - EXPECT_TRUE( cp->getChildWidget()->getElementTag() == "textinputpassword" ); + EXPECT_TRUE( cp->getChildWidget()->asType()->getMode() == + UITextInput::TextInputMode::Password ); + EXPECT_TRUE( cp->getChildWidget()->asType()->getMode() == + UITextInput::TextInputMode::Password ); + EXPECT_TRUE( cm->getChildWidget()->asType()->getMode() == + UITextInput::TextInputMode::Password ); EXPECT_TRUE( cc->getChildWidget()->isType( UI_TYPE_CHECKBOX ) ); Engine::destroySingleton();