How do I get the horizontal scrollbar to appear only when needed?

1,001 views
Skip to first unread message

Eric Promislow

unread,
Oct 28, 2010, 2:23:13 PM10/28/10
to scintilla...@googlegroups.com
In Komodo 6 and Scite 2.02 (which scintilla Komodo 6 uses),
the horizontal scrollbar is always present, even for an empty
document.

In Komodo I can write a macro that controls its appearance,
by toggling the SetHScrollBar property.  But it doesn't work
the way the docs have me expect:

"""
SCI_SETHSCROLLBAR(bool visible)
SCI_GETHSCROLLBAR
The horizontal scroll bar is only displayed if it is needed for the assumed width. If you never wish to see it, call SCI_SETHSCROLLBAR(0). Use SCI_SETHSCROLLBAR(1) to enable it again. SCI_GETHSCROLLBAR returns the current state. The default state is to display it when needed.
"""

If visible is 1, the scrollbar is always displayed.  If it's 0, it's never
displayed.  Is this a bug, or is there something else I need to do?

- Eric

flashk

unread,
Oct 28, 2010, 6:00:52 PM10/28/10
to scintilla-interest
Hi Eric,

On Oct 28, 11:23 am, Eric Promislow <eric.promis...@gmail.com> wrote:
> If visible is 1, the scrollbar is always displayed.  If it's 0, it's never
> displayed.  Is this a bug, or is there something else I need to do?

Try enabling scroll width tracking using SCI_SETSCROLLWIDTHTRACKING.
Then set the scroll width to a low value using SCI_SETSCROLLWIDTH (I
use 5). Now the horizontal scroll bars should only appear if any
displayed lines exceed the width of the window. One thing to note, the
documentation states that scroll width tracking will never reduce the
scroll width. So you will need to manually lower the scroll width if
the width of the content is reduced.

-farshid

Neil Hodgson

unread,
Oct 28, 2010, 6:00:53 PM10/28/10
to scintilla...@googlegroups.com
Eric Promislow:

> In Komodo 6 and Scite 2.02 (which scintilla Komodo 6 uses),
> the horizontal scrollbar is always present, even for an empty
> document.

> ...


> If visible is 1, the scrollbar is always displayed.  If it's 0, it's never
> displayed.  Is this a bug, or is there something else I need to do?

Its going to depend on the scroll width so investigate
SCI_SETSCROLLWIDTH and SCI_SETSCROLLWIDTHTRACKING.
http://www.scintilla.org/ScintillaDoc.html#SCI_SETSCROLLWIDTH

Neil

Eric Promislow

unread,
Nov 1, 2010, 1:33:48 PM11/1/10
to scintilla...@googlegroups.com
Obviously we've implemented it incorrectly in Komodo, but I'm finding it still
doesn't work 100% if I drive it from the interactive shell.  For example, using
a fixed-width font, if I set scrollWidth to 600, and scrollWidthTracking to true,
the horiz scroll bar appears when I type a long line.  But when I delete text
so the line fits within the view (and xoffset is 0), the horizontal scroll bar
is still there.  The interactive shell shows me that scrollWidth has increased
from 600 to 845, which would explain why the scroll bar is there.

Does our client code have to do more work to implement this correctly?

- Eric

Neil Hodgson

unread,
Nov 1, 2010, 5:26:06 PM11/1/10
to scintilla...@googlegroups.com
Eric Promislow:

> ... using a fixed-width font, if I set scrollWidth to 600, and


> scrollWidthTracking to true, the horiz scroll bar appears when
> I type a long line.  But when I delete text so the line fits within
> the view (and xoffset is 0), the horizontal scroll bar is still
> there.  The interactive shell shows me that scrollWidth has
> increased from 600 to 845, which would explain why the scroll
> bar is there.

This is the intended behaviour. As the documentation says: "This
mode never adjusts the scroll width to be narrower." This is due to
the performance cost of dynamically determining the current widest
line.

> Does our client code have to do more work to implement this correctly?

Yes.

Neil

Eric Promislow

unread,
Nov 3, 2010, 5:04:34 PM11/3/10
to scintilla...@googlegroups.com
Does anyone have this working?  On all three main platforms?

- Eric


  Neil

--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla...@googlegroups.com.
To unsubscribe from this group, send email to scintilla-inter...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.


Jason Haslam

unread,
Nov 3, 2010, 5:56:43 PM11/3/10
to scintilla...@googlegroups.com
We do, but we have to enforce the same fixed-width font for every style in the document to get acceptable performance. When a document is opened for the first time we measure each line using:

 POINTXFROMPOSITION(GETLINEENDPOSITION(line)) - POINTXFROMPOSITION(POSITIONFROMLINE(line))

I suppose that this causes line layout to happen in advance for each line but it seems very fast. The key is that the entire document doesn't have to be styled in advance because we know that the font for all the of styles will be the same as STYLE_DEFAULT. We maintain a SplitVector of these line widths that tracks insertions and deletions.

I think that most editors that use scintilla wouldn't be willing to enforce the same font for each style.

Jason
Reply all
Reply to author
Forward
0 new messages