GridView fixed size position to top left

- Port changes for tview to not position fixed
  size items into bottom right if item in
  question is last one.
- Fixes #1010
This commit is contained in:
Janne Valkealahti
2024-04-15 08:59:15 +01:00
parent 544601c679
commit 054db7651f
2 changed files with 20 additions and 16 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.
@@ -525,20 +525,6 @@ public class GridView extends BoxView {
offsetX += width2 + add;
}
// Line up the last row/column with the end of the available area.
int border = 0;
if (isShowBorders()) {
border = 1;
}
int last = rowPos.length - 1;
if (rowPos[last] + rowHeight[last] + border - offsetY < height) {
offsetY = rowPos[last] - height + rowHeight[last] + border;
}
last = columnPos.length - 1;
if (columnPos[last] + columnWidth[last] + border - offsetX < width) {
offsetX = columnPos[last] - width + columnWidth[last] + border;
}
// The focused item must be within the visible area.
if (focus != null) {
if (focus.y + focus.h - offsetY >= height) {

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.
@@ -68,6 +68,24 @@ class GridViewTests extends AbstractViewTests {
verify(sbox1).setRect(1, 1, 78, 22);
}
@Test
void positionsWith1x1FixedSizeGoTopLeft() {
BoxView box1 = new BoxView();
BoxView sbox1 = spy(box1);
GridView grid = new GridView();
grid.setShowBorders(false);
grid.setRowSize(1);
grid.setColumnSize(1);
grid.setShowBorder(false);
grid.addItem(sbox1, 0, 0, 1, 1, 0, 0);
grid.setRect(0, 0, 80, 24);
grid.draw(screen24x80);
verify(sbox1).setRect(0, 0, 1, 1);
}
@Test
void positionsWith1x2() {
BoxView box1 = new BoxView();