Skip to content

Commit

Permalink
GridView fixed size position to top left
Browse files Browse the repository at this point in the history
- Port changes for tview to not position fixed
  size items into bottom right if item in
  question is last one.
- Fixes #1010
  • Loading branch information
jvalkeal committed Apr 15, 2024
1 parent 544601c commit 054db76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -525,20 +525,6 @@ else if (column == 0) {
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -68,6 +68,24 @@ void borderMakesItemSmaller() {
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();
Expand Down

0 comments on commit 054db76

Please sign in to comment.