Page 1 of 1

Text BackColor questions in scintilla

Posted: Fri Nov 15, 2024 4:07 am
by ynkrc
I found the text has a white BackColor, but how to change it?

Code: Select all

If OpenWindow(0, 0, 0, 330, 390, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScintillaGadget(0, 5, 5, 320, 380,0)
  ScintillaSendMessage(0, #SCI_SETMARGINTYPEN,0,#SC_MARGIN_NUMBER)
  ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, 25)
  ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 1,#SC_MARGIN_TEXT)
  ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 1, 150)
  ScintillaSendMessage(0, #SCI_SETMARGINMASKN, 1, #SC_MASK_FOLDERS)
  ScintillaSendMessage(0, #SCI_SETFOLDMARGINCOLOUR,1,RGB(0, 255, 255))
  ScintillaSendMessage(0, #SCI_STYLESETBACK,#STYLE_LINENUMBER, RGB(172, 212, 204))
  ScintillaSendMessage(0, #SCI_STYLESETBACK,#STYLE_DEFAULT, RGB(255, 255, 0))
  ScintillaSendMessage(0, #SCI_SETTEXT,0, UTF8("text1"+#LF$+"text2"+#LF$+"text3"+#LF$+"text4"))
  ScintillaSendMessage(Gadget, #SCI_SETMARGINSENSITIVEN, 1, #True)
  ;ScintillaSendMessage(0, #SCI_MARGIN , 0, UTF8(":Batch 1"))
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 0, UTF8("line1"))
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 1, UTF8("line2"))
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 2, UTF8("line3"))
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 3, UTF8("line4"))
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Re: Text BackColor questions in scintilla

Posted: Fri Nov 15, 2024 12:03 pm
by spikey
You need to set the body style with #SCI_STARTSTYLING and #SCI_SETSTYLING. The margin style with #SCI_MARGINSETSTYLE. You will need to update as the body text is edited. This can be done via a callback responding to the #SCN_STYLENEEDED notification (or a lexer, if that's appropriate to you).

Code: Select all

#STYLE_CYAN = 1

If OpenWindow(0, 0, 0, 330, 390, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScintillaGadget(0, 5, 5, 320, 380,0)
                       
  ScintillaSendMessage(0, #SCI_SETMARGINTYPEN,0,#SC_MARGIN_NUMBER)
  ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, 25)
  ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 1,#SC_MARGIN_TEXT)
  ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 1, 150)
  ScintillaSendMessage(0, #SCI_SETMARGINMASKN, 1, #SC_MASK_FOLDERS)
  ScintillaSendMessage(0, #SCI_SETFOLDMARGINCOLOUR,1,RGB(0, 255, 255))
  ScintillaSendMessage(0, #SCI_STYLESETBACK,#STYLE_LINENUMBER, RGB(172, 212, 204))
  ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(255, 255, 0))
  ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_CYAN, RGB(0, 255, 255))
  
  ScintillaSendMessage(0, #SCI_SETTEXT,0, UTF8("text1"+#LF$+"text2"+#LF$+"text3"+#LF$+"text4"))
  ScintillaSendMessage(0, #SCI_STARTSTYLING, 0)
  ScintillaSendMessage(0, #SCI_SETSTYLING, ScintillaSendMessage(0, #SCI_GETLENGTH), #STYLE_DEFAULT)
  
  ScintillaSendMessage(0, #SCI_SETMARGINSENSITIVEN, 1, #True)
  ;ScintillaSendMessage(0, #SCI_MARGIN , 0, UTF8(":Batch 1"))
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 0, UTF8("line1"))
  ScintillaSendMessage(0, #SCI_MARGINSETSTYLE, 0, #STYLE_CYAN)
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 1, UTF8("line2"))
  ScintillaSendMessage(0, #SCI_MARGINSETSTYLE, 1, #STYLE_CYAN)
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 2, UTF8("line3"))
  ScintillaSendMessage(0, #SCI_MARGINSETSTYLE, 2, #STYLE_CYAN)
  ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 3, UTF8("line4"))
  ScintillaSendMessage(0, #SCI_MARGINSETSTYLE, 3, #STYLE_CYAN)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Text BackColor questions in scintilla

Posted: Fri Nov 15, 2024 4:45 pm
by ynkrc
Thanks for your reply. It works well,although the marginback and margintextback are not identical.The codes far exceeded my expectations
spikey wrote: Fri Nov 15, 2024 12:03 pm You need to set the body style with #SCI_STARTSTYLING and #SCI_SETSTYLING. The margin style with #SCI_MARGINSETSTYLE. You will need to update as the body text is edited. This can be done via a callback responding to the #SCN_STYLENEEDED notification (or a lexer, if that's appropriate to you).
....

Re: Text BackColor questions in scintilla

Posted: Fri Nov 15, 2024 5:05 pm
by spikey
ynkrc wrote: Fri Nov 15, 2024 4:45 pm ... the marginback and margintextback are not identical.
It's rendered with a checker-board pattern on lines with no text, if you zoom in. You might be able to achieve a closer match if you lighten the styles colour. I didn't try.

Re: Text BackColor questions in scintilla

Posted: Sat Nov 16, 2024 3:22 am
by ynkrc
yes,I set the color to RGB(180, 255, 255), the colors look almost the same.Thanks.
spikey wrote: Fri Nov 15, 2024 5:05 pm It's rendered with a checker-board pattern on lines with no text, if you zoom in. You might be able to achieve a closer match if you lighten the styles colour. I didn't try.

Re: Text BackColor questions in scintilla

Posted: Sat Nov 16, 2024 10:11 am
by spikey
You're welcome! :)