Page 1 of 1

[patch] Improve the horizontal scrollbar

Posted: Sun Oct 05, 2008 1:35 pm
by count0
I found most editor/IDEs using Scintilla have a little annoyance: the horizontal scrollbar is ugly, it's always set to a very large length and never change.
Except the Notepad++, it will recalculate and set the length of horizontal scrollbar on UpdateUI event, so the horizontal scrollbar looks very nice, this is some code I learned from it.

Add a function to LiteEditor/cl_editor.cpp (and decalare it in header, of course)

Code: Select all

void LEditor::recalcHorizontalScrollbar()
{
	// recalculate and set the length of horizontal scrollbar
	int maxPixel = 0;
	int startLine = GetFirstVisibleLine();
	int endLine =  startLine + LinesOnScreen();
	if (endLine >= (GetLineCount() - 1))
		endLine--;

	for (int i = startLine; i <= endLine; i++) {
		int visibleLine = (int) DocLineFromVisible(i);			//get actual visible line, folding may offset lines
		int endPosition = GetLineEndPosition(visibleLine);		//get character position from begin
		int beginPosition = PositionFromLine(visibleLine);		//and end of line

		wxPoint beginPos = PointFromPosition(beginPosition);
		wxPoint endPos = PointFromPosition(endPosition);

		int curLen = endPos.x - beginPos.x;
		
		if (maxPixel < curLen) //If its the largest line yet
			maxPixel = curLen;
	}

	if (maxPixel == 0)
		maxPixel++;											//make sure maxPixel is valid

	int currentLength = GetScrollWidth();					//Get current scrollbar size
	if (currentLength != maxPixel) {
		//And if it is not the same, update it
		SetScrollWidth(maxPixel);
	}
}
call it from void LEditor::OnSciUpdateUI(wxScintillaEvent &event)

Code: Select all

void LEditor::OnSciUpdateUI(wxScintillaEvent &event)
{
...
#ifdef __WXMAC__
		Refresh();
#endif

	}

    recalcHorizontalScrollbar(); // Call it here!

	//let the context handle this as well
	m_context->OnSciUpdateUI(event);
}

void LEditor::OnMarginClick(wxScintillaEvent& event)
{
...
then the scrollbar will look better.

Re: [patch] Improve the horizontal scrollbar

Posted: Mon Oct 06, 2008 3:03 pm
by eranif
Hi,

this patch looks good, however I might apply it for windows only since on Linux /Mac sxScintilla is not the fastest component...

EDIT:

It will be better if you send a .patch file instead of what you just did.

to create patch file do this:
Switch to the explorer tab
right click on 'trunk'
and select svn -> show diff
you will then get a .diff file rename this file and post it


Eran

Re: [patch] Improve the horizontal scrollbar

Posted: Mon Oct 06, 2008 4:52 pm
by count0
OK, here it is. Hope it won't break anything...

Re: [patch] Improve the horizontal scrollbar

Posted: Tue Oct 07, 2008 3:39 pm
by eranif
Patch applied (for all OSs) - thanks, looking good

Eran