Best approach to build a line number view for a text editor
Posted
#1
(In Topic #1288)
Regular

I am playing on a text editor
what is the best approach/components to implement the line number view ?
Would be a of scrollview, textarea and something together?
Posted
Guru

Code (gambas)
- BuildForm
- LineNos
- Start
- ' Gambas class file
- Dim sText As String = "To be, or not to be, that is the question:\nWhether 'tis nobler in the mind to suffer\nThe slings and arrows of outrageous fortune,\nOr to take arms against a sea of troubles\nAnd by opposing end them. To die—to sleep,\nNo more; and by a sleep to say we end\nThe heart-ache and the thousand natural shocks\nThat flesh is heir to: 'tis a consummation\nDevoutly to be wish'd. To die, to sleep;\nTo sleep, perchance to dream—ay, there's the rub:\nFor in that sleep of death what dreams may come,\nWhen we have shuffled off this mortal coil,\nMust give us pause—there's the respect\nThat makes calamity of so long life.\nFor who would bear the whips and scorns of time,\nTh'oppressor's wrong, the proud man's contumely,\nThe pangs of dispriz'd love, the law's delay,\nThe insolence of office, and the spurns\nThat patient merit of th'unworthy takes,\nWhen he himself might his quietus make\nWith a bare bodkin? Who would fardels bear,\nTo grunt and sweat under a weary life,\nBut that the dread of something after death,\nThe undiscovere'd country, from whose bourn\nNo traveller returns, puzzles the will,\nAnd makes us rather bear those ills we have\nThan fly to others that we know not of?\nThus conscience doth make cowards of us all,\nAnd thus the native hue of resolution\nIs sicklied o'er with the pale cast of thought,\nAnd enterprises of great pith and moment\nWith this regard their currents turn awry\nAnd lose the name of action.\n"
- TextArea1.Text = sText
<IMG src="https://www.cogier.com/gambas/LineNumbers.png">
</IMG>EDIT: -
You can also use the built in Text Editor gb.form.editor
Posted
Regular

Another textarea with the same font
Thanks anyway.
Posted
Guru

TextEditor.class is what the gambas IDE uses and has many of the same features.
TextEditor1.ShowLineNumbers = True
/comp/gb.form.editor/texteditor - Gambas Documentation
Posted
Regular

Posted
Regular

BruceSteers said
use gb.form.editor
TextEditor.class is what the gambas IDE uses and has many of the same features.
TextEditor1.ShowLineNumbers = True
/comp/gb.form.editor/texteditor - Gambas Documentation
One doubt:
Textarea had .pos that gives like a "String.Left" position of the entire text
What is the equivalent in TextEditor class?
I found only: Line, Column, Current (that returns a line) but I didn't find an equivalent to .pos yet
Can you help?
Posted
Guru

I make my own Pos Property like this…
Save the following text as a file called TextEditor.class in your project source folder then you should then have TextEditor.Pos property.
Code (gambas)
PS. probably the Pos_Write method could be better.
Posted
Regular

Posted
Regular

BruceSteers said
It does not have a Pos property like Textarea, it has ToPos that converts line/column to a pos.
I make my own Pos Property like this…
Save the following text as a file called TextEditor.class in your project source folder then you should then have TextEditor.Pos property.Code (gambas)
PS. probably the Pos_Write method could be better.
Topos seems to be a Graphical position (pixels on screen) Is'nt it?
TextEditor.ToPos (gb.form.editor)
Function ToPos ( [ Line As Integer, Column As Integer ] ) As Point
Return the relative position in pixels of a specific cursor position.
Posted
Regular

Code
Texto.topos(line, col) it gives me [x y]
and I am looking for String.Len( of current position)
Posted
Guru

sergioabreu said
If I ran:
Code
Texto.topos(line, col)
it gives me [x y]
and I am looking for String.Len( of current position)
oops yep , I hadn't even realized ToPos gives a pixel position not a character position !
(I copied that code from my editor program, and it's wrong lol, cheers for spotting the bug)
Now I'm using this….
Code (gambas)
Posted
Regular

I thank you for showing me how to extend a class in gambas. It opens a universe lol
1 guest and 0 members have just viewed this.


