mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-10 21:16:24 +02:00
Add some hackery to work around the problem of textedit losing focus on click
This commit is contained in:
1 parent
79d189b545
commit
14141b5a9e
3 files changed
+24
-9
No files matched your search
+16
-4
@@ -17,7 +17,7 @@ namespace UI {
|
||||
|
||||
static View *focusedView;
|
||||
static bool focusMovementEnabled;
|
||||
|
||||
bool focusForced;
|
||||
static recursive_mutex mutex_;
|
||||
|
||||
const float ITEM_HEIGHT = 64.f;
|
||||
@@ -63,21 +63,25 @@ View *GetFocusedView() {
|
||||
return focusedView;
|
||||
}
|
||||
|
||||
void SetFocusedView(View *view) {
|
||||
void SetFocusedView(View *view, bool force) {
|
||||
if (focusedView) {
|
||||
focusedView->FocusChanged(FF_LOSTFOCUS);
|
||||
}
|
||||
focusedView = view;
|
||||
if (focusedView) {
|
||||
focusedView->FocusChanged(FF_GOTFOCUS);
|
||||
if (force) {
|
||||
focusForced = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EnableFocusMovement(bool enable) {
|
||||
focusMovementEnabled = enable;
|
||||
if (!enable) {
|
||||
if (focusedView)
|
||||
if (focusedView) {
|
||||
focusedView->FocusChanged(FF_LOSTFOCUS);
|
||||
}
|
||||
focusedView = 0;
|
||||
}
|
||||
}
|
||||
@@ -619,7 +623,7 @@ void TextEdit::GetContentDimensions(const UIContext &dc, float &w, float &h) con
|
||||
}
|
||||
|
||||
// Handles both windows and unix line endings.
|
||||
std::string FirstLine(const std::string &text) {
|
||||
static std::string FirstLine(const std::string &text) {
|
||||
size_t pos = text.find("\r\n");
|
||||
if (pos != std::string::npos) {
|
||||
return text.substr(0, pos);
|
||||
@@ -631,6 +635,14 @@ std::string FirstLine(const std::string &text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
void TextEdit::Touch(const TouchInput &touch) {
|
||||
if (touch.flags & TOUCH_DOWN) {
|
||||
if (bounds_.Contains(touch.x, touch.y)) {
|
||||
SetFocusedView(this, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEdit::Key(const KeyInput &input) {
|
||||
if (!HasFocus())
|
||||
return;
|
||||
|
||||
@@ -43,7 +43,7 @@ class View;
|
||||
void EnableFocusMovement(bool enable);
|
||||
bool IsFocusMovementEnabled();
|
||||
View *GetFocusedView();
|
||||
void SetFocusedView(View *view);
|
||||
void SetFocusedView(View *view, bool force = false);
|
||||
|
||||
enum DrawableType {
|
||||
DRAW_NOTHING,
|
||||
@@ -674,7 +674,8 @@ public:
|
||||
|
||||
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
virtual void Draw(UIContext &dc) override;
|
||||
virtual void Key(const KeyInput &input) override;
|
||||
virtual void Key(const KeyInput &key) override;
|
||||
virtual void Touch(const TouchInput &touch) override;
|
||||
|
||||
private:
|
||||
void InsertAtCaret(const char *text);
|
||||
|
||||
+5
-3
@@ -17,7 +17,7 @@ const float ITEM_HEIGHT = 64.f;
|
||||
|
||||
static recursive_mutex focusLock;
|
||||
static std::vector<int> focusMoves;
|
||||
|
||||
extern bool focusForced;
|
||||
bool dragCaptured[MAX_POINTERS];
|
||||
|
||||
void CaptureDrag(int id) {
|
||||
@@ -1192,9 +1192,11 @@ static void ProcessHeldKeys(ViewGroup *root) {
|
||||
}
|
||||
|
||||
bool TouchEvent(const TouchInput &touch, ViewGroup *root) {
|
||||
EnableFocusMovement(false);
|
||||
|
||||
focusForced = false;
|
||||
root->Touch(touch);
|
||||
if ((touch.flags & TOUCH_DOWN) && !focusForced) {
|
||||
EnableFocusMovement(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user