Skip to content

Commit

Permalink
generate: Only enter affected area
Browse files Browse the repository at this point in the history
Closes #199
  • Loading branch information
ArthaTi committed Nov 3, 2024
1 parent 1ffa8fa commit 2051081
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
26 changes: 21 additions & 5 deletions source/fluid/text/text.d
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ struct StyledText(StyleRange = TextStyleSlice[]) {
return indexAtDots(backend.scale * needle);

}

/// ditto
size_t indexAtDots(Vector2 needle) {

Expand Down Expand Up @@ -878,24 +878,40 @@ struct StyledText(StyleRange = TextStyleSlice[]) {
// No chunks to render, stop here
if (newChunks.empty) return;

auto startY = +float.infinity;
auto endY = -float.infinity;

// Clear the chunks
foreach (chunkIndex; newChunks.save) {

texture.clearImage(chunkIndex);

// Find the topmost and bottommost chunk
auto rect = texture.chunkRectangle(chunkIndex);
if (rect.y < startY) startY = rect.y;
if (rect.end.y > endY) endY = rect.end.y;

}

auto ruler = TextRuler(typeface, _sizeDots.x);
auto start = indexAtDots(Vector2(0, startY));
auto ruler = rulerAt(start);
bool started;

// Copy the layer range, make it infinite
auto styleMap = this.styleMap.save.chain(TextStyleSlice.init.repeat);

// Run through the text
foreach (line; value.byLine) {
foreach (line; value[start .. $].byLine) {

auto index = line.index;
auto index = start + line.index;

if (started) {
ruler.startLine();
}
else started = true;

ruler.startLine();
// Stop when reached the end of the drawable area
if (ruler.caret.y > endY) break;

// Split on words
// TODO use the splitter provided when resizing
Expand Down
16 changes: 11 additions & 5 deletions source/fluid/text_input.d
Original file line number Diff line number Diff line change
Expand Up @@ -4064,22 +4064,28 @@ unittest {
import std.file;
import std.datetime.stopwatch;

auto root = multilineInput();
auto input = multilineInput(
.layout!"fill",
);
auto root = vscrollFrame(
.layout!"fill",
input
);
auto io = new HeadlessBackend;

// Prepare
root.io = io;
io.clipboard = readText(__FILE__);
root.draw();

// Paste the text
input.focus();
io.nextFrame();

const runCount = 10;

// Paste the text
auto result = benchmark!({
root.value = "";
root.paste();
input.value = "";
input.paste();
root.draw();
})(runCount);

Expand Down

0 comments on commit 2051081

Please sign in to comment.