Size: a a a

2021 January 03

VA

Vadim Averin in pro.algorithms
Firstly, how do you want to scroll the content? By dragging the content or by scrolling the wheel/dragging a scrollbar?
источник

VA

Vadim Averin in pro.algorithms
Matthew Good
Like, scrolling the scroll bar should scroll the content proportionally right?

For example

If the bar is at the top, the content is at the top

If the bar is in the middle, the content is in the middle

If the bar is at the bottom, the content is at the bottom
OK. I understand
источник

MG

Matthew Good in pro.algorithms
Vadim Averin
Firstly, how do you want to scroll the content? By dragging the content or by scrolling the wheel/dragging a scrollbar?
Dragging a scroll bar
источник

VA

Vadim Averin in pro.algorithms
The JScrollPane is the solution
источник

VA

Vadim Averin in pro.algorithms
It will handle all scrolling logic
источник

MG

Matthew Good in pro.algorithms
Yes but I want to implement the logic myself
источник

VA

Vadim Averin in pro.algorithms
🤦‍♂️
источник

AM

Azure Mynn in pro.algorithms
Matthew Good
Like, scrolling the scroll bar should scroll the content proportionally right?

For example

If the bar is at the top, the content is at the top

If the bar is in the middle, the content is in the middle

If the bar is at the bottom, the content is at the bottom
Oh, well, you divide the current position of the bar by the total height of it (minus the height of the draggable bar itself) to get a value between 0 and 1, you can then multiply it by the page height in pixels or something to get the desired offset
источник

AM

Azure Mynn in pro.algorithms
Smth like curBarY / (totalScrollHeight - barHeight) * pageHeight
источник

VA

Vadim Averin in pro.algorithms
Azure Mynn
Oh, well, you divide the current position of the bar by the total height of it (minus the height of the draggable bar itself) to get a value between 0 and 1, you can then multiply it by the page height in pixels or something to get the desired offset
It wouldn't work if the scrollbar's thumb isn't just a dot/a circle.
источник

VA

Vadim Averin in pro.algorithms
Azure Mynn
Smth like curBarY / (totalScrollHeight - barHeight) * pageHeight
Well, but it would
источник

AM

Azure Mynn in pro.algorithms
Vadim Averin
It wouldn't work if the scrollbar's thumb isn't just a dot/a circle.
It would, because we subtract the height of it :)
источник

VA

Vadim Averin in pro.algorithms
@smallville7123 Hey, are you inventing a graphic engine or something?
источник

MG

Matthew Good in pro.algorithms
Azure Mynn
Oh, well, you divide the current position of the bar by the total height of it (minus the height of the draggable bar itself) to get a value between 0 and 1, you can then multiply it by the page height in pixels or something to get the desired offset
Hmm, so as an example

If the window is 30 pixels

The content is 60 pixels

The scroll bar (excuding buttons) is 30 pixels

And the bar itself is 15 pixels

If the bar is offset by 15 pixels (at the bottom)

Then...

Val = 15 / (30-15)

Offset = Val * 60

Something like that?
источник

AM

Azure Mynn in pro.algorithms
And as for the height itself, it can be the height of the container divided by the real height of the contents
источник

AM

Azure Mynn in pro.algorithms
Matthew Good
Hmm, so as an example

If the window is 30 pixels

The content is 60 pixels

The scroll bar (excuding buttons) is 30 pixels

And the bar itself is 15 pixels

If the bar is offset by 15 pixels (at the bottom)

Then...

Val = 15 / (30-15)

Offset = Val * 60

Something like that?
Yep, something like that
источник

AM

Azure Mynn in pro.algorithms
Oh, actually you might also want to subtract 30 from 60
источник

AM

Azure Mynn in pro.algorithms
Because the offset probably should leave a certain amount of height after it
источник

MG

Matthew Good in pro.algorithms
Hm so this?

Val = 15 / (30-15)

Offset = Val * (60 - 30)
источник

AM

Azure Mynn in pro.algorithms
Matthew Good
Hm so this?

Val = 15 / (30-15)

Offset = Val * (60 - 30)
I mean 60 - 30, but yeah, and also you should clamp all the values so they don't go out of bounds
источник