Skip to content

Commit 054db76

Browse files
committed
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
1 parent 544601c commit 054db76

File tree

2 files changed

+20
-16
lines changed
  • spring-shell-core/src

2 files changed

+20
-16
lines changed

spring-shell-core/src/main/java/org/springframework/shell/component/view/control/GridView.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 the original author or authors.
2+
* Copyright 2023-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -525,20 +525,6 @@ else if (column == 0) {
525525
offsetX += width2 + add;
526526
}
527527

528-
// Line up the last row/column with the end of the available area.
529-
int border = 0;
530-
if (isShowBorders()) {
531-
border = 1;
532-
}
533-
int last = rowPos.length - 1;
534-
if (rowPos[last] + rowHeight[last] + border - offsetY < height) {
535-
offsetY = rowPos[last] - height + rowHeight[last] + border;
536-
}
537-
last = columnPos.length - 1;
538-
if (columnPos[last] + columnWidth[last] + border - offsetX < width) {
539-
offsetX = columnPos[last] - width + columnWidth[last] + border;
540-
}
541-
542528
// The focused item must be within the visible area.
543529
if (focus != null) {
544530
if (focus.y + focus.h - offsetY >= height) {

spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 the original author or authors.
2+
* Copyright 2023-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,6 +68,24 @@ void borderMakesItemSmaller() {
6868
verify(sbox1).setRect(1, 1, 78, 22);
6969
}
7070

71+
@Test
72+
void positionsWith1x1FixedSizeGoTopLeft() {
73+
BoxView box1 = new BoxView();
74+
BoxView sbox1 = spy(box1);
75+
GridView grid = new GridView();
76+
77+
grid.setShowBorders(false);
78+
grid.setRowSize(1);
79+
grid.setColumnSize(1);
80+
grid.setShowBorder(false);
81+
grid.addItem(sbox1, 0, 0, 1, 1, 0, 0);
82+
83+
grid.setRect(0, 0, 80, 24);
84+
grid.draw(screen24x80);
85+
86+
verify(sbox1).setRect(0, 0, 1, 1);
87+
}
88+
7189
@Test
7290
void positionsWith1x2() {
7391
BoxView box1 = new BoxView();

0 commit comments

Comments
 (0)