#(IMGUI) Text field shrunk/small, and text field validation

1 messages · Page 1 of 1 (latest)

fresh island
#

I have 2 issues this morning that I'm not sure how to get around. I've done google searching, and even the chat bot isn't much help in solving these. I'm hoping someone can give me a boost in the right direction here.

My first issue is surrounding UI, of which I am NOT very good at. I have a text field where I want to allow the user to enter an integer value, yet the field itself is quite...shrunken. A screen shot of this is attached. You can see the text field is quite small upon initial opening, and a google search told me to use EditorGUILayout to get around this...but EditorGUILayout isn't available even with the using UnityEditor statement.

I tried to follow what @abstract flower did in the Maneuver Node Controller mod, with my code looking thusly (with those pieces not applicable to this having been removed):


        protected string strDistanceToTarget = "";
        protected string strMessage = "";
        protected string strRendezvousMessage = "";

        protected override void FillWindow(int windowID)
        {
            base.Update();
            base.FillWindow(windowID);

            styRendezvousDistance = new GUIStyle(GUI.skin.GetStyle("Label"));
            styRendezvousDistance.normal.textColor = Color.white;

            GUILayout.BeginHorizontal();
            GUILayout.Label(">> Approximate final distance to target (meters)", GUILayout.Width(500));
            strDistanceToTarget = GUILayout.TextField(strDistanceToTarget, styRendezvousDistance);
            GUILayout.EndHorizontal();
}```

Even with this code, the text field still comes out like that.  Now, I can click in it and start typing, and it gets bigger.  And then stays that way even when clicking out of the window.  Which is odd because I can continue entering characters in that field, and it continues to widen and widen and widen without end.
#

The second issue I have is also surrounding the text field, but it's related to the actual code itself. I want to check that the text field is an actual number and not someone just typing away with no real value. So I use the following code:


            strMessage = "";

            if (!double.TryParse(strMessage, out dblNumericCheck))
            {
                strMessage = "Distance to target must be an integer value in meters";
                return;
}```

Unfortunately, the check always fails.  That is, the code continues to return that the value is not an integer (or, in this case, a double) no matter what value I put in the text field.
covert jolt
#

its small

#

so the thing with GUILayout its that

#

each UI element has a flexible space, a max and min widht and height

#

GUILayout uses that to set the sizes of the UI elements

#

the problem is, some of them are way bigger than u want them to be

#

also ur setting the label of the Aproximate Final etc to 500 width

#

leaving no space for the input UI Element

#

it seems to be at most 400 pixel in widht? maybe 370

#

´try changing it to that

fresh island
# covert jolt it seems to be at most 400 pixel in widht? maybe 370

See, I'm no UI designer, so without being able to actually SEE the desired final width, I have to guess. And as the window itself seems to expand when you add width to controls, I have no way of knowing how big to make something. Which may very well be my problem here.

#

So I'll give that a shot and see if that fixes the problem with the visual size of the text field.

covert jolt
#

im sure that you can set the window size, on the OnGui() iirc

daring plaza
#

you can specifically set the width of the TextField

fresh island
covert jolt
#

the second issue its always false beucase ur setting the strMessage as "" just before the parse...

#

you're parsing a empty string everytime

fresh island
covert jolt
#

ur using it to parse tho

fresh island
#

ah, that means I've got the check backwards.

covert jolt
#

strMessage = "";

        if (!double.TryParse(**strMessage**, out dblNumericCheck))
fresh island
#

yeah, not enough coffee this morning

#

I'll have to work on that too.

daring plaza
covert jolt
daring plaza
#

well yeah, but not for IMGUI I mean

#

you just have to eyeball it, test, and update

covert jolt
#

yeah there is, just dont use it

fresh island
covert jolt
#

since its meant for the editor kekw

fresh island
#

And thank you both for the help! I shall update my code and test again!

daring plaza
covert jolt
daring plaza
#

it's just for in-game debug windows and stuff

covert jolt
#

lmao

fresh island
#

And that all worked. Some days I just don't see the obvious.

#

Still not happy entirely with the UI, but I'll work on that later. For now, I get to get into the actual math and creation of nodes. Wish me luck!

covert jolt
#

if you want full control over the ui

#

use GUI instead of GUILayout

warm shard
#

Text field shrunk/small, and text field validation