Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Focus on Multiple TextInputs #209

Open
noio opened this issue Jun 19, 2014 · 5 comments
Open

Focus on Multiple TextInputs #209

noio opened this issue Jun 19, 2014 · 5 comments

Comments

@noio
Copy link

noio commented Jun 19, 2014

When creating a UI with multiple textinputs, the default behavior is for each textfield to stay selected after it's clicked. This often leads to the case where multiple textinputs receive input text.

Would it be an idea to have the Canvas keep track of which textfield is in focus? I might be able to contribute.

@Wazhup
Copy link

Wazhup commented Jul 17, 2014

@noio do you solve it? if yes how? thanks for your time

@noio
Copy link
Author

noio commented Jul 18, 2014

I wrote some code "manually" to unselect all textinputs (except one) when a new one is selected:

void ofApp::unfocusAllTextInputs(ofxUITextInput* except){
    for (int i = 0; i < textInputs.size(); i ++){
        if (except != textInputs[i]){
            textInputs[i]->setFocus(false);
        }
    }
}

Then I call this whenever a new textinput is selected in ofApp::guiEvent(ofxUIEventArgs& e):

if (kind == OFX_UI_WIDGET_TEXTINPUT){
    ofxUITextInput *ti = (ofxUITextInput *) e.widget;
    if (ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS){
        unfocusAllTextInputs(ti);
    }
}

This does mean you have to keep track of the textinputs:

windowHTextInput = gui->addTextInput("WINDOW_H", ofToString(ofGetHeight()));
windowHTextInput->setAutoClear(false);
textInputs.push_back(windowHTextInput);

@Wazhup
Copy link

Wazhup commented Jul 24, 2014

@noio yap, i did the same :D

@moebiussurfing
Copy link

@noio . Thanks. it helped me too. After some doubts, finally I defined textInputs and my variables in ofApp.h like this:

void unfocusAllTextInputs(ofxUITextInput* except);
vector<ofxUITextInput *> textInputs;
ofxUITextInput *textInputUserKitLAB;
ofxUITextInput *textInputSeedPresetKit;

@chuckleplant
Copy link

This happens to me with the ofxUIScrollableCanvas, quick fix:

void ofxUIScrollableCanvas::mousePressed(int x, int y, int button)
{
    if(sRect->inside(x, y))
    {
        hit = true;
        for(vector<ofxUIWidget *>::iterator it = widgets.begin(); it != widgets.end(); ++it)
        {
            if((*it)->isVisible())
            {
                if((*it)->isHit(x, y))
                {
                    if((*it)->isDraggable())
                    {
                        hitWidget = true;
                    }
                    (*it)->mousePressed(x, y, button);
                }
                else if((*it)->getKind() == ofxUIWidgetType::OFX_UI_WIDGET_TEXTINPUT)
                {
                     (*it)->mousePressed(x, y, button);
                }
            }
        }
    }

    isScrolling = false;
    vel.set(0,0);
}

I think the solution would be making ofxUITextInput always listen to mouse events, then checking for their rects. This way it would be globally fixed, even if you have multiple ofxUICanvas.

andreirt added a commit to andreirt/candle-clock that referenced this issue May 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants