From 054db7651ffd1a2b2908f7c4395c2e7eeee11d23 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Mon, 15 Apr 2024 08:59:15 +0100 Subject: [PATCH] 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 --- .../component/view/control/GridView.java | 16 +-------------- .../component/view/control/GridViewTests.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/GridView.java b/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/GridView.java index 5857ef1bb..3d9f2b55a 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/GridView.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/GridView.java @@ -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 @@ 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) { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java index 2c10a8f47..455be78bb 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java @@ -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 @@ 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();