Search Unity

An odd GUI Slider getting stuck thing.

Discussion in 'Immediate Mode GUI (IMGUI)' started by vinceparker, Nov 3, 2007.

  1. vinceparker

    vinceparker

    Joined:
    Oct 11, 2007
    Posts:
    7
    I found something odd in the GUI Interface.

    I just tryed to have the value of a slider in a GUILayout change the Text inside a GUI Box that is above the slider. But when I try it, the slider will stop moving as soon as the Box text gets updated. It acts as if I let go of the mouse button. Here is my code:

    Code (csharp):
    1. var sliderValue = 0;
    2.  
    3. function OnGUI () {
    4.     GUILayout.BeginArea (Rect (10,10,200,200));
    5.     GUILayout.BeginVertical();
    6.     GUILayout.Box("Volume: " + sliderValue);
    7.     sliderValue = GUILayout.HorizontalSlider(sliderValue, 0, 100);
    8.     GUILayout.EndVertical();
    9.     GUILayout.EndArea();
    10. }
    Now if I change the code so I'm using a Label instead of a box, then it works.

    Code (csharp):
    1. var sliderValue = 0;
    2.  
    3. function OnGUI () {
    4.     GUILayout.BeginArea (Rect (10,10,200,200));
    5.     GUILayout.BeginVertical();
    6.     GUILayout.Label("Volume: " + sliderValue);
    7.     sliderValue = GUILayout.HorizontalSlider(sliderValue, 0, 100);
    8.     GUILayout.EndVertical();
    9.     GUILayout.EndArea();
    10. }
    11.  
    It also works if the Box is after the slider in the layout:

    Code (csharp):
    1.     sliderValue = GUILayout.HorizontalSlider(sliderValue, 0, 100);
    2.     GUILayout.Box("Volume: " + sliderValue);
    3.  
    Is it not designed to work this way with Boxes?... I guess I could just use a Label or a TextArea since they work fine. Just thought I should ask after I found it.

    -Vince
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    I've tested your code, and tried the same thing in C# too. It does seem to be a bug. I think Nicholas may have to figure this one out.
     
  3. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Did you file a bug on this one?
     
  4. AbandonedCart

    AbandonedCart

    Joined:
    Mar 4, 2014
    Posts:
    72
    I had to laugh. It is now 2016 and Unity 5.3 and this is still an issue.

    When I implement a slider after a textfield, the slider gets locked in place. I can randomly click on the bar until the value changes and then continue into sliding, but stopping will lock it again.

    Code (CSharp):
    1. GUI.TextField (new Rect (740, 80, 40, 40), current.ToString("F1"));
    2. GUI.TextField (new Rect (540, 80, 180, 40), "Slider paremeter");
    3. current = GUI.HorizontalSlider (new Rect (540, 140, 240, 40), current, 1.0f, 10.0f);
    I found a workaround would be to place the slider code above the textfield and then use the rectangle parameters to place the textfield back above the slider.

    Code (CSharp):
    1. current = GUI.HorizontalSlider (new Rect (540, 140, 240, 40), current, 1.0f, 10.0f);
    2. GUI.TextField (new Rect (740, 80, 40, 40), current.ToString("F1"));
    3. GUI.TextField (new Rect (540, 80, 180, 40), "Slider parameter");
     
    Last edited: Apr 15, 2016