Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with line wrapping with SDL2 frontend when line numbers is disabled #1243

Closed
HappyEnt opened this issue Jan 8, 2024 · 5 comments
Closed
Labels
bug sdl2 Issue related to the SDL2 frontend

Comments

@HappyEnt
Copy link

HappyEnt commented Jan 8, 2024

Hello,

its me again. Unfortunately #1241 did not fix the problem completely with the SDL2 line wrapping implementation,
as it now only works when line numbers are also enabled. When they are disabled the following error is thrown upon encountering
a too long line:

 SDL Error (#<SDL-SURFACE {#X00000000}>): Text has zero width
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {7006240513}>

...

21: ((LAMBDA (LEM-CORE::E) :IN LEM-CORE::CALL-WITH-DISPLAY-ERROR) #<SDL2-TTF::SDL-TTF-ERROR {700D848853}>)
22: (SB-KERNEL::%SIGNAL #<SDL2-TTF::SDL-TTF-ERROR {700D848853}>)
23: (ERROR SDL2-TTF::SDL-TTF-ERROR :RC #<SDL2-FFI:SDL-SURFACE {#X00000000}> :STRING "Text has zero width")
24: (SDL2-TTF:RENDER-UTF8-BLENDED #<SDL2-FFI:TTF-FONT {#X1480E2A00}> #.(SB-SYS:INT-SAP #X600000CE49F0) 208 208 208 0)
25: (LEM-SDL2/DRAWING::MAKE-TEXT-SURFACE #<LEM-SDL2/DISPLAY:DISPLAY {7003972AB3}> "" NIL :LATIN)
26: (LEM-SDL2/DRAWING::MAKE-TEXT-SURFACE-WITH-CACHE #<LEM-SDL2/DISPLAY:DISPLAY {7003972AB3}> "" NIL :LATIN)
27: ((:METHOD LEM-SDL2/DRAWING::GET-SURFACE :AROUND (T T)) #<LEM-CORE/DISPLAY:TEXT-OBJECT {700D82B703}> #<LEM-SDL2/DISPLAY:DISPLAY {7003972AB3}>) [fast-method]
28: ((:METHOD LEM-SDL2/DRAWING::OBJECT-WIDTH (LEM-CORE/DISPLAY:TEXT-OBJECT T)) #<LEM-CORE/DISPLAY:TEXT-OBJECT {700D82B703}> #<LEM-SDL2/DISPLAY:DISPLAY {7003972AB3}>) [fast-method]
29: ((:METHOD LEM-SDL2/DRAWING::DRAW-OBJECT (LEM-CORE/DISPLAY:TEXT-OBJECT T T T T)) #<LEM-CORE/DISPLAY:TEXT-OBJECT {700D82B703}> 0 153 #<LEM-SDL2/DISPLAY:DISPLAY {7003972AB3}> #<LEM-SDL2/VIEW::VIEW {7005C14883}>) [fast-method]
30: (LEM-SDL2/DRAWING::REDRAW-PHYSICAL-LINE #<LEM-SDL2/DISPLAY:DISPLAY {7003972AB3}> #<LEM-SDL2/VIEW::VIEW {7005C14883}> 0 136 (#<LEM-CORE/DISPLAY:TEXT-OBJECT {700D82B703}>) 17)
31: (LEM-CORE::REDRAW-LOGICAL-LINE-WHEN-LINE-WRAPPING #<LEM-CORE:WINDOW {7005A3F053}> 136 #S(LEM-CORE::LOGICAL-LINE :STRING "        :do (let ((pos (position c elt :start start :test (if ignore-case #'char-equal #'char=))))" :ATTRIBUTES ((8 11 LEM-CORE:SYNTAX-BUILTIN-ATTRIBUTE) (12 13 NIL) (13 16 LEM-BASE:SYNTAX-KEYWORD-ATTRIBUTE) (16 17 NIL) (39 45 LEM-CORE:SYNTAX-BUILTIN-ATTRIBUTE) (52 57 LEM-CORE:SYNTAX-BUILTIN-ATTRIBUTE) (58 59 NIL) (59 61 LEM-BASE:SYNTAX-KEYWORD-ATTRIBUTE NIL) (61 62 NIL)) :LEFT-CONTENT NIL :END-OF-LINE-CURSOR-ATTRIBUTE NIL :EXTEND-TO-END NIL :LINE-END-OVERLAY NIL) NIL 0)
32: ((LAMBDA (LEM-CORE::LOGICAL-LINE) :IN LEM-CORE::REDRAW-LINES) #S(LEM-CORE::LOGICAL-LINE :STRING "        :do (let ((pos (position c elt :start start :test (if ignore-case #'char-equal #'char=))))" :ATTRIBUTES ((8 11 LEM-CORE:SYNTAX-BUILTIN-ATTRIBUTE) (12 13 NIL) (13 16 LEM-BASE:SYNTAX-KEYWORD-ATTRIBUTE) (16 17 NIL) (39 45 LEM-CORE:SYNTAX-BUILTIN-ATTRIBUTE) (52 57 LEM-CORE:SYNTAX-BUILTIN-ATTRIBUTE) (58 59 NIL) (59 61 LEM-BASE:SYNTAX-KEYWORD-ATTRIBUTE NIL) (61 62 NIL)) :LEFT-CONTENT NIL :END-OF-LINE-CURSOR-ATTRIBUTE NIL :EXTEND-TO-END NIL :LINE-END-OVERLAY NIL))
33: (LEM-CORE::CALL-DO-LOGICAL-LINE #<LEM-CORE:WINDOW {7005A3F053}> #<FUNCTION (LAMBDA (LEM-CORE::LOGICAL-LINE) :IN LEM-CORE::REDRAW-LINES) {700D7E98AB}>)
34: (LEM-CORE::REDRAW-LINES #<LEM-CORE:WINDOW {7005A3F053}>)
35: ((:METHOD LEM-CORE:REDRAW-BUFFER (T LEM-BASE:TEXT-BUFFER T T)) #<unused argument> #<LEM-BASE:TEXT-BUFFER completion.lisp /Users/christian/common-lisp/lem/src/completion.lisp {700ED00073}> #<LEM-CORE:WINDOW {7005A3F053}> NIL) [fast-method]
36: ((SB-PCL::EMF LEM-CORE:REDRAW-BUFFER) #<unused argument> #<unused argument> #<LEM-SDL2/SDL2:SDL2 {7005877863}> #<LEM-BASE:TEXT-BUFFER completion.lisp /Users/christian/common-lisp/lem/src/completion.lisp {700ED00073}> #<LEM-CORE:WINDOW {7005A3F053}> NIL)
37: ((LAMBDA NIL :IN LEM-CORE:REDRAW-BUFFER))
@mychris
Copy link
Contributor

mychris commented Jan 8, 2024

Thanks for your feedback. Could you try out the PR and report back if it is working for you? My tests looked promising.

@HappyEnt
Copy link
Author

HappyEnt commented Jan 9, 2024

Looks good so far :)! I haven't encountered any crashes yet. However, moving to the end of a line when wrapping is enabled currently acts a little bit up and does not properly jump to the end of the line in all cases. I guess this probably unrelated to this issue / SDL2, I will look into this problem a little bit more tomorrow when I have a little bit more time.

@mychris
Copy link
Contributor

mychris commented Jan 9, 2024

Looks good so far :)! I haven't encountered any crashes yet.

Very good.

However, moving to the end of a line when wrapping is enabled currently acts a little bit up and does not properly jump to the end of the line in all cases.

Let me see if we are thinking about the same thing here, because there are some navigational problems with line wrapping and line-numbers right now.
If you are at the beginning of a line, which is wrapped to several lines and you are at the very beginning of it, executing M-x next-line will move in a stair like fashion, meaning:

   1|█aaaaaaaaa
    |aaaaaaaaaa
    |aaaaaaaaaa
   2|

will move to

   1|aaaaaaaaaa
    |aaaa█aaaaa
    |aaaaaaaaaa
   2|

The same is true if you execute M-x move-to-end-of-line.

The problem here is that the backend window structure doesn't yet know anything about the line-numbers and makes all of its calulation based on the full width of the window. This has nothing to do with rendering indeed.
The backend window needs to get knowledge about the width of the body of the window (meaning the are which contains the buffer contents) and needs to have knowledge about some sort of left and right margins, in which things like line-numbers can be drawn. But that's not done yet.

If you are thinking about something else, please elaborate on it, so I can see if it is indeed a problem in the frontend/communication between frontend and backend.

Commands that act on logical lines like M-x next-logical-line and M-x move-to-end-of-logical-line should work fine though.

EDIT: I have seen there is window-left-width which holds the size of the left margin, but it isn't used in the calculations yet.

@mychris
Copy link
Contributor

mychris commented Jan 9, 2024

I updated the PR. navigation is not perfect yet but seems better.

@HappyEnt
Copy link
Author

Yes! Thats exactly the behavior I also observed. I can't even keep up with how fast you are fixing this things, thanks very much for the efforts :)! I will try out your fix later after work.

@Sasanidas Sasanidas added bug sdl2 Issue related to the SDL2 frontend labels Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug sdl2 Issue related to the SDL2 frontend
Projects
None yet
Development

No branches or pull requests

4 participants