Browse Source

Merge pull request #955 from AtomicGameEngine/TSH-ATOMIC-TABSELECTFIX

UIEditFields auto-select contents on enter
JoshEngebretson 9 years ago
parent
commit
5e962b0308

+ 1 - 1
Resources/EditorData/AtomicEditor/editor/ui/createproject.tb.txt

@@ -3,7 +3,7 @@ TBLayout: axis: y, distribution: gravity, position: left
 		TBLayout: distribution: gravity
 			TBTextField: text: "Project Name:"
 			TBLayout: gravity: left right, distribution-position: right bottom
-				TBEditField: id: project_name, text: "MyGame", autofocus: 1
+				TBEditField: id: project_name, text: "MyGame"
 					lp: min-width: 240
 		TBLayout: gravity: left right, distribution-position: right bottom
 			TBImageWidget: id: project_image

+ 3 - 3
Resources/EditorData/AtomicEditor/editor/ui/mainframe.tb.txt

@@ -37,11 +37,11 @@ TBLayout: distribution: gravity, axis: y
                             TBWidget
             TBLayout: distribution: gravity, position: top
                 TBLayout: distribution: gravity, axis: y, position: left, gravity: top bottom
-                    TBEditField: text: "Project", styling: 1, readonly: 1, adapt-to-content: 1, skin: AccentColor4
+                    TBEditField: text: "Project", is-focusable: 0, styling: 1, readonly: 1, adapt-to-content: 1, skin: AccentColor4
                         font: size: 11
                     TBLayout: distribution: gravity, id: projectviewcontainer
                     TBSeparator: gravity: left right, skin: AESeparator
-                    TBEditField: text: "Hierarchy", styling: 1, readonly: 1, adapt-to-content: 1, skin: AccentColor4
+                    TBEditField: text: "Hierarchy", is-focusable: 0, styling: 1, readonly: 1, adapt-to-content: 1, skin: AccentColor4
                         font: size: 11
                     TBLayout: distribution: gravity, id: hierarchycontainer
                         TBWidget: gravity: top bottom
@@ -53,7 +53,7 @@ TBLayout: distribution: gravity, axis: y
                         TBEditField: multiline: 1, styling: 1, gravity: left right, id: consoletext
                             text: "Hello World!"
                 TBLayout: distribution: gravity, axis: y, position: left, gravity: top bottom, id: inspectorlayout
-                    TBEditField: text: "Inspector", styling: 1, readonly: 1, adapt-to-content: 1, skin: AccentColor4
+                    TBEditField: text: "Inspector", is-focusable: 0, styling: 1, readonly: 1, adapt-to-content: 1, skin: AccentColor4
                         font: size: 11
                     TBLayout: distribution: gravity, id: inspectorcontainer
 

+ 2 - 3
Resources/EditorData/AtomicEditor/editor/ui/renameasset.tb.txt

@@ -6,10 +6,9 @@ TBLayout: axis: y, distribution: gravity, position: left
 	TBSeparator: gravity: left right, skin: AESeparator
 	TBLayout: gravity: left right, distribution-position: right bottom
 		TBTextField: text: "New Name:"
-		TBEditField: id: new_name, autofocus: 1
+		TBEditField: id: new_name
 			lp: min-width: 180
 	TBSeparator: gravity: left right, skin: AESeparator
-	TBLayout: 
+	TBLayout:
 		TBButton: text: Rename, id: rename
 		TBButton: text: Cancel, id: cancel
-		

+ 2 - 2
Resources/EditorData/AtomicEditor/editor/ui/snapsettings.tb.txt

@@ -2,7 +2,7 @@ TBLayout: axis: y, distribution: gravity, position: left
 	TBLayout: distribution: gravity
 		TBTextField: text: "Translate X:"
 		TBLayout: gravity: left right, distribution-position: right bottom
