[patch] Improve the horizontal scrollbar
Posted: 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)
call it from void LEditor::OnSciUpdateUI(wxScintillaEvent &event)
then the scrollbar will look better.
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);
}
}
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)
{
...