PBEdit - a Canvas-based Texteditor

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

Thanks Mr.L! for this wonderful Canvas-based Texteditor, with all its features. I love it :)

For my needs, I made some modifications that could perhaps interest you.
  • Added View_Resize() in PBEdit_SetGadgetText() for multi-line texts otherwise only the first 2 lines are displayed
  • Add a Redonly parameter in PBEdit_Gadget(WindowID, X, Y, Width, Height, LanguageFile$ = "", ReadOnly = #False)
    In readonly, Redo/Undo, GadgetDrop procedures are not called and only some keys, mouse events are active
    In the example, the readonly mode is done with the parameter -Read : PBEdit -Read
  • Add a button in the top right corner, if wanted, with ex: PBedit_AddButton(editor, "Copy All")
    The button is made with a new canvas added, it would certainly be better if it was drawn directly in the main *view\canvas.
    With the EventType LeftClick, MouseEnter and MouseLeave events depending on the mouse position
    I'm a bit afraid to ruin this nice code, it would be nice if someone could implement it like this
  • For my needs and testing, personalized PBEdit_Dark(Light)Color.xml and PBEdit_Dark(Light)PureBasic.xml are included
The Vertival scroll bar doesn't work well but I didn't see how to fix it!

Please correct me, improves,.. it would be nice to have a part of it in your next update.
I named the version 1.0.85 not to interfere with yours: 1.0.8, 1.0.9
PBEdit_1_0_85.zip

Keep up the good work 8)
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

Hi ChrisR!
I'm glad you like my texteditor and thank you for your contributon :D ! The read only option is a nice feature, I will implement it in the next version.

Can you explain, what is wrong with the vertical Scrollbar? I have tested your code and everything seems to work fine on my computer.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

Hi Mr.L,
I'm glad you're here and ready to continue improving PBEdit, it's really worth it, it is awesome :)

for the vertical Scrollbar, with the included example (*te\visibleLineCount = 14)
If I reduce the window to show only 10 lines (*view\pageHeight = 10) and with the scrollbarV now displayed.
The PageLength calculation looks good ( 7692 = (10*10000)/(14-1)

But if I press the bottom button of the Scrollbar
In Event_ScrollBar() Procedure, I have, GetGadgetState(gNr) = 1 and lineNr = 0
lineNr = ( (GetGadgetState(gNr) + 1) * *te\visibleLineCount) / #TE_MaxScrollbarHeight

Which gives in Scroll_Line() *view\firstVisibleLineNr = 1 and not 2
I have ~ the same thing if I use the elevator
It works well with MouseWheel
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

A 2nd test, with the vertical scrollbar where the error seems further:

With the mouse wheel, I go to the bottom of the example, the displayed lines go from 4 to 14, it's OK.
If i press the top arrow, it is good at the 1st pass in Scroll_Line() with *view\firstVisibleLineNr = 3
Then in Scroll_Update(), *cursor\position\visibleLineNr is still 1 and

Code: Select all

pos = *cursor\position\visibleLineNr - *view\scroll\visibleLineNr  ; -2 = 1 - 3
If pos < 0
Scroll_Line(*te, *view, *cursor, *view\scroll\visibleLineNr + pos)  ; *view\scroll\visibleLineNr + pos = 3 - 2 = 1
And the 1st line is displayed.

#
I also found another small bug in ScrollUpdate()
If we reduce the display to the limit in height, width, without the 2 Scrollbars and then reduce only its height to make the vertical scrollbar appear.
The page width should be reduced to viewWidth - *te\scrollbarWidth and thus also display the horizontal bar.
The same thing in the other direction if we reduce its width, the horizontal scroll bar is displayed and the vertical scroll bar should follow.

I hope you will be able to reproduce and fix.
Just the little things I saw, the rest seems to work fine :)
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

For the Read Only mode, glad you like.

Instead of doing as I did for undo/redo, drag/drop, it is probably best to use your procedure in Undo_Add(),...

Code: Select all

