VladimirMarkelov / clui

Command Line User Interface (Console UI inspired by TurboVision)
MIT License
670 stars 50 forks source link

Explicitly place cursor in field so it is ready to begin typing? #132

Open MostHated opened 5 years ago

MostHated commented 5 years ago

Heya, I am trying to find a way to make it so that upon opening the application, or opening specific windows the cursor is placed explicitly within a field and you can begin typing in it without having to click on it first, but I have yet to find the magic combination to make it work.

I tried to see if this might work, but no such luck:

    settingsFrame.OnActive(func(active bool) { // ------------------------------------- The parent container 
        tokenEdit.ProcessEvent(ui.Event{Type: ui.EventKey, Key: term.MouseLeft}) // ----- Edit field 

        //(func() {
        //  ui.PutEvent(ui.Event{Type: ui.EventKey, Key: term.MouseLeft})
        //})()
    })

    settingsFrame.SetActive(true)

I tried to see if using term.KeyTab might work, but it tabs to the menu instead of within the current frame.

What could work is if there were identifiers/number order to the tabstops, and I could specify a target for the tab.

___Main Window__________________________________________________________________
   Frame for Menu           | Frame for contents - frame2                       |
    ______________________  |    _____________________________________________  |
   | MenuItem1 - TabId0   | |   |Frame for Textfield                          | |
   | MenuItem1 - TabId1   | |   |                                             | |
   | MenuItem2 - TabId2   | |   | Label : ==== TextField ====== - TabId5      | |
   | MenuItem3 - TabId3   | |   |_____________________________________________| |
   | MenuItem4 - TabId4   | |                                                   |
   |______________________| |                                                   |
____________________________|___________________________________________________|

// --- onVisible, or possible onActivate? ---------------------------------------------------
frame2.onVisible(true){
    ui.PutEvent(ui.Event{Type: ui.EventKey, Key: term.TabKey, Target: TabId5 })
}   

Something like the above, so upon frame2 becoming available it will automatically place the cursor into the text field so that someone can start typing without having to click, tab, etc manually, allowing much more fluid movement and less need of the mouse?

I see that there is a Target within the event struct, so I tried:

    //--- tokenEdit is the edit field I am trying to make the cursor go to currently in my testing
    ui.PutEvent(ui.Event{Type: ui.EventKey, Key: term.MouseLeft, Target: tokenEdit}) 

That didn't seem to work though.

VladimirMarkelov commented 5 years ago

Have you tried something like ui.ActivateControl(window, tokenEdit)? where window is your Window that contains frame frame2 or settingsFrame?

MostHated commented 5 years ago

It seems to move the cursor there, but it wont let you type unless you physically click in the edit field. If you tab to it though, as soon as it lands on the field you can start typing.