mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] TextFieldWithExtension blocks cursor on the rightmost text
This commit is contained in:
@@ -76,6 +76,7 @@ app_objs += $(addprefix apps/shared/,\
|
||||
tab_table_controller.o\
|
||||
text_field_delegate.o\
|
||||
text_field_delegate_app.o\
|
||||
text_field_with_extension.o\
|
||||
toolbox_helpers.o\
|
||||
values_function_parameter_controller.o\
|
||||
values_parameter_controller.o\
|
||||
|
||||
14
apps/shared/text_field_with_extension.cpp
Normal file
14
apps/shared/text_field_with_extension.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "text_field_with_extension.h"
|
||||
|
||||
namespace Shared {
|
||||
|
||||
void TextFieldWithExtension::willSetCursorLocation(int * location) {
|
||||
size_t textLength = strlen(text());
|
||||
assert(textLength >= m_extensionLength);
|
||||
size_t maxLocation = textLength - m_extensionLength;
|
||||
if (*location > (int)maxLocation) {
|
||||
*location = maxLocation;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
32
apps/shared/text_field_with_extension.h
Normal file
32
apps/shared/text_field_with_extension.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef SHARED_TEXT_FIELD_WITH_EXTENSION_H
|
||||
#define SHARED_TEXT_FIELD_WITH_EXTENSION_H
|
||||
|
||||
#include <escher/text_field.h>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
class TextFieldWithExtension : public TextField {
|
||||
public:
|
||||
TextFieldWithExtension(size_t extensionLength,
|
||||
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 backgroundColor = KDColorWhite) :
|
||||
TextField(parentResponder, textBuffer, draftTextBuffer, textBufferSize, delegate, hasTwoBuffers, size, horizontalAlignment, verticalAlignment, textColor, backgroundColor),
|
||||
m_extensionLength(extensionLength)
|
||||
{}
|
||||
private:
|
||||
void willSetCursorLocation(int * location) override;
|
||||
size_t m_extensionLength;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -55,6 +55,7 @@ protected:
|
||||
virtual const ContentView * nonEditableContentView() const = 0;
|
||||
private:
|
||||
virtual TextInputDelegate * delegate() = 0;
|
||||
virtual void willSetCursorLocation(int * location) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,8 @@ TextInput::ContentView::ContentView(const KDFont * font) :
|
||||
}
|
||||
|
||||
void TextInput::ContentView::setCursorLocation(int location) {
|
||||
int adjustedLocation = location < 0 ? 0 : location;
|
||||
adjustedLocation = adjustedLocation > (signed int)editedTextLength() ? (signed int)editedTextLength() : adjustedLocation;
|
||||
assert(location >= 0);
|
||||
int adjustedLocation = location > (signed int)editedTextLength() ? (signed int)editedTextLength() : location;
|
||||
m_cursorIndex = adjustedLocation;
|
||||
layoutSubviews();
|
||||
}
|
||||
@@ -84,7 +84,9 @@ void TextInput::scrollToCursor() {
|
||||
}
|
||||
|
||||
bool TextInput::setCursorLocation(int location) {
|
||||
contentView()->setCursorLocation(location);
|
||||
int adjustedLocation = location < 0 ? 0 : location;
|
||||
willSetCursorLocation(&adjustedLocation);
|
||||
contentView()->setCursorLocation(adjustedLocation);
|
||||
scrollToCursor();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user