ProcedureReturnIf(*te\readonly = #True)
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

ChrisR wrote: Tue Nov 09, 2021 1:47 am I also found another small bug in ScrollUpdate()
If we reduce the display to the limit in height, width, without the 2 Scrollbars and then reduce only its height to make the vertical scrollbar appear.
The page width should be reduced to viewWidth - *te\scrollbarWidth and thus also display the horizontal bar.
The same thing in the other direction if we reduce its width, the horizontal scroll bar is displayed and the vertical scroll bar should follow.
this should be fixed in the new version (1.0.9).
I also added a new flag "enableReadOnly" that can be set in the *.settings file

Here is the download link: Download

I guess the other bug (vertical scrollbar) will take a little more time.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

I didn't see that you had modified your post with the 1.0.9 download link now.
Thanks for your new version, there are a lot of changes and thanks for including the Read Only mode :)
Tested quickly, it looks good for the readonly mode, multines PBEdit_SetGadgetText, V&H Scrollbar display.
About readOnly, in addition to the *.settings file, it might be good to have a function to enable or disable it (ex: PBEdit_SetMode(ID, readOnly = #False)).
You removed PBEdit_SetCurrentPosition() I was using, is there any other way to do it ?
Thanks for all the good work done and good luck for the vertical scrollbar (I don't know, it doesn't seem simple but it might be easier based on ListSize(*te\textLine() and have GetGadgetState = 1st Line visible).
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

ChrisR wrote: Wed Nov 10, 2021 3:43 pm You removed PBEdit_SetCurrentPosition() I was using, is there any other way to do it ?
I have changed the Procedure name to PBEdit_SetCursorPosition(ID, LineNr, charNr)
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: PBEdit - a Canvas-based Texteditor

Post by Neil »

Hi Mr L

Sorry, but when I try and run your app I get the error message


The required compiler cannot be found
PureBasic 6.00 Alpha 5 - C backend


I have seen posts about C backend, but I thought that was something in development

Thanks

Neil
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

Mr.L wrote: Wed Nov 10, 2021 6:56 pm I have changed the Procedure name to PBEdit_SetCursorPosition(ID, LineNr, charNr)
It's all good, thanks :)

Mini thing seen, using PBEdit_LoadSettings, the scrollBar settings are not updated in the view, fix here in Settings_ReadXml() with

Code: Select all

Case "enablescrollbarhorizontal" : *te\enableScrollBarHorizontal = Val(value) : *te\view\scrollBarH\enabled = Val(value)	
Case "enablescrollbarvertical"   : *te\enableScrollBarVertical   = Val(value) : *te\view\scrollBarV\enabled = Val(value)

Neil wrote: Wed Nov 10, 2021 10:39 pm The required compiler cannot be found
PureBasic 6.00 Alpha 5 - C backend
PB6 alpha 5 with ASM and C compiler is available for testing and possibly reporting bugs, it is already well advanced.
Just change the compiler in compiler options if you use another version.
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PBEdit - a Canvas-based Texteditor

Post by StarBootics »

@Mr.L

Your canvas editor look nice but under linux I have only one line available. If I press the enter key there is no new line. I presume it's a bug but I don't have time to investigate.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: PBEdit - a Canvas-based Texteditor

Post by Rinzwind »

Under Windows cpu usage is low. Under macos it is around 6% which is quite high. Probably a gadget canvas macos performance issue?

Anyway, massively impressive job. Not sure what gave you they motivation to do this with pb, but wow. Thanks. Did it get inspired by a c project or from scratch?
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: PBEdit - a Canvas-based Texteditor

Post by Neil »

So I have loaded PureBasic6 compiler

Now I get this error message

Image

Thanks

Neil
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PBEdit - a Canvas-based Texteditor

Post by ChrisR »

The more I test, the more impressed I am, PBEdit is really very complete 8)
An additional function that would be interesting to have in future would be to auto-scroll (Left or right) when selecting with LeftButtonDown or LeftDoubleClick. As it has already been done for the vertical selection.
If the text line is bigger than the view size to be able to continue the selection or see the whole selection, if LeftDoubleClick.
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

Neil wrote: Thu Nov 11, 2021 11:24 am So I have loaded PureBasic6 compiler
Now I get this error message
seems strange to me. I have never seen that message before, neither with C-Backend nor with the "normal" copmiler.
What Operating system do you have?
Rinzwind wrote: Thu Nov 11, 2021 1:58 am Under Windows cpu usage is low. Under macos it is around 6% which is quite high
Yes, 6% is quite high. It surely has to do something with the constant redraw of the cursor, i suppose
StarBootics wrote: Thu Nov 11, 2021 12:53 am Your canvas editor look nice but under linux I have only one line available
I will look into that issue. Need to set up my Virtualbox first...
ChrisR wrote: Thu Nov 11, 2021 12:28 pm An additional function that would be interesting to have in future would be to auto-scroll (Left or right) when selecting with LeftButtonDown or LeftDoubleClick. As it has already been done for the vertical selection.
maybe in the next update :)
Post Reply