|
2 | 2 | #define _RIVE_TEXT_INPUT_HPP_ |
3 | 3 |
|
4 | 4 | #include "rive/generated/text/text_input_base.hpp" |
| 5 | +#include "rive/advancing_component.hpp" |
5 | 6 | #include "rive/text/raw_text_input.hpp" |
6 | 7 | #include "rive/text/text_interface.hpp" |
7 | 8 | #include "rive/input/focusable.hpp" |
| 9 | +#include <cmath> |
8 | 10 |
|
9 | 11 | namespace rive |
10 | 12 | { |
11 | 13 | class TextStyle; |
12 | 14 | class ScrollConstraint; |
13 | | -class TextInput : public TextInputBase, public TextInterface, public Focusable |
| 15 | +class TextInput : public TextInputBase, |
| 16 | + public TextInterface, |
| 17 | + public Focusable, |
| 18 | + public AdvancingComponent |
14 | 19 | { |
15 | 20 | public: |
16 | 21 | void draw(Renderer* renderer) override; |
@@ -63,28 +68,44 @@ class TextInput : public TextInputBase, public TextInterface, public Focusable |
63 | 68 |
|
64 | 69 | /// Advance edge scrolling during drag. Returns true if still scrolling. |
65 | 70 | bool advanceDrag(float elapsedSeconds); |
| 71 | + bool advanceComponent(float elapsedSeconds, |
| 72 | + AdvanceFlags flags = AdvanceFlags::Animate | |
| 73 | + AdvanceFlags::NewFrame) override; |
66 | 74 |
|
67 | 75 | /// Whether currently dragging (for hit test to avoid interference). |
68 | 76 | bool isDragging() const { return m_isDragging; } |
69 | 77 |
|
70 | 78 | protected: |
71 | 79 | void textChanged() override; |
72 | 80 | void selectionRadiusChanged() override; |
| 81 | + void multilineChanged() override; |
73 | 82 |
|
74 | 83 | private: |
75 | 84 | /// Convert a world position to local text input coordinates. |
76 | 85 | /// Handles viewport clamping and auto-scroll for scroll constraints. |
77 | | - bool worldToLocalWithViewport(Vec2D worldPosition, Vec2D& outLocal); |
| 86 | + bool worldToLocalWithViewport(Vec2D worldPosition, |
| 87 | + Vec2D& outLocal, |
| 88 | + bool enableAutoScroll); |
| 89 | + |
| 90 | + float edgeScrollSpeedForDistance(float distanceFromEdge) const; |
| 91 | + float edgeActivationDistance(float position, float edgeStart) const; |
| 92 | + |
| 93 | + void updateMultiline(); |
78 | 94 |
|
79 | 95 | AABB m_worldBounds; |
80 | 96 | TextStyle* m_textStyle = nullptr; |
81 | 97 | ScrollConstraint* m_scrollConstraint = nullptr; |
82 | 98 |
|
83 | 99 | /// Whether the user is currently dragging to select text. |
84 | 100 | bool m_isDragging = false; |
| 101 | + Vec2D m_lastDragWorldPosition = Vec2D(NAN, NAN); |
| 102 | + |
| 103 | + /// Scroll velocity for edge scrolling during drag in X. |
| 104 | + float m_scrollX = 0.0f; |
85 | 105 |
|
86 | 106 | /// Scroll velocity for edge scrolling during drag. |
87 | 107 | float m_scrollY = 0.0f; |
| 108 | + float m_layoutWidth = NAN; |
88 | 109 |
|
89 | 110 | #ifdef WITH_RIVE_TEXT |
90 | 111 | RawTextInput m_rawTextInput; |
|
0 commit comments