Cannot enter text into Verse.Widgets.TextField/TextArea

Started by m1st4x, October 01, 2020, 02:42:55 PM

Previous topic - Next topic

m1st4x

I'm trying to add a text field for user input into DoWindowContents() of a derived MainTabWindow class



string text = Verse.Widgets.TextField(rect, "Enter text here");



The widget appears, a prompt is indicating and I can select the preset text.
But on keypress no character shows up and string text leaves unchanged.

Same with Widgets.TextArea and listing_Standard.TextEntry

What's wrong? I don't get any further...

Thanks,
-m1st4x-


m1st4x

Ok, just tried to call GUI.TextField directly without wrappers - changes nothing :| Logfile is clean...


RawCode

logfile is clean because you never added any trace output, adding trace output really helps, atleast you will know, is your code actually executing or not...


m1st4x

Don't know what to trace here, it's a single line of code.

Or do you mean a global setting for more trace output?

No errors logged in my AppData/Rimworld/Player.txt

[UPDATE]
This is how it works:


class TabWindow : MainTabWindow
{
     public string str = "";

     public override void DoWindowContents(Rect rect)
     {
           base.DoWindowContents(rect);
           GUI.BeginGroup(rect);
           try {
               string text = GUI.TextField(rect, this.str);
               //validation etc.
               this.str = text; // stores the value
           }
           catch (Exception e) {
               Log.Message(e.StackTrace);
           } finally {
               GUI.EndGroup();
           }
     }
}


LWM

You might have multilple things fighting for the same input in that rect.

Why not split up the rect into two parts, and pass one part to base.DoWindowContents, and then put your TextField into the other rect?

m1st4x

Hi, thanks for the hint.
I already had different rectangles for base class and my controls.
That's not the reason.
The code above is just a simplification for debugging.




RawCode

you still have no trace output, probably you actually need to add some?

if you don't know what to trace, i will give you a hints

Quotestring text
Quoteis your code actually executing or not

m1st4x

As I said
Quote
The widget appears, a prompt is indicating and I can select the preset text.
But on keypress no character shows up and string text leaves unchanged.

RawCode

i wish you luck developing anything without using tracing or debugger*




*you may need multiple human sacrifices to actually get sufficient luck to develop this way, virgins and children works best

m1st4x

I use Verse.Log.Message for debug output or simply put my value somewhere on screen.
(Changed the code snippet just for you ;-)

Connecting the debugger to RW is indeed something I'm gonna try soon.

RawCode

kay

string text = GUI.TextField(rect, str);
always empty string because you never set "str" and never actually save user input from method
ever if user typed anything into text field, you will replace it with empty string next frame.

with traceoutput set you will notice, that your input is registered but not saved, but you reject to use traceoutput.

i don't need your traceoutput, YOU NEED IT

m1st4x

Thanks for the last post, finally saw my mistake.
I've updated the code above, now it works as desired.

RawCode


LWM

If you want to keep trace code around for possible future use, there's some slick features that C# lets you do that also keeps trace from showing up when you don't want - I can point you to an example if you like.