Dynamic GUI Label list not dependent on Y/height value?

So I have a dictionary I’m iterating through to display some labels:

for (int i = 0; i < this.myDictionary.Count; i++)
                {
                     if (conditions met)
                            {
                                GUI.Label(new Rect(1560f, 180f + (float)(i * 30), 340f, 30f), this.myDictionary[i] + "   " + SomeVar.ToString());
                            }

Now, sometimes conditions arent met and thus the label is skipped and “i” is incremented so next label will be 2x lower by Y/height than should be.

Any ideas how can I handle this situation? Do I really have to make another custom list?

add anohter variable that tracks successful occurrances

int success =0
for( int i ....
  if( condition ) {
    GUI.Lable(using success, not 'i' ...
    success++

That’s what I’m doing right now, but things a bit more complex than that man:

int lines = 0;
x = 5;
using (List<GameObject>.Enumerator enumerator = new List<GameObject>(this.myDict.Keys).GetEnumerator())
{
    while (enumerator.MoveNext())
    {
        GameObject gameObject = enumerator.Current;
        if (condition_here)
        {
            //doing stuff
            var displayValue = somevalue;
            if (condition_here && displayValue > x)
            {
                GUI.Label(new Rect(1560f, 180f + (float)(lines * 30), 340f, 30f), stuff);
            }
            else if (condition_here && GUI.Button(new Rect(1560f, 180f + (float)(lines * 30), 340f, 30f), stuff)
            {
                //doing stuff on button press can't increment lines++ here
            }
            lines++;
            }
            else
            {
                //doing stuff
            }
        }
        //doing stuff
    }
}

As you can see depending on some condition I either want to display stuff as simple label OR as clickable buttons and for each case I need to keep track of position.

For now, because my GUI elements tired to dictionary state I used workaround to get total lines I will display and draw them from highest to lowest. Still, a clean, universal solution would be nice

Nest your if statements

if (condition) {
  lines++//here alwasy incrememnts with condition
  if(displayValue > x){
    Label(...)
  } else if ( Button(...) ){

  }
} else {
   //not condition
}

I can’t nest that one, both IFs check specific states and there are dozens of other states therefore the rest will match with “else”, already been there.

Plus, your example does not make a difference because lines++ still incrementing and it just wont display one of the label but because I use “lines” to increment offset for Rect height value it will be displaced again, i.e. label 1 matches and drawn, label 2 does not match and skipped, label 3 matches and drawn but not below label 1 because we’ve only skipped label 2 being drawn but “lines” were incremented.

And then there is second case when button condition has to display ALL buttons according to “lines” so “lines” cannot be messed with in general

So… you need to draw a picture so I can understand what you need, and post the actual code thats giving you problems.
I’ve given you a solution to the code snippets you posted both times, but aparently thats not the actual code you are using…

Thanks for the tips hpjohn, I just made to separate counters, for box and labels for now. No biggie.