[Gtk] Fold margin formatting / Folding in the container

27 views
Skip to first unread message

Robin Haberkorn

unread,
Apr 26, 2025, 7:51:16 PMApr 26
to scintilla-interest
Hello everyone,

while trying to add some kind of folding support to my editor, I found that it
is relatively hard to get the fold margin correctly set up under Gtk. By
default, the folding symbols will be all circles (SC_MARK_CIRCLE) and what's
worse is that they are all black on white including the lines without any
markers. The margin type apparently has no influence on this, even though
SC_MARGIN_BACK/SC_MARGIN_FORE should somehow cause STYLE_DEFAULT to be
respected. Consequently, to configure the fold margin 2 for my color scheme and
two fold markers, I'd have to do something like:

SCI_SSETFOLDMARGINCOLOUR(1, BGCOLOR)
SCI_SSETFOLDMARGINHICOLOUR(1, BGCOLOR)

SCI_MARKERDEFINE(SC_MARKNUM_FOLDER, SC_MARK_CHARACTER+'+')
SCI_MARKERSETFORE(SC_MARKNUM_FOLDER, FGCOLOR)
SCI_MARKERSETBACK(SC_MARKNUM_FOLDER, BGCOLOR)

SCI_MARKERDEFINE(SC_MARKNUM_FOLDEROPEN, SC_MARK_CHARACTER+'-')
SCI_MARKERSETFORE(SC_MARKNUM_FOLDEROPEN, FGCOLOR)
SCI_MARKERSETBACK(SC_MARKNUM_FOLDEROPEN, BGCOLOR)

SCI_SETMARGINMASKN(2, (1 << 30) | (1 << 31))

Is this the expected behavior?
The fold margin on Scinterm is not black-on-white and even has '+'/'-' markers
by default.

In a related matter: I found that I couldn't enable folding on a lexer I
implemented in the container (ie. by hooking into SCN_STYLENEEDED
notifications). It's not sufficient to just set the fold level on lines
via SCI_SETFOLDLEVEL. There won't be any fold markers afterwards. I
suspect, that it's not currently possible without implementing the ILexer5
interface. If the problem is not on my side, I suggest that this should be
fixed. It's not very convenient to wrap ILexer5 in some third language.
Even in plain C, which is what I am using, this means to either add a C++
compilation unit and suddenly having to make practically all of my
internal headers C++-compatible, or having to write a plain C API wrapper
around ILexer5/IDocument with its dozens of functions. Also, I have "dumb"
lexers written in my scripting language, that are supposed to style the
document only once and it would be nice if I could let them also set the
fold levels. Although, for them I could probably implement some dummy
ILexer5 instance, which just makes sure that folding is enabled, since
they don't actually have to respond to lexing and folding requests
dynamically.

Best regards,
Robin

Neil Hodgson

unread,
Apr 27, 2025, 2:32:31 AMApr 27
to scintilla...@googlegroups.com
Robin Haberkorn:

> while trying to add some kind of folding support to my editor, I found that it
> is relatively hard to get the fold margin correctly set up under Gtk. By
> default, the folding symbols will be all circles (SC_MARK_CIRCLE)

Yes, applications are responsible for choosing the marker symbols and
colours used for the fold margin.

There is example code in SciTE around line 1420 of scite/src/SciTEProps.cxx.

> In a related matter: I found that I couldn't enable folding on a lexer I
> implemented in the container (ie. by hooking into SCN_STYLENEEDED
> notifications). It's not sufficient to just set the fold level on lines
> via SCI_SETFOLDLEVEL.

Indicating fold headers with the SC_FOLDLEVELHEADERFLAG is also needed.

Neil

Robin Haberkorn

unread,
Apr 27, 2025, 11:16:46 AMApr 27
to scintilla...@googlegroups.com
On Sun, 27 Apr 2025, Neil Hodgson wrote:

> Yes, applications are responsible for choosing the marker symbols and
> colours used for the fold margin.
>
But what are SCI_SETMARGINTYPEN(SC_MARGIN_BACK) and
SC_MARGIN_FORE supposed to do?

>
>> In a related matter: I found that I couldn't enable folding on a lexer I
>> implemented in the container (ie. by hooking into SCN_STYLENEEDED
>> notifications). It's not sufficient to just set the fold level on lines
>> via SCI_SETFOLDLEVEL.
>
> Indicating fold headers with the SC_FOLDLEVELHEADERFLAG is also needed.
>
Yes, I knew that. I did get it to work. The line with
SC_FOLDLEVELHEADERFLAG should still have the previous fold level. So for
instance

SCI_SETFOLDLEVEL(0, SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG)
SCI_SETFOLDLEVEL(1, SC_FOLDLEVELBASE+1)

appears to work for a one line fold, starting at line 1.

So it does work "from the container".

Thanks!
Robin

Neil Hodgson

unread,
Apr 27, 2025, 6:50:41 PMApr 27
to Scintilla mailing list
Robin Haberkorn:

> But what are SCI_SETMARGINTYPEN(SC_MARGIN_BACK) and SC_MARGIN_FORE supposed to do?

They choose the background colour for that margin.

Neil

Robin Haberkorn

unread,
May 1, 2025, 11:33:17 AMMay 1
to 'Neil Hodgson' via scintilla-interest
Hallo Neil,

they should choose the background color from STYLE_DEFAULT?

This is not what's happening. Have a look at this sample - it's a modified
"Bait" for Gtk 3:

https://gist.github.com/rhaberkorn/ce11d1b35633908d4af51eb16f79e1f0

Also, the automatic fold setting apparently doesn't work. I beliebve it
should be able to handle clicks automatically.

Best regards,
Robin

Neil Hodgson

unread,
May 1, 2025, 6:54:37 PMMay 1
to scintilla...@googlegroups.com
> This is not what's happening. Have a look at this sample - it's a modified
> "Bait" for Gtk 3:
>
> https://gist.github.com/rhaberkorn/ce11d1b35633908d4af51eb16f79e1f0

SCI_SETFOLDMARGINCOLOUR(bool useSetting, colour back)
SCI_SETFOLDMARGINHICOLOUR(bool useSetting, colour fore)
These messages allow changing the colour of the fold margin and fold
margin highlight. On Windows the fold margin colour defaults to
::GetSysColor(COLOR_3DFACE) and the fold margin highlight colour to
::GetSysColor(COLOR_3DHIGHLIGHT).

> Also, the automatic fold setting apparently doesn't work. I beliebve it
> should be able to handle clicks automatically.

SCI_SETMARGINSENSITIVEN(int margin, bool sensitive)
SCI_GETMARGINSENSITIVEN(int margin) → bool
Each of the five margins can be set sensitive or insensitive to mouse
clicks. A click in a sensitive margin sends a SCN_MARGINCLICK or
SCN_MARGINRIGHTCLICK notification to the container. Margins that are
not sensitive act as selection margins which make it easy to select
ranges of lines. By default, all margins are insensitive.

Neil
Reply all
Reply to author
Forward
0 new messages