Don't fail writing text outside screen

- Adding np check not to try using item outside of a screen
- This fix essentially discards text write beyond screen bounds
- Fixes #993
This commit is contained in:
Janne Valkealahti
2024-01-29 09:42:57 +00:00
parent 9830fafe1a
commit 3d52f174af
2 changed files with 29 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -300,12 +300,14 @@ public class DefaultScreen implements Screen, DisplayLines {
for (int i = 0; i < text.length() && i < columns; i++) {
char c = text.charAt(i);
DefaultScreenItem item = layer.getScreenItem(x + i, y);
item.content = Character.toString(c);
if (color > -1) {
item.foreground = color;
}
if (style > -1) {
item.style = style;
if (item != null) {
item.content = Character.toString(c);
if (color > -1) {
item.foreground = color;
}
if (style > -1) {
item.style = style;
}
}
}
}