Overspill in List Boxes

Started by Atelier, Sat 25/07/2009 11:39:20

Previous topic - Next topic

Atelier

Hullo.

The list box is a fairly integral part of my project. But I've come up with a problem. When there's too many words in a list box, it doesn't fill down the box create a block of writing, but instead it just carries on over the rest of the screen. I cannot possibly make my box any wider, and I must use a list box, too.

It is possible to get rid of this overspill and have the text carried on downwards and not across, like labels do? Thanks. :)

GuyAwesome

AFAIK, ListBoxes can't have multi-line items, so you can't get the wrap-around effect you want you want. I tink you'll need to split the longer lines of text into shorter ones that fit the ListBox. You could write a custom function for adding items to the ListBox, that automaticaly splits too-wide lines into multiple entries.
Code: ags

function AddItemWrapped(this ListBox*, String text) {
  if (GetTextWidth(text, this.Font) < this.Width) this.AddItem(text);
  else {
    String TempItem = text;
    while (GetTextWidth(TempItem, this.Font) > this.Width || TempItem.Chars[TempItem.Length-1] != ' ') {
      TempItem = TempItem.Truncate(TempItem.Length-1);
    }
    this.AddItem(TempItem);
    text = text.Substring(TempItem.Length, text.Length-TempItem.Length);
    this.AddItemWrapped(text);
  }
}

(Use in place of ListBox.AddItem. Quickly tested - works OK, but might not be what you want.)
That, or work out line lengths and split them yourself...

The problems I can see here are that you won't be able to check/manipulate items as easily - you won't know if a given item needs to be combined with the lines before or after it to get the full text, how much of the text is in each 'line' (without testing the game and checking), and obviously deleting items becomes harder as well (if you remove item[X], do yu have to remove item [X+/-1] as well?). I'm not sure how you'd simply resolve these, sorry.

Atelier

Great, that's awesome GuyAwesome! :) I've found a way to do it, using part of your code and part of mine. I don't think I thanked you the last time you gave help, so I'll do that now.

Thanks!

SMF spam blocked by CleanTalk