GUI Scrollbar View

Dagoba

Member
Hello!
There's a problem or more like lack of creativity to create a working scrollbar's view.

I bought a scrollbar example from YoYoGames market and the scrollbar works fine (after I slightly modified it because it didn't work instantly).
There wasn't an example of scrollbar how it works inside a box (which I thought there would be), so I want a scrollbar to make some kind of view to move. I know how to do this but is a view really a great way to do this? I already use one view to follow mouse and whenever I click a certain object, it will pop up a GUI with buttons, different tabs etc.

Now, how do I add items inside the GUI (or more like a list) that is longer than the height of my GUI box? That's why I am using a scrollbar. Should I draw those items outside of ROOM and make the view in the center of the box? I think that this kind of method is pretty poor/unprofessional.

And also, there are 3 different pages, 3 different scrollbars and 3 different items inside of them.
I know how to do this as well like:
Code:
if (page == 1)
{
//Draw this item
//Draw that
//Draw that
//Draw scrollbar
}
else if (page == 2)
//bla bla, you get it
But I have no idea to make a working scrollbar and view within GML, I could do it with other language but now I am using a GM:Studio.. :D

Any ideas?

Thanks in advance!
 

kamiyasi

Member
You could use surfaces. First create a surface, draw to the surface, then draw the surface to the screen positioned where you want it in the box. I'm not sure exactly what kind of result you want to get so I can't think of too much more advice than that.
 

Dagoba

Member
Yeah that could work indeed. I checked surfaces again from manual (haven't used them for ages) and they could really work.
The thing that I am trying to do is some kind of ListView kind of thing.

It is a chest, where you can loot everything (button), take single items (button too) or store items in it (button as well).
The item names are as list. If there is for example 10 items in the chest, it will do a for loop inside and generate 10 lines within the info of the object (object's name, object's quality and then button to take the item).

Could this be done within the surfaces?
 
P

ph101

Guest
Yeah I posted a recent thread on this: https://forum.yoyogames.com/index.p...ow-using-surfaces-but-in-gui.8734/#post-60871
I haven't got round to implementing it yet but there is some nice code to get you started on the click through. You want to implement that in your GUI layer. In your example, you would just have a simple loop drawing the text from each list item at a height defined by the number in the list. You would also I guess want to then set up a collision zone at that line when you are drawing it so that you can detect when you click a specific line. I'm not sure yet how to code that mouse detection within a surface layer scrolled but its possible no doubt. Your system will need to take into acconut how far it has been scrolled perhaps and offset that in the collision code on the Y.
 
Top