custom draw scrollbar

61 views
Skip to first unread message

Teodor Petrov

unread,
Jun 23, 2013, 9:18:21 AM6/23/13
to wx-...@googlegroups.com
Hi,

I want to implement a scrollbar that does something like the enhanced
scrollbar in the VS 2010+
Here are some example screen shots:
http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-92-metablogapi/7288.image_5F00_thumb_5F00_5E25D284.png
http://2.bp.blogspot.com/-iIec5_4GAUs/Ta1jXYHFA7I/AAAAAAAAAT4/SxLHjlZDcEs/s1600/EnhancedScrollbarVS2010.PNG

I want to do the first version, so what are my options in wxWidgets?
I want it to be as cross-platform as possible. I'm using a modified
wxScintilla for the editor.
And as far as I saw Notepad++ have done a workaround to get the second
variant of the
feature, see here:
http://notepad-plus-plus.org/assets/images/docMap.png
This is an option, but it doesn't look as fancy and modern as the
VStudio's solution.

I'm still on wx2.8 and there is no option to switch exclusively to
wx2.9, so the solution
should work on both version.

Best regards,
Teodor

Vadim Zeitlin

unread,
Jun 23, 2013, 9:05:07 PM6/23/13
to wx-...@googlegroups.com
On Sun, 23 Jun 2013 16:18:21 +0300 Teodor Petrov wrote:

TP> I want to implement a scrollbar that does something like the enhanced
TP> scrollbar in the VS 2010+
TP> Here are some example screen shots:
TP> http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-92-metablogapi/7288.image_5F00_thumb_5F00_5E25D284.png
TP> http://2.bp.blogspot.com/-iIec5_4GAUs/Ta1jXYHFA7I/AAAAAAAAAT4/SxLHjlZDcEs/s1600/EnhancedScrollbarVS2010.PNG

Well, the bad news is that this is so far away from the typical native
look and feel that you would have to do absolutely everything yourself. The
good news is that it should be possible to do it as you wouldn't be
constrained by the native scrollbars limitations.

TP> I want to do the first version, so what are my options in wxWidgets?

There is nothing for it right now. You'd have to create your own custom
scrolled window as the standard wxScrolledWindow relies on standard
scrollbars. Again, this should be possible but it won't be very simple.
And I really have no idea how to combine this with the use of wxSTC...
In short, this looks like a rather interesting project to me.

TP> I'm still on wx2.8 and there is no option to switch exclusively to
TP> wx2.9, so the solution should work on both version.

I don't think there is much difference between 2.8 and 2.9 in these
aspects.

Regards,
VZ

Paul K

unread,
Jun 24, 2013, 5:54:47 PM6/24/13
to wx-...@googlegroups.com
Teodor,
 
> I want it to be as cross-platform as possible. I'm using a modified wxScintilla for the editor.
> And as far as I saw Notepad++ have done a workaround to get the second variant of the
> feature, see here: http://notepad-plus-plus.org/assets/images/docMap.png
> This is an option, but it doesn't look as fancy and modern as the VStudio's solution.
I'm in a similar situation. I've been prototyping something very close to what you see on Notepad++ screenshot. In my case, the minimap is just another wxSTC control that "looks" at the same document; I can synchronize both of them such that scrolling in one scrolls the other one. Yes, it's not as fancy as VS solution, but at least I can do it with the current wxwidgets functionality.
 
What I can't figure out is that orange area in the minimap that matches the lines that are seen in the editor.
 
I haven't had a chance look at notepad++ to see how they do this; Does anyone know how this is done?
 
Paul.

Vadim Zeitlin

unread,
Jun 24, 2013, 6:45:43 PM6/24/13
to wx-...@googlegroups.com
On Mon, 24 Jun 2013 14:54:47 -0700 (PDT) Paul K wrote:

PK> What I can't figure out is that orange area in the minimap that matches the
PK> lines that are seen in the editor.
PK>
PK> I haven't had a chance look at notepad++ to see how they do this; Does
PK> anyone know how this is done?

Perhaps you could use wxOverlay for this?
VZ

Paul K

unread,
Jun 24, 2013, 7:47:45 PM6/24/13
to wx-...@googlegroups.com
Vadim,
 
> Perhaps you could use wxOverlay for this?
Quite possibly (by looking at the description). I need to give it a try as I've never used it before...
 
Thanks for the pointer.
 
Paul.
 

Teodor Petrov

unread,
Jun 25, 2013, 4:22:45 AM6/25/13
to wx-...@googlegroups.com
On 25.06.2013 00:54, Paul K wrote:
> I'm in a similar situation. I've been prototyping something very close
> to what you see on Notepad++ screenshot. In my case, the minimap is
> just another wxSTC control that "looks" at the same document; I can
> synchronize both of them such that scrolling in one scrolls the other
> one. Yes, it's not as fancy as VS solution, but at least I can do it
> with the current wxwidgets functionality.
>
Hi Paul,

Are you implementing this feature for an open-source project or closed one?
If it is the former can you share some code? :)

Best regards,
Teodor

Paul K

unread,
Jun 25, 2013, 6:00:37 PM6/25/13
to wx-...@googlegroups.com
Teodor:
 
> Are you implementing this feature for an open-source project or closed one?
> If it is the former can you share some code? :)
 
Yes, it's an open-source project (http://studio.zerobrane.com), but this code is not included yet; it's only a prototype I'm working on.
 
Something like this should give you an idea; this is in Lua, but you can easily map wxwidgets/wxstc calls to whatever works for you. This code simply sets the first line when it is scrolled. As the minimap is likely to have a different font size, you may need to come up with a different synchronization condition, but the main idea is likely to be the same.
 
require "wx"
local frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "STC Demo",
  wx.wxDefaultPosition, wx.wxSize(450, 450), wx.wxDEFAULT_FRAME_STYLE )
local e1 = wxstc.wxStyledTextCtrl(frame, wx.wxID_ANY,
  wx.wxDefaultPosition, wx.wxSize(0, 0), wx.wxBORDER_STATIC)
local e2 = wxstc.wxStyledTextCtrl(frame, wx.wxID_ANY,
  wx.wxDefaultPosition, wx.wxSize(0, 0), wx.wxBORDER_STATIC)
local sizer = wx.wxBoxSizer(wx.wxHORIZONTAL)
sizer:Add(e1, 1, wx.wxEXPAND + wx.wxALL, 10)
sizer:Add(e2, 1, wx.wxEXPAND + wx.wxALL, 10)
frame:SetAutoLayout(true)
frame:SetSizer(sizer)
 
e2:SetMarginWidth(1, 0)
e2:SetMarginLeft(2)
-- set doc pointers to the same document
local docpointer = e1:GetDocPointer()
e1:AddRefDocument(docpointer)
e2:SetDocPointer(docpointer)
 
-- create handlers that keep the two viewes in sync
local nosync = false
local function sync(ed1, ed2)
  return function()
    if nosync then return end
    nosync = true
    local line = ed1:GetFirstVisibleLine()
    if ed2:GetFirstVisibleLine() ~= line then ed2:ScrollToLine(line) end
    nosync = false
  end
end
e1:Connect(wxstc.wxEVT_STC_PAINTED, sync(e1, e2))
e2:Connect(wxstc.wxEVT_STC_PAINTED, sync(e2, e1))
 
frame:Show(true)
wx.wxGetApp():MainLoop()
 
Paul.
 
Reply all
Reply to author
Forward
0 new messages