[SPOUT] GenericTextField acting very strange

Discussion in 'Plugin Development' started by blaise64, Dec 26, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    blaise64

    I'm trying to create a gui plugin for admin with buttons and text field to help me administrate my server.
    I found the plugin AdminGUI witch does that but I want to do my version ^^

    I have the same comportement with my plugin and AdminGUI : text field seems to loose focus without a reason when typing. So you need to reselect it before continuing typing.
    It's a bit confusing ..
    More over it seem that the right last third part of the GenericTextField widget can't be used (no possibility to type something in even if the maximum characters setting is higher than the number of caracter you typed).

    Did someone else having the same problem ?
    I use GenericContainer to place my widgets and attach the container to the popup, is this the right method ?
     
  2. Offline

    Rycochet

    That bug has been reported elsewhere, but not been caught yet - so not sure what's causing it. Due to the major rewrite going on, it might not actually get caught in the current code, but it's almost definitely client side, and as soon as it is found it'll get fixed.

    Popup -> Container -> Widgets is the recommended way of doing things - possibly even subclassing Popup or Container and creating everything in the constructor instead if it's more complex ;-)
     
  3. Offline

    blaise64

    @Rycochet
    May be I have a element that can cause this bug.
    I can't found the issues you mention on the bug tracker so I post here.

    The first bug is the loose of the focus. I made a little test where I rewrite the writeData and readData method to print the state of the focus and the same for the method onTextFieldEvent()
    Here are the results :
    Code:
    15:43:26 [INFO] TextFieldChangeEvent - new text is: test_param1de - focus: false
    15:43:26 [INFO] entry : writing data - focus:false
    15:43:28 [INFO] TextFieldChangeEvent - new text is: test_param1dede - focus: false
    15:43:28 [INFO] entry : writing data - focus:false
    15:43:29 [INFO] TextFieldChangeEvent - new text is: test_param1dedede - focus: false
    15:43:29 [INFO] entry : writing data - focus:false
    There is no readData so no update of the focus => focus is always reset to false when a TextFieldChangeEvent append without the setFocus(true) method because writeData is call after a TextFieldChangeEvent.
    If you try you can see you loose the focus every time you stop typing during more than 1 tick...
    The solution I use for this problem is to put setFocus(true) in the onTextFieldChange method :
    Code:
     public void onTextFieldChange(TextFieldChangeEvent event)
        {
            this.setFocus(true);
            this.text=event.getNewText();
            System.out.println("TextFieldChangeEvent - new text is: "+event.getNewText()+" - focus: "+isFocused());
            //this.app_root.registerParameter(var, text);
        }
    And this work really fine. I don't loose the focus and there is no problem when changing from one text field to another.
    Code:
    23:49:01 [INFO] TextFieldChangeEvent - new text is: test_param1  - focus: true
    23:49:01 [INFO] entry : writing data - focus:true
    23:49:04 [INFO] TextFieldChangeEvent - new text is: test_param1 gyl - focus: true
    23:49:04 [INFO] entry : writing data - focus:true
    23:49:07 [INFO] TextFieldChangeEvent - new text is: test_param1 gylvhubo;vora;vatuovta - focus: true
    23:49:07 [INFO] entry : writing data - focus:true
    23:49:09 [INFO] TextFieldChangeEvent - new text is: test_param1 gylvhubo;vora;vatuovtano - focus: true
    23:49:09 [INFO] entry : writing data - focus:true
    23:49:13 [INFO] TextFieldChangeEvent - new text is: test_param1  - focus: true
    23:49:13 [INFO] entry : writing data - focus:true
    23:49:19 [INFO] TextFieldChangeEvent - new text is: test_param1 huvrahuilvrvbirlavuirahui - focus: true
    23:49:19 [INFO] entry : writing data - focus:true
    But sometime there is a little graphic bug of the text without lost of data.

    The other problem I mention is the bug of max size of the text in the TextField.
    I made some testing to figure out the problem and I think I find the problem.
    First of all I increase the max number of lines in my TextField.
    I found that then the text reach the previous limit it goes to the next line...
    More over when I resize the windows it fit well if the TextField police size is the same than the button police size.
    Here is a capture when resized:
    [​IMG]

    Here a capture when max sized windows:
    [​IMG]

    So I take a look at the code of GenericTextProcessor class and I found this method :
    Code:
    protected boolean formatText() {//line 238
    where the text is split:
    Code:
    // split very long words
    if (wordWidth > width) { //line 274
        int i = word.length();
        while (i > 0 && wordWidth > width)
            wordWidth -= font.getTextWidth(String.valueOf(word.charAt(--i)));
        position = position - word.length() + i;
        lineBreaks.add(position);
        lineWidth = 0;
        word = word.substring(i);
        skipIterator = true;}// check if this word would exceed the max-width of the line
    else if (lineWidth + wordWidth > width) {
        if (lineBreaks.size() + 1 < lineLimit) {
            lineBreaks.add(position - word.length());
            lineWidth = wordWidth;
        } else
            return false;
    } else {
        lineWidth += wordWidth;
    }previousSpace = false;
    The wordWidth is calculate by:
    Code:
    wordWidth = font.getTextWidth(word);//line 257
    I think it is this method witch doesn't give the right size.

    I made another test to test this: I change the GUI size in the spoutcraft client options to small and I found that the text in the Field is resize but the limit is always to the same number of character. More over the text in the buttons is not resize.
    [​IMG]

    So I think the MinecraftFont.getTextWidth(String s) give a size based on the number of characters and the size of a character in the police used for the buttons but it is not the same than in the TextField.
    May be if you set the same police for all the widgets it will match.

    I hope this can help you !
     
Thread Status:
Not open for further replies.

Share This Page