-			TBEditField: id: trans_x, autofocus: 1, text-align: center
+			TBEditField: id: trans_x, text-align: center
 				lp: min-width: 100
 	TBLayout: distribution: gravity
 		TBTextField: text: "Translate Y:"
@@ -25,6 +25,6 @@ TBLayout: axis: y, distribution: gravity, position: left
 			TBEditField: id: scale, text-align: center
 				lp: min-width: 100
 	TBSeparator: gravity: left right, skin: AESeparator
-	TBLayout: 
+	TBLayout:
 		TBButton: text: Apply, id: apply
 		TBButton: text: Cancel, id: cancel

+ 3 - 0
Script/AtomicEditor/ui/modal/CreateProject.ts

@@ -64,6 +64,9 @@ class CreateProject extends ModalWindow {
         this.projectPathField.text = userDocuments;
         this.populateLanguageSelectionList();
 
+        // Need to manually set the focus so the contents get auto-selected
+        this.projectNameField.setFocus();
+
         this.resizeToFitContent();
         this.center();
 

+ 1 - 0
Script/AtomicEditor/ui/modal/SnapSettingsWindow.ts

@@ -38,6 +38,7 @@ class SnapSettingsWindow extends ModalWindow {
 
         this.refreshWidgets();
 
+        this.transXEditField.setFocus();
     }
 
     apply() {

+ 1 - 0
Script/AtomicEditor/ui/modal/UIResourceOps.ts

@@ -425,6 +425,7 @@ export class RenameAsset extends ModalWindow {
         this.resizeToFitContent();
         this.center();
 
+        this.nameEdit.setFocus();
     }
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {

+ 45 - 1
Source/Atomic/UI/UIEditField.cpp

@@ -33,7 +33,8 @@ using namespace tb;
 namespace Atomic
 {
 
-UIEditField::UIEditField(Context* context, bool createWidget) : UIWidget(context, false)
+UIEditField::UIEditField(Context* context, bool createWidget) : UIWidget(context, false),
+    firstFocusFlag_(false)
 {
     if (createWidget)
     {
@@ -194,6 +195,32 @@ void UIEditField::SetTextAlign(UI_TEXT_ALIGN align)
 
 }
 
+void UIEditField::OnFocusChanged(bool focused)
+{
+    UIWidget::OnFocusChanged(focused);
+
+    if (!widget_)
+        return;
+
+    // safe cast?
+    TBEditField* w = (TBEditField*) widget_;
+
+    TBStyleEdit* styleEdit = w->GetStyleEdit();
+    if (styleEdit != NULL)
+    {
+        if (focused)
+        {
+            styleEdit->selection.SelectAll();
+            firstFocusFlag_ = true;
+        }
+        else
+        {
+            styleEdit->selection.SelectNothing();
+        }
+    }
+
+}
+
 bool UIEditField::OnEvent(const tb::TBWidgetEvent &ev)
 {
     if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("edit_complete"))
@@ -203,6 +230,23 @@ bool UIEditField::OnEvent(const tb::TBWidgetEvent &ev)
         SendEvent(E_UIWIDGETEDITCOMPLETE, eventData);
         return true;
     }
+    else if (ev.type == EVENT_TYPE_POINTER_DOWN)
+    {
+        // Select the entire value in the field when it is selected
+        if (widget_ && firstFocusFlag_)
+        {
+            firstFocusFlag_ = false;
+
+            // safe cast?
+            TBEditField* w = (TBEditField*) widget_;
+
+            TBStyleEdit* styleEdit = w->GetStyleEdit();
+            if (styleEdit != NULL)
+            {
+                styleEdit->selection.SelectAll();
+            }
+        }
+    }
 
     return UIWidget::OnEvent(ev);
 }

+ 4 - 1
Source/Atomic/UI/UIEditField.h

@@ -72,8 +72,11 @@ protected:
 
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
 
-private:
+    virtual void OnFocusChanged(bool focused);
 
+private:
+    // Used to keep track of if we have just been focused for the click select
+    bool firstFocusFlag_;
 };
 
 }