I think this is a universal problem of GUIs, but I have no idea how to look for the algorithm.

The idea is simple, making from ground up an optimal edit area (like a TMemo, a TEdit, or the Delphi's editor).

The first problem that must be optimized is drawing the text lines in a way that consumes as little time as possible. For example, if a document of 100,000 lines is being edited in the text box, the idea is to show only the (let's say) 80 lines the user is watching. And not only that, if the content of that huge document is distributed in those 80 lines, to show only the characters inside the showable area.

That brings us to the second problem is which dealing with variable font widths. And later on dealing with styles...

Is out there any function in Pascal that can do most of this work in a general way? I mean, the function could have callback functions to get the document text, size font, cursor position, scrolling position, etc, etc, and then just order to draw each text line from one point to another.

Does something like that exist? :?