Hi !
I'm currently doing an UI, and I need a DScrollPanel. I'm searching since few days how it can be possible to know wether or not a DScrollPanel is visible ?
Let me explain :
User can configure some cars in an NPC, and thanks to a little loop, I'm displaying them onto a DFrame.
Since the user can add tons of cars, I need to put all these things in a DScrollPanel.
For some purpose, I would like to know if it's possible to know if a DScrollPanel is visible / active / IDK how you call that, when you can use it.
I already tried IsVisible(), GetDisabled(), and it don't work.
Thanks a lot in advance,
Gabyfle.
Did you mean a ScrollBar?
You can set a variable as true when it is opened and false when it is closed by the player.
Then just check if the variable is true in an if statement.
Yes, I mean a scrollbar, I mean this :
Category
JNelson I think that you didn't well interpreted what I mean...
User can configure things like that :
buses = {
["sw_bus"] = {
description = "This is the most modern bus we have in stock. Filled with technology, it will allow you to control your position and know the traffic in real time!",
price = 10,
jobs = {
["Bus driver"] = true,
["Citizen"] = true
},
model = "models/sligwolf/bus/bus.mdl"
},
["sw_bendibus"] = {
description = "The biggest bus out there, to transport the whole city. Up to 10 people can sit in this double-bus. Thanks to his powerful engine, he can brings you everywhere. A real revolution of transports.",
price = 50,
jobs = {
["Bus driver"] = true,
["Citizen"] = true
},
model = "models/sligwolf/bus/bus.mdl"
}
}
If player let things like that, or if he just have few cars (like 3), it'll look like that :
https://files.facepunch.com/forum/upload/304226/1b912961-4074-4906-b6d7-310f99174d18/20190224215826_1.jpg
When the player add a lot of cars, the scrollbar will appear, and then we're gonna get something like that
https://files.facepunch.com/forum/upload/304226/f4f6c938-6c64-43b9-bac8-43201728c44d/20190224211611_1.jpg
The DScrollBarPanel appeared, and you can scroll to see the different cars.
The question is, how can I know if the scroll bar appeared or not ?
Well, first.
ScrollBar is stored in :GetVBar()
You can try to check when self.VBar.Enabled is true
Both of the two way of getting "Enabled" attribute are returning a "nil" value :
local bar = scroll:GetVBar()
print(type(bar.Enabled))
This returns : "nil"
Try use VBar:IsEnabled()
It returns me true, wether or not it's displayed.
Oh my bad, totally misinterpreted.
Since what others are suggesting isnt working then:
You can check wether the buses table has more then 3 entries using the # operator. This is a pretty hacky way of doing it tho, it assumes the sizes of the panel(s) will be the same all the time.
If the panel size changes then youl have to do some tricky math stuff.
I thought to do something like that, but it's quite strange, I can't get this attribute, even if it's defined :/
Oh, yeah. that is scroll.Enabled instead self.VBar.Enabled
I tried something like that, but still not working, always "TRUE"...
local isScrollbarVisible = scroll:GetCanvas():GetTall() > bar:GetTall()
if isScrollbarVisible then
buyBut:SetSize(w - ((w / 6) - 100), 30)
else
buyBut:SetSize(w - ((w / 6) + 40), 30)
end
I edited my post:
Wait, you did something wrong.
I've tested it and DScrollPanel.VBar.Enabled works fine
That's very weird because I'm getting a nil.
local scroll = vgui.Create("DScrollPanel", container)
scroll:Dock(FILL)
Later in the code :
local buyBut = vgui.Create("DButton", contents)
buyBut:SetText("I need this bus!" .. "(".. "$" .. v.price ..")")
buyBut:SetPos((w / 6) + 15, (w / 8) + (140 * i) - 20)
if scroll.VBar.Enabled then
buyBut:SetSize(w - ((w / 6) - 100), 30)
else
print(type(scroll.VBar.Enabled))
buyBut:SetSize(w - ((w / 6) + 40), 30)
end
I get nil.
Did you also try scroll:GetVBar():IsVisible()
Yes, it's always returning "true"...
You're probably getting a nil because VBar.Enabled is indeed nil when you create the DScrollPanel since it uses Dock which will perform its layout in the next frame, use the :PerformLayout of the container and everything there
Now everything is clear
Thanks, working fine + I learned something interesting
Hey guys,
Sorry to ennoy you again, but I talked to fassssst !
Know, IsVisible() is always returning false, I can get why...
Any explanation ?
My code :
https://pastebin.com/5QqELzjP
There's no difference in the code that gets executed, and you should really be using PerformLayout instead of positioning it on creation, that's literally the purpose of PerformLayout
Sorry, but I'm not really sure to get how can I use PerformLayout(). Isn't supposed to be used on a Panel registration ?
Can you show me an example ?
Every size, regardless of if it's static should go into a PerformLayout.
This is an example of code where a btn would be 20% of a frames height, and whenever the frame's PerformLayout is called the button will also automatically adjust
https://pastebin.com/wjVruQgC
Ok, I'll totaly rewrite my code, to get something like that.
Actually, I'm just painting things on the screen thanks to vgui.Create() function, I do not register a new PANEL class.
You should use DScrollPanel:OnScrollbarAppeared to check when the scrollbar gets enabled or disabled. If you don't want to draw the scrollbar at all you should do DScrollPanel.VBar:SetWide(0).
I'll try this. Never seen this method anywhere !?
Maybe we should add it in the wiki, because it can be usefull ?
It's a function you're meant to make yourself.
function DScrollPanel:OnScrollbarAppeared()
print("scrollbar changed")
end
Lol, I'm quite stupid, sorry
That's not what Panel:OnScrollbarAppeared is for, you could make any function to do what you're doing. Panel:OnScrollbarAppeared is a hook like Panel:Paint, it gets automatically called whenever the scrollbar is enabled or disabled. If you need to change anything when it's called you should either do it in a Panel:PerformLayout hook or a Panel:OnScrollbarAppeared hook.
don't call :PerformLayout() directly, you should call :InvalidateLayout() instead.
Also for the if self.VBar.Enabled then return true else return false, instead of writing that you can just type return self.VBar.Enabled
Sorry, you need to Log In to post a reply to this thread.