LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/components/input - MaterialInputField.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 3 0.0 %
Date: 2024-05-12 00:16:13 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_INPUT_MATERIALINPUTFIELD_H_
      24             : #define XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_INPUT_MATERIALINPUTFIELD_H_
      25             : 
      26             : #include "MaterialSurface.h"
      27             : #include "MaterialInputTextContainer.h"
      28             : #include "MaterialIconSprite.h"
      29             : 
      30             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      31             : 
      32             : enum class InputFieldStyle {
      33             :         Filled,
      34             :         Outlined,
      35             : };
      36             : 
      37             : enum class InputFieldPasswordMode {
      38             :         NotPassword,
      39             :         ShowAll,
      40             :         ShowChar,
      41             :         ShowNone,
      42             : };
      43             : 
      44             : enum class InputFieldError {
      45             :         None,
      46             :         Overflow,
      47             :         InvalidChar,
      48             : };
      49             : 
      50             : class InputField : public Surface {
      51             : public:
      52             :         static constexpr uint32_t InputEnabledActionTag = maxOf<uint32_t>() - 2;
      53             :         static constexpr uint32_t InputEnabledLabelActionTag = maxOf<uint32_t>() - 3;
      54             : 
      55             :         virtual ~InputField();
      56             : 
      57             :         virtual bool init(InputFieldStyle = InputFieldStyle::Filled);
      58             :         virtual bool init(InputFieldStyle, const SurfaceStyle &);
      59             : 
      60             :         virtual void onEnter(xenolith::Scene *) override;
      61             :         virtual void onExit() override;
      62             :         virtual void onContentSizeDirty() override;
      63             : 
      64             :         virtual void setLabelText(StringView);
      65             :         virtual StringView getLabelText() const;
      66             : 
      67             :         virtual void setSupportingText(StringView);
      68             :         virtual StringView getSupportingText() const;
      69             : 
      70             :         virtual void setLeadingIconName(IconName);
      71             :         virtual IconName getLeadingIconName() const;
      72             : 
      73             :         virtual void setTrailingIconName(IconName);
      74             :         virtual IconName getTrailingIconName() const;
      75             : 
      76             :         virtual void setEnabled(bool);
      77             :         virtual bool isEnabled() const;
      78             : 
      79           0 :         virtual WideStringView getInputString() const { return _inputString; }
      80             : 
      81             :         virtual void setInputType(TextInputType);
      82           0 :         virtual TextInputType getInputType() const { return _inputType; }
      83             : 
      84             :         virtual void setPasswordMode(InputFieldPasswordMode);
      85           0 :         virtual InputFieldPasswordMode getPasswordMode() const { return _passwordMode; }
      86             : 
      87             : protected:
      88             :         virtual bool handleTap(const Vec2 &);
      89             : 
      90             :         virtual bool handlePressBegin(const Vec2 &);
      91             :         virtual bool handleLongPress(const Vec2 &, uint32_t tickCount);
      92             :         virtual bool handlePressEnd(const Vec2 &);
      93             :         virtual bool handlePressCancel(const Vec2 &);
      94             : 
      95             :         virtual bool handleSwipeBegin(const Vec2 &pt, const Vec2 &d);
      96             :         virtual bool handleSwipe(const Vec2 &pt, const Vec2 &d, const Vec2 &v);
      97             :         virtual bool handleSwipeEnd(const Vec2 &v);
      98             : 
      99             :         virtual void updateActivityState();
     100             :         virtual void updateInputEnabled();
     101             : 
     102             :         virtual void acquireInputFromContainer();
     103             :         virtual void acquireInput(const Vec2 &targetLocation);
     104             :         virtual void updateCursorForLocation(const Vec2 &);
     105             : 
     106             :         virtual void handleTextInput(WideStringView, TextCursor, TextCursor);
     107             :         virtual void handleKeyboardEnabled(bool, const Rect &, float);
     108             :         virtual void handleInputEnabled(bool);
     109             : 
     110             :         virtual bool handleInputChar(char16_t);
     111             : 
     112             :         virtual void handleError(InputFieldError);
     113             : 
     114             :         InputFieldStyle _style = InputFieldStyle::Filled;
     115             :         InputListener *_inputListener = nullptr;
     116             :         InputListener *_focusInputListener = nullptr;
     117             :         TypescaleLabel *_labelText = nullptr;
     118             :         TypescaleLabel *_supportingText = nullptr;
     119             :         InputTextContainer *_container = nullptr;
     120             :         IconSprite *_leadingIcon = nullptr;
     121             :         IconSprite *_trailingIcon = nullptr;
     122             :         Surface *_indicator = nullptr;
     123             : 
     124             :         WideString _inputString;
     125             :         TextInputHandler _handler;
     126             :         TextCursor _cursor;
     127             :         TextCursor _markedRegion = TextCursor::InvalidCursor;
     128             :         TextInputType _inputType = TextInputType::Default;
     129             :         InputFieldPasswordMode _passwordMode = InputFieldPasswordMode::NotPassword;
     130             : 
     131             :         float _activityAnimationDuration = 0.25f;
     132             :         bool _mouseOver = false;
     133             :         bool _enabled = true;
     134             :         bool _focused = false;
     135             :         bool _pointerSwipeCaptured = false;
     136             :         bool _containerSwipeCaptured = false;
     137             :         bool _rangeSelectionAllowed = true;
     138             :         bool _isLongPress = false;
     139             : };
     140             : 
     141             : }
     142             : 
     143             : #endif /* XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_INPUT_MATERIALINPUTFIELD_H_ */

Generated by: LCOV version 1.14