Scroll bar dimensions

87 views
Skip to first unread message

Vinay Sajip

unread,
May 8, 2013, 8:00:58 AM5/8/13
to scintilla-interest
I'm trying to implement functionality whereby scroll bars are only
displayed when needed. In my application, the contents of the editor
are all in a single style, so the text height is a constant.

For the vertical scroll bar, I send the control a SCI_SETVSCROLLBAR
with a parameter of num_lines * text_height > control_height.

For the horizontal scroll bar, I enable scroll width tracking and
recompute the maximum scroll width after any change to the editor
contents. Since there's just one text style, the performance using
this approach seems acceptable.

However, if the vertical scroll bar is showing, I need to adjust for
this during the calculations, as the client width will depend on the
scroll bar visibility. How can I find the dimensions of the scrollbars
in a cross-platform way?

Regards,

Vinay Sajip

Neil Hodgson

unread,
May 8, 2013, 11:51:07 PM5/8/13
to scintilla...@googlegroups.com
Vinay Sajip:

> For the vertical scroll bar, I send the control a SCI_SETVSCROLLBAR
> with a parameter of num_lines * text_height > control_height.

The parameter to SCI_SETVSCROLLBAR is a boolean.
http://www.scintilla.org/ScintillaDoc.html#SCI_SETVSCROLLBAR

> However, if the vertical scroll bar is showing, I need to adjust for
> this during the calculations, as the client width will depend on the
> scroll bar visibility.

You specify the width of the document. Scintilla works out the current visible width and thus how to scroll.
http://www.scintilla.org/ScintillaDoc.html#SCI_SETSCROLLWIDTH

Neil

Vinay Sajip

unread,
May 9, 2013, 10:31:01 AM5/9/13
to scintilla-interest
On May 9, 4:51 am, Neil Hodgson <nyamaton...@me.com> wrote:

>    The parameter to SCI_SETVSCROLLBAR is a boolean.http://www.scintilla.org/ScintillaDoc.html#SCI_SETVSCROLLBAR

Thanks for the quick response. the parameter of num_lines *
text_height > control_height is a boolean - perhaps I should have
parenthesised for clarity as "(num_lines * text_height) >
control_height". That seems to work as expected.

>    You specify the width of the document. Scintilla works out the current visible width and thus how to scroll.http://www.scintilla.org/ScintillaDoc.html#SCI_SETSCROLLWIDTH

Yes, I got this from the documentation, but it doesn't work as
expected for me (I don't know if it's relevant, but I'm using
QScintilla2). With a call to SCI_SETSCROLLWIDTH with a value of 1, the
horizontal scrollbar is still shown! I did a call to
SCI_GETSCROLLWIDTH to make sure that the value had indeed been set
correctly, and it had. The same happens with other small values of the
scroll width, e.g. 8, 16, 24. To get the horizontal scroll bar to
disappear when it's not needed, I had to do the following after the
SCI_SETSCROLLWIDTH call:

1. Get the left margin width, say as mw.
2. If vertical scroll bar is showing, do mw += the vertical scroll bar
width.
3. If the scroll width passed with SCI_SETSCROLLWIDTH is greater than
(the control's width - mw), show the
horizontal scroll bar, else hide it, using SCI_SETHSCROLLBAR.

This is what prompted me to ask about how to get the vertical scroll
bar width. I know how to get the scrollbar width when using Qt, but I
wasn't sure if there was a cross-platform way (i.e. Scintilla API) to
do it.

Perhaps it's a QScintilla bug which requires the above steps to be
taken - I've not yet had a chance to try it with a bare Scintilla
control.

Regards,

Vinay Sajip

Neil Hodgson

unread,
May 9, 2013, 8:45:19 PM5/9/13
to scintilla...@googlegroups.com
Vinay Sajip:

> Yes, I got this from the documentation, but it doesn't work as
> expected for me (I don't know if it's relevant, but I'm using
> QScintilla2). With a call to SCI_SETSCROLLWIDTH with a value of 1, the
> horizontal scrollbar is still shown!

Make sure scroll width tracking is off as otherwise it will check and possibly expand width when painting.

I tried using ScintillaEditBase (a Qt binding distributed from scintilla.org which is not the same as QScintilla2) and the horizontal scroll bar appears and disappears as the window is made longer and shorter.

Neil

Reply all
Reply to author
Forward
0 new messages