mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-09-11 11:45:27 +02:00
Persist table layouts just after changing the real used sizes and show truncated cell tooltips in the whole applications tables v2
This commit is contained in:
@@ -22,8 +22,8 @@ import java.util.OptionalDouble;
|
||||
*/
|
||||
public final class TableLayoutManager {
|
||||
|
||||
private static final double CELL_HORIZONTAL_PADDING = 28.0;
|
||||
private static final double DEFAULT_MINIMUM_WIDTH = 42.0;
|
||||
private static final double CELL_HORIZONTAL_PADDING = 16.0;
|
||||
private static final double DEFAULT_MINIMUM_WIDTH = 24.0;
|
||||
|
||||
private TableLayoutManager() {
|
||||
}
|
||||
@@ -139,7 +139,11 @@ public final class TableLayoutManager {
|
||||
measure(String.valueOf(value.getValue()), measurement)
|
||||
);
|
||||
}
|
||||
return clamp(requiredWidth + CELL_HORIZONTAL_PADDING, spec.minimumWidth, spec.maximumInitialWidth);
|
||||
return calculateInitialContentWidth(
|
||||
requiredWidth,
|
||||
spec.minimumWidth,
|
||||
spec.maximumInitialWidth
|
||||
);
|
||||
}
|
||||
|
||||
private static <S> double flexibleInitialWidth(TableView<S> table, ColumnSpec spec) {
|
||||
@@ -223,6 +227,18 @@ public final class TableLayoutManager {
|
||||
return Math.max(minimum, Math.min(value, maximum));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a compact content width. Package-private for focused sizing tests.
|
||||
*/
|
||||
@SuppressWarnings("PMD.CommentDefaultAccessModifier")
|
||||
static double calculateInitialContentWidth(
|
||||
final double measuredWidth,
|
||||
final double minimum,
|
||||
final double maximum
|
||||
) {
|
||||
return clamp(measuredWidth + CELL_HORIZONTAL_PADDING, minimum, maximum);
|
||||
}
|
||||
|
||||
public static final class ColumnSpec {
|
||||
private final String id;
|
||||
private final TableColumn<?, String> column;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package kst4contest.view;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TableLayoutManagerTest {
|
||||
|
||||
@Test
|
||||
void contentWidthUsesCompactPadding() {
|
||||
assertEquals(116.0, TableLayoutManager.calculateInitialContentWidth(100.0, 24.0, 200.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void contentWidthStillHonorsMinimumAndMaximum() {
|
||||
assertEquals(24.0, TableLayoutManager.calculateInitialContentWidth(0.0, 24.0, 200.0));
|
||||
assertEquals(200.0, TableLayoutManager.calculateInitialContentWidth(250.0, 24.0, 200.0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user