[patch] Improve the horizontal scrollbar

Discussion about CodeLite development process and patches
count0
CodeLite Enthusiast
Posts: 16
Joined: Fri Jul 04, 2008 10:46 am
Contact:

[patch] Improve the horizontal scrollbar

Post by count0 » Sun Oct 05, 2008 1:35 pm

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.

User avatar
eranif
CodeLite Plugin
Posts: 6120
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: [patch] Improve the horizontal scrollbar

Post by eranif » Mon Oct 06, 2008 3:03 pm

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
Make sure you have read the HOW TO POST thread

count0
CodeLite Enthusiast
Posts: 16
Joined: Fri Jul 04, 2008 10:46 am
Contact:

Re: [patch] Improve the horizontal scrollbar

Post by count0 » Mon Oct 06, 2008 4:52 pm

OK, here it is. Hope it won't break anything...
You do not have the required permissions to view the files attached to this post.

User avatar
eranif
CodeLite Plugin
Posts: 6120
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: [patch] Improve the horizontal scrollbar

Post by eranif » Tue Oct 07, 2008 3:39 pm

Patch applied (for all OSs) - thanks, looking good

Eran
Make sure you have read the HOW TO POST thread

Post Reply