Make the map sidebar a resizable island

Long palette names were cut off by the sidebar's fixed width. The
sidebar is now a rounded island set apart from the window edges, and
dragging the gap beside it makes it wider or narrower.

Model used: Claude Opus 5.5
This commit is contained in:
piexel
2026-10-19 18:19:35 +02:00
parent bfeb017037
commit 38b340ac14
2 changed files with 78 additions and 4 deletions
@@ -0,0 +1,60 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.gui;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;
/**
* A rounded panel set apart from the window edges, like the tool windows of IntelliJ's islands theme. Its right edge
* meets a split pane divider, which provides the gap there.
*/
final class IslandPanel extends JPanel {
private static final long serialVersionUID = 7313084027614358519L;
private static final int GAP = 6;
private static final int CORNER_ARC = 12;
private static final int INNER_PADDING = 4;
IslandPanel(JComponent content) {
super(new BorderLayout());
setOpaque(false);
setBorder(StudioTheme.emptyBorder(GAP + INNER_PADDING, GAP + INNER_PADDING, GAP + INNER_PADDING, INNER_PADDING));
add(content, BorderLayout.CENTER);
}
@Override
protected void paintComponent(Graphics graphics) {
Graphics2D canvas = (Graphics2D) graphics.create();
try {
canvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
canvas.setColor(StudioTheme.PANEL_BACKGROUND);
int gap = StudioTheme.scale(GAP);
int arc = StudioTheme.scale(CORNER_ARC);
canvas.fill(new RoundRectangle2D.Double(gap, gap, getWidth() - gap, getHeight() - gap * 2D, arc, arc));
} finally {
canvas.dispose();
}
}
}
@@ -53,6 +53,9 @@ public final class MapWindow implements MapCanvas.Listener {
private static final String MAP_CARD = "map";
private static final String PALETTES_CARD = "palettes";
private static final int SIDEBAR_WIDTH = 270;
private static final int SIDEBAR_MINIMUM_WIDTH = 200;
private static final int CONTENT_MINIMUM_WIDTH = 320;
private static final int SIDEBAR_DIVIDER_WIDTH = 6;
private static final double PALETTE_RECENTER_DISTANCE_BLOCKS = 1D;
private static final double VIEW_LIST_SHARE_WITH_PALETTES = 0.34D;
@@ -110,14 +113,11 @@ public final class MapWindow implements MapCanvas.Listener {
private void buildFrame() {
content.add(canvas, MAP_CARD);
statusBars.add(canvas.statusBar(), MAP_CARD);
sidebar.setPreferredSize(StudioTheme.scaledSize(SIDEBAR_WIDTH, 0));
sidebar.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, StudioTheme.SEPARATOR));
sidebar.add(viewListScroll, BorderLayout.CENTER);
frame.setLayout(new BorderLayout());
frame.add(buildToolbar(), BorderLayout.NORTH);
frame.add(sidebar, BorderLayout.WEST);
frame.add(content, BorderLayout.CENTER);
frame.add(buildSidebarSplit(), BorderLayout.CENTER);
frame.add(inspectorSlot, BorderLayout.EAST);
frame.add(statusBars, BorderLayout.SOUTH);
installShortcuts(frame.getRootPane());
@@ -226,6 +226,20 @@ public final class MapWindow implements MapCanvas.Listener {
}
}
// Dragging the gap beside the sidebar island makes it wider, so long palette names fit.
private JSplitPane buildSidebarSplit() {
IslandPanel island = new IslandPanel(sidebar);
island.setMinimumSize(StudioTheme.scaledSize(SIDEBAR_MINIMUM_WIDTH, 0));
content.setMinimumSize(StudioTheme.scaledSize(CONTENT_MINIMUM_WIDTH, 0));
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, island, content);
split.setBorder(BorderFactory.createEmptyBorder());
split.setBackground(StudioTheme.EDITOR_BACKGROUND);
split.setDividerSize(StudioTheme.scale(SIDEBAR_DIVIDER_WIDTH));
split.setResizeWeight(0D);
split.setDividerLocation(StudioTheme.scale(SIDEBAR_WIDTH));
return split;
}
// The palettes need the room more than the view list, which scrolls once it is squeezed.
private int viewListHeightBesidePalettes() {
int fullHeight = viewList.getPreferredSize().height + 4;