11 m_textBuffer(textBuffer),
12 m_draftTextBuffer(draftTextBuffer),
13 m_currentDraftTextLength(0),
14 m_textBufferSize(textBufferSize),
15 m_horizontalAlignment(horizontalAlignment),
16 m_verticalAlignment(verticalAlignment)
22 m_draftTextBuffer = draftTextBuffer;
26 KDColor bckCol = m_backgroundColor;
31 ctx->
drawString(
text(), characterFrameAtIndex(0).origin(), m_fontSize, m_textColor, bckCol);
36 return const_cast<const char *
>(m_draftTextBuffer);
38 return const_cast<const char *
>(m_textBuffer);
42 return m_currentDraftTextLength;
46 reloadRectFromCursorPosition(0);
50 m_currentDraftTextLength = textLength;
54 reloadRectFromCursorPosition(0);
58 m_horizontalAlignment = horizontalAlignment;
59 m_verticalAlignment = verticalAlignment;
64 if (m_isEditing ==
isEditing && !reinitDrafBuffer) {
67 if (reinitDrafBuffer) {
68 reinitDraftTextBuffer();
77 m_draftTextBuffer[0] = 0;
78 m_currentDraftTextLength = 0;
83 if (m_currentDraftTextLength + textSize >= m_textBufferSize || textSize == 0) {
86 for (
int k = m_currentDraftTextLength; k >= location && k >= 0; k--) {
87 m_draftTextBuffer[k+textSize] = m_draftTextBuffer[k];
89 strlcpy(&m_draftTextBuffer[location],
text, textSize);
90 if (location+textSize > 0) {
91 m_draftTextBuffer[location+textSize-1] =
text[textSize-1];
93 m_currentDraftTextLength += textSize;
94 for (
size_t i = 0; i < m_currentDraftTextLength; i++) {
95 if (m_draftTextBuffer[i] ==
'\n') {
96 m_draftTextBuffer[i] = 0;
97 m_currentDraftTextLength = i;
101 reloadRectFromCursorPosition((m_horizontalAlignment == 0.0f ? location : 0));
117 m_currentDraftTextLength--;
118 if (m_horizontalAlignment > 0.0f) {
119 reloadRectFromCursorPosition(0);
122 if( m_horizontalAlignment == 0.0f) {
125 for (
int k =
cursorLocation(); k < (
signed char)m_currentDraftTextLength; k ++) {
126 m_draftTextBuffer[k] = m_draftTextBuffer[k+1];
128 m_draftTextBuffer[m_currentDraftTextLength] = 0;
137 reloadRectFromCursorPosition((m_horizontalAlignment == 0.0f ?
cursorLocation() : 0));
144 void TextField::ContentView::layoutSubviews() {
152 KDRect TextField::ContentView::characterFrameAtIndex(
size_t index)
const {
155 KDCoordinate cursorWidth = m_cursorView.minimalSizeForOptimalDisplay().width();
166 m_hasTwoBuffers(hasTwoBuffers),
198 if (reinitDrafBuffer) {
278 assert(m_delegate !=
nullptr);
292 bool didHandleEvent = privateHandleEvent(event);
bool setCursorLocation(int location)
void setDraftTextBuffer(char *draftTextBuffer)
KDPoint drawString(const char *text, KDPoint p, KDText::FontSize size=KDText::FontSize::Large, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite, int maxLength=-1)
void setText(const char *text)
size_t cursorLocation() const
TextField(Responder *parentResponder, char *textBuffer, char *draftTextBuffer, size_t textBufferSize, TextFieldDelegate *delegate=nullptr, bool hasTwoBuffers=true, KDText::FontSize size=KDText::FontSize::Large, float horizontalAlignment=0.0f, float verticalAlignment=0.5f, KDColor textColor=KDColorBlack, KDColor=KDColorWhite)
static constexpr int k_maxBufferSize
constexpr KDCoordinate width() const
static KDSize stringSize(const char *text, FontSize size=FontSize::Large)
size_t editedTextLength() const override
Responder * parentResponder() const
bool removeChar() override
void markRectAsDirty(KDRect rect)
void setDraftTextBuffer(char *draftTextBuffer)
size_t strlcpy(char *dst, const char *src, size_t len)
void setAlignment(float horizontalAlignment, float verticalAlignment)
void setText(const char *text)
void setEditing(bool isEditing, bool reinitDraftBuffer)
bool removeEndOfLine() override
bool textFieldShouldFinishEditing(Ion::Events::Event event)
virtual bool handleEvent(Ion::Events::Event event)
virtual void setEditing(bool isEditing, bool reinitDraftBuffer=true)
virtual bool textFieldDidReceiveEvent(TextField *textField, Ion::Events::Event event)=0
const char * text() const override
void store(const char *storedText)
virtual void scrollToCursor()
constexpr KDColor KDColorWhite
size_t strlen(const char *s)
virtual bool removeEndOfLine()
void drawRect(KDContext *ctx, KDRect rect) const override
bool insertTextAtLocation(const char *textBuffer, int location)
virtual bool textFieldDidAbortEditing(TextField *textField, const char *text)
ContentView(char *textBuffer, char *draftTextBuffer, size_t textBufferSize, KDText::FontSize size, float horizontalAlignment=0.0f, float verticalAlignment=0.5f, KDColor textColor=KDColorBlack, KDColor=KDColorWhite)
const char * text() const
KDSize minimalSizeForOptimalDisplay() const override
KDSize minimalSizeForOptimalDisplay() const override
const char * text() const
virtual bool textFieldDidHandleEvent(TextField *textField, bool returnValue, bool textHasChanged)
constexpr Event ShiftLeft
constexpr KDRect KDRectZero
void fillRect(KDRect rect, KDColor color)
ContentView m_contentView
bool handleEventWithText(const char *text, bool indenting=false) override
constexpr Event ShiftRight
size_t draftTextLength() const
virtual bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event)
bool handleEvent(Ion::Events::Event event) override
KDCoordinate width() const
static Clipboard * sharedClipboard()
static constexpr KDSize charSize(FontSize size=FontSize::Large)
KDColor backgroundColor() const
bool insertTextAtLocation(const char *text, int location) override
void setAlignment(float horizontalAlignment, float verticalAlignment)
virtual void layoutSubviews() override
KDCoordinate height() const
void scrollToCursor() override
int CursorIndexInCommand(const char *text)
void reinitDraftTextBuffer()
constexpr Event Backspace
constexpr KDCoordinate height() const