Scrollview width

Post

Posted
Rating:
#1 (In Topic #1852)
Regular
bill-lancaster is in the usergroup ‘Regular’
How can I determine the useable width of a scrollview?

I want to insert TextLabels whose width fits the scrollview but I need to know the width of the vertical scrollbar (if there is one)

ScrollView1.ScrollW has a value of Zero

Any advice would be welcome
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
I get a value returned from ScrollView.Width on my system. Run this code and see if that helps you. You can resize the centre partition and/or the form to get a new value of the width.

ScrollViewWidth.png

Run this code in a Graphical Application.




' Gambas class file

Private Splitter1 As Splitter
Private ScrollView1 As ScrollView
Private Label1 As Label
Private Label2 As Label
Private HBox1 As HBox

Public Sub Form_Open()

  BuildForm()

End

Public Sub Form_Show()

  Splitter1_Resize()

End

Public Sub Splitter1_Resize()

  Label2.Text = "Scroll width = " & ScrollView1.Width

End

Public Sub Form_Resize()

  Splitter1_Resize()

End

Public Sub BuildForm()

  With Me
    .H = 500
    .W = 800
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Border = True
  End With

  With Splitter1 = New Splitter(Me) As "Splitter1"
    .Expand = True
    .Arrangement = Arrange.Horizontal
    .Spacing = True
  End With

  With ScrollView1 = New ScrollView(Splitter1) As "ScrollView1"
    .Expand = True
    .Arrangement = Arrange.Vertical
    .Background = Color.Blue
  End With

  With Label1 = New Label(Splitter1) As "Label1"
    .Expand = True
    .Alignment = Align.Center
    .Text = "Hello!"
    .Font.Bold = True
    .Font.Size = 18
  End With

  With HBox1 = New HBox(Me) As "HBox1"
    .H = 28
  End With

  With Label2 = New Label(Me) As "Label2"
    .H = 35
    .Alignment = Align.Center
    .Font.Bold = True
    .Font.Size = 12
  End With

End
 
Online now: No Back to the top

Post

Posted
Rating:
#3
Banned
Check out Style.class for the Scrollbar size and spacing.
I detect if it's visible or not by seeing if ClientHeight is bigger than actual height.

Code


Dim iVisibleWidth as integer = ScrollView1.Width

If ScrollView1.ClientHeight > ScrollView1.Height Then iVisibleWidth -= Style.ScrollbarWidth + Style.ScrollbarSpacing

Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
bill-lancaster is in the usergroup ‘Regular’
Thank you cogier & Bruce

My project has a series of vertical textlabels of varying heights within a scrollview.
With Bruce's code, scrollview1.clientheight never exeeds scrollview.height, even though the contents of scrollview are 2 X scroillview height

BTW gambas 3.19.5

 
Online now: No Back to the top

Post

Posted
Rating:
#5
Banned
OOPs sorry I meant ContentsHeight not Clientheight :-\

If ScrollView1.ContentsHeight > ScrollView1.Height Then iVisibleWidth -= Style.ScrollbarWidth + Style.ScrollbarSpacing
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
Gianluigi is in the usergroup ‘GambOS Contributor’
With BruceSteers' help, I got this example working.
I'm not sure if this is helpful, because I'm not sure what you mean by "vertical textlabels."

 :goodbye:

Attachment

ScrollTestLabelWithoutPanel-0.0.2.tar.gz

Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
Gianluigi is in the usergroup ‘GambOS Contributor’
Hi BruceSteers ,
I was thinking about Autoresize and Expand, which actually appear to be inconsistent.
How do you explain that this is the only way to make the Row property work with ScrollView?
Thanks.
P.S. I hope I'm not off-topic.  :$
Online now: No Back to the top

Post

Posted
Rating:
#8
Banned

Gianluigi said

Hi BruceSteers ,
I was thinking about Autoresize and Expand, which actually appear to be inconsistent.
How do you explain that this is the only way to make the Row property work with ScrollView?
Thanks.
P.S. I hope I'm not off-topic.  :$

I am not quite sure what you are asking?

AutoResize should not effect the internals of what the ScrollView.Arrangement is doing, it is more relevant to the outside container that it resides in.

Care should be taken to ensure anything that wants to auto size itself can be allowed to by it's container.
Online now: No Back to the top

Post

Posted
Rating:
#9
Banned
Back on topic

I've been playing with this and am now thinking maybe I've over-thought this and all you need is ScrollView1.ClientWidth

Never mind all the previous code I posted.

See if ScrollView1.ClientWidth gives the correct value.

Code

Dim iVisibleWidth as integer = ScrollView1.ClientWidth

Last edit: by BruceSteers

Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
Gianluigi is in the usergroup ‘GambOS Contributor’

BruceSteers said

I am not quite sure what you are asking?

AutoResize should not effect the internals of what the ScrollView.Arrangement is doing, it is more relevant to the outside container that it resides in.

Care should be taken to ensure anything that wants to auto size itself can be allowed to by it's container.

Yes, you're right; I didn't explain myself well.
I meant that for TextLabels to work properly within the Row-arranged ScrollView, the TextLabels must have their AutoResize and Expand properties set to True.
Which seems counterintuitive, as I think you also pointed out.
If I misunderstood, I apologize.

Of course, I am referring to the project I posted

 :goodbye:

Last edit: by Gianluigi

Online now: No Back to the top

Post

Posted
Rating:
#11
Banned
Gianluigi
A ScrollView has a resizable internal Contents area (ContentsWidth / ContentsHeight).
A normal container does not.

your program only crashed when the container resized to be larger than the controls because the parent container tries to expand it. the Scrollview does not do that , the scrollView expands but it's contents stop at the limit.

Hope that makes sense.
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
bill-lancaster is in the usergroup ‘Regular’
Thanks so much, does the job.
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
Gianluigi is in the usergroup ‘GambOS Contributor’
I'm glad you solved it.
Now I understand, the project I posted doesn't work.
So I'm attaching the corrected project, which didn't work the first time I tried it.
I probably worked on one object thinking it was another. :-/
Sorry for the noise and if I've gone off topic.

 :goodbye:

Attachment

ScrollTextLabel-0.0.2.tar.gz

Online now: No Back to the top
1 guest and 0 members have just viewed this.