STR #2621

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | Roadmap 1.3 ]

STR #2621

Application:FLTK Library
Status:1 - Closed w/Resolution
Priority:1 - Request for Enhancement, e.g. asking for a feature
Scope:3 - Applies to all machines and operating systems
Subsystem:Core Library
Summary:Line numbers in Fl_Text_Display/Editor
Version:1.3-feature
Created By:Jimmio92
Assigned To:greg.ercolano
Fix Version:1.3-current (SVN: v10152)
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:


Name/Time/Date Filename/Size top right image
 
#1 LZAntal
06:47 Oct 29, 2012
LZA_FL_Text_Editor.diff
10k
 
 
#2 LZAntal
06:51 Oct 29, 2012
LZA_FL_Text_Editor-linenumbers.png
115k
 
 
#3 greg.ercolano
17:32 May 19, 2014
Fl_Text_Display-v2.patch
14k
 
 
#4 greg.ercolano
17:42 May 19, 2014
Fl_Text_Display-v3.patch
14k
 
bottom left image   bottom right image

Trouble Report Comments:


Name/Time/Date Text top right image
 
#1 Jimmio92
23:02 May 05, 2011
Fltk2 has it, as far as I can tell, and there seems to be a function related to it in 1.3, however after many attempts, I see no way of activating it. Could it be ported to 1.3 and/or written?  
 
#2 LZAntal
06:50 Oct 29, 2012
LZA_FL_Text_Editor.diff is a patch to the current 1.3 svn-9705 it adds line number support to it. It also handles line wrapping and aligns the numbers nicely to the right.
LZA_FL_Text_Editor-linenumbers.png screenshot showing it action.
 
 
#3 greg.ercolano
15:46 May 19, 2014
Assigning this to myself.. investigating adding it for 1.3.3.

We now have the FLTK_ABI_VERSION macro that allows us to add
ABI breaking features, so I can address the TODO items mentioned
in the diff file.
 
 
#4 greg.ercolano
17:32 May 19, 2014
First let me thank LZA for such a clean and simple patch!

I started with that, and tweaked only a few things, mostly implementing
your TODO items the patch comments recommend. Also mods for indent and doxygen.

I addressed the TODO items by adding the following methods:

         linenumber_font()    -- font used for line#s
         linenumber_size()    -- font size use for line#s
         linenumber_align()   -- left/center/right align for line#s
         linenumber_fgcolor() -- foreground color for line# text
         linenumber_bgcolor() -- background color for line# text
         linenumber_fmt()     -- printf() style format string (lets one set
                                 digit padding, decimal vs. hex vs. octal

If the FLTK_ABI_VERSION is set to 10303, the set/get methods work as expected. Otherwise, the get methods return hardcoded defaults, and the set methods do nothing. Docs for set methods indicate the need for the ABI macro to be set.

The result of these mods is Fl_Text_Display-v2.patch, attached here as a first pass.

I tested briefly on linux with various font sizes for textsize() vs. linenumber_size()
to make sure the line numbers end up drawn in the right places.

Will test on other platforms to make sure everything works before committing.
Folks are welcome to test and follow up here with comments/suggs.

Thinking for the future: we /might/ want to add a "line number offset" method,
so that apps like fluid can show line numbers in the Fl_Text_Display oriented
code windows so that line#s correspond to the final code's line#s. In this case
the first line# in the code windows would NOT be 1.

New -> Active, assigning to Core Library, and changed software version from 1.4 -> 1.3.
 
 
#5 greg.ercolano
17:42 May 19, 2014
Attaching Fl_Text_Display-v3.patch with small mod to v2,
changing the name for the line number formatting method from:

    linenumber_padstr()  // old
    linenumber_format()  // new

..because I think 'format' is a better name for that method.
 
 
#6 greg.ercolano
17:47 May 19, 2014
TODO:

    * Add some short doxygen docs in Fl_Text_Display's description
      section describing how to enable+use line#s. Include screenshots.

    * Perhaps modify test/editor to include View->Line Numbers menu option.
 
 
#7 greg.ercolano
23:32 May 20, 2014
Note to LZA: in your patch, a note about the following code:

+      /* LZA
+       without calling the draw_line_numbers method here when we
+       hit enter for new line no line number gets drawn
+      */
+      textD->draw_line_numbers(true);
+      //textD->damage( ::FL_DAMAGE_EXPOSE );

..this can cause trouble because draw_line_numbers() does actual
FLTK drawing operations (e.g. fl_rectf()) which aren't valid in this
context (modify callback) because draw operations aren't allowed
outside of the draw() method. Linux would throw the following X errors
in 'editor' when opening different files while line numbers are enabled:

---
X_PolyFillRectangle: BadDrawable (invalid Pixmap or Window parameter) 0x3400f0c
XRequest.139: BadDrawable (invalid Pixmap or Window parameter) 0x3400f0c
XRequest.139: RenderBadPicture (invalid Picture parameter) 0x3400f0c
XRequest.139: RenderBadPicture (invalid Picture parameter) 0x3400e6d
---

I've tested with that line commented out on all three platforms, and
line numbers seem to work normally when the Enter key is hit, so will
probably just leave it out in the final commit.
 
 
#8 greg.ercolano
00:02 May 21, 2014
Fixed in Subversion repository.

Committed r10152 with some extra mods for correct cross platform
colors, doxygen docs, etc.

Modified editor to have a new Edit -> Preferences -> Line Numbers
option so line#s can be enabled/disabled.

Closing. If you find any issues with this feature, start a new STR.
If you have comments about this STR, please follow up on the
fltk.coredev (google groups), and if need be, I can reopen.
 
 
#9 AlbrechtS
06:53 Aug 16, 2014
Great new feature. Thanks to the OP and Greg.

I have only one comment: Maybe it would be wise to copy and store the format string given by Fl_Text_Display::linenumber_format(const char* val) internally (and free in the d'tor, if one was copied), just like copy_label() for widgets. Just to avoid common errors like constructing the format string in local (stack) variables in user code.

Opinions?
 
 
#10 greg.ercolano
12:48 Oct 27, 2014
Fixed in Subversion repository.

Agreeing with Albrecht's comment #9; added in r10396, docs included.

Closing.
 
bottom left image   bottom right image

Return to Bugs & Features ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2022 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.