• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

[solved] hide scrollbar if list contains only a few elements

f95zoneuser463

Member
Game Developer
Aug 14, 2017
219
1,017
I have a quest log screen that got to small for all my quests. So I had to modify it with a scrollbar. It's all working fine except for some cosmetic problem:
qlog scrollbar.png
Two questions:
1. Is still the proper way to use scrollbars? Because this code makes me want to puke... more indentations please!
2. What is an elegant way to hide the scrollbar if the list of quest names is not that long. My only idea is to count the number of quest names in the list and add a switch like this to the screen:
if quest_name_count < 12:
*show version without scrollbar*
else:
*show version with scrollbar*

relevant code from that quest log:
Code:
## QUESTNAMES:
vbox:
    text "Name:" color gui.accent_color size 60
    frame:
        background None
        side ("c r"):
            area (0,0,300,595)
            viewport id "questnames":
                draggable True mousewheel True
                vbox:
                    xmaximum 300
                    xfill True
                    for i in log.activetab():
                        textbutton i.title() text_hover_color gui.hover_color action SetField(log, "qvar", i) background None xpadding 0.0 text_size 40
            vbar value YScrollValue("questnames")
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,058
If you put (If quest_name_count is a variable lol):
Code:
if quest_name_count >= 12:
   vbar value YScrollValue("questnames")
That should just make the scroll bar will be there only when you have 12 or more quests.
 
  • Like
Reactions: f95zoneuser463

Rich

Old Fart
Modder
Respected User
Donor
Game Developer
Jun 25, 2017
2,472
6,941
The "bar" and "vbar" elements have a style property named "unscrollable" which affects what happens to the bar when there isn't enough content to allow the bar to scroll.

If you set "unscrollable" to "hide", you'll get what you want without having to worry about how tall the elements are, etc.

 
  • Like
Reactions: f95zoneuser463

f95zoneuser463

Member
Game Developer
Aug 14, 2017
219
1,017
Thanks for the help!

Yep this works fine: ("quest_name_count" was just some pseudo-code variable)
if len(log.activetab()) > 12:
vbar value YScrollValue("questnames")


But unscrollable is perfect.
vbar unscrollable "hide" value YScrollValue("questnames")

Changing this to solved.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,196
14,928
By the way, the answer at your first question is : No !

The proper way to use viewport is now to use it's "scrollbars" property :

Code:
screen myScreen:
    vbox:
       text "Name:" color gui.accent_color size 60
       frame:
           background None    
           viewport:
               draggable True
               mousewheel True
               scrollbars "vertical"   # <------ here
               vbox:
                   xmaximum 300
                   xfill True
                   for i in log.activetab():
                       textbutton [...]
[Note: WARNING the indentation is probably messed]