Made Hover Info resizable via handle at bottom right

This commit is contained in:
bigguy345 committed 2026-03-05 01:17:22 +02:00
1 parent bee84a622c
commit c537a09ad1
3 files changed
+129 -23

No files matched your search

@@ -65,6 +65,16 @@ public class HoverState {
private boolean tooltipPositionOverridden;
private int overriddenTooltipX, overriddenTooltipY;
/** Tooltip panel resize state */
private boolean isResizingTooltip;
private int resizeInitMouseX, resizeInitMouseY;
private int resizeInitW, resizeInitH;
private boolean tooltipSizeOverridden;
private int overriddenTooltipW, overriddenTooltipH;
/** Minimum tooltip dimensions when user-resized */
private static final int MIN_TOOLTIP_W = 80;
private static final int MIN_TOOLTIP_H = 30;
/** Smooth scroll: target offset (pixels), current is animated toward it each frame */
private float targetScrollOffset;
/** Vertical scroll offset for tooltip content (pixels) */
@@ -233,6 +243,8 @@ public class HoverState {
isDraggingScrollbar = false;
isDraggingTooltip = false;
tooltipPositionOverridden = false;
isResizingTooltip = false;
tooltipSizeOverridden = false;
tooltipScrollOffsetF = 0;
targetScrollOffset = 0;
tooltipMaxScroll = 0;
@@ -451,6 +463,43 @@ public class HoverState {
public int getOverriddenTooltipX() { return overriddenTooltipX; }
public int getOverriddenTooltipY() { return overriddenTooltipY; }
// ==================== TOOLTIP PANEL RESIZE ====================
/** Returns true when the mouse is over the resize handle (bottom-right corner). */
public boolean isMouseOverResizeHandle(int mx, int my) {
if (!tooltipVisible || tooltipPanelW <= 0) return false;
int rx = tooltipPanelX + tooltipPanelW - 8;
int ry = tooltipPanelY + tooltipPanelH - 8;
return mx >= rx && mx <= tooltipPanelX + tooltipPanelW
&& my >= ry && my <= tooltipPanelY + tooltipPanelH;
}
/** Begin resizing; captures current panel dimensions as the baseline. */
public void startTooltipResize(int mouseX, int mouseY) {
isResizingTooltip = true;
resizeInitMouseX = mouseX;
resizeInitMouseY = mouseY;
resizeInitW = tooltipSizeOverridden ? overriddenTooltipW : tooltipPanelW;
resizeInitH = tooltipSizeOverridden ? overriddenTooltipH : tooltipPanelH;
}
/** Called every frame while M1 is held to resize the tooltip panel. */
public void updateTooltipResize(int mouseX, int mouseY) {
if (!isResizingTooltip) return;
overriddenTooltipW = Math.max(MIN_TOOLTIP_W, resizeInitW + (mouseX - resizeInitMouseX));
overriddenTooltipH = Math.max(MIN_TOOLTIP_H, resizeInitH + (mouseY - resizeInitMouseY));
tooltipSizeOverridden = true;
}
public void releaseTooltipResize() {
isResizingTooltip = false;
}
public boolean isResizingTooltip() { return isResizingTooltip; }
public boolean hasOverriddenSize() { return tooltipSizeOverridden; }
public int getOverriddenTooltipW() { return overriddenTooltipW; }
public int getOverriddenTooltipH() { return overriddenTooltipH; }
public boolean isDraggingScrollbar() {
return isDraggingScrollbar;
}
@@ -109,6 +109,21 @@ public class TokenHoverRenderer {
// Box dimensions — use visibleContentHeight so positioning matches rendering
int boxWidth = contentWidth + PADDING * 2;
int boxHeight = visibleContentHeight + PADDING * 2;
// Apply user size override when the panel has been resized
if (hoverState.hasOverriddenSize()) {
int overW = Math.max(MIN_WIDTH + PADDING * 2, hoverState.getOverriddenTooltipW());
int overH = Math.max(lineHeight + PADDING * 2, hoverState.getOverriddenTooltipH());
boxWidth = overW;
visibleContentHeight = overH - PADDING * 2;
boxHeight = overH;
// Re-measure with new wrap width so scrollbar detection is accurate
int newContentW = boxWidth - PADDING * 2;
totalContentHeight = calculateContentHeight(info, newContentW);
if (totalContentHeight > visibleContentHeight) {
totalContentHeight = calculateContentHeight(info, newContentW - 6);
}
}
// Position the tooltip — use dragged position if user has panned the panel
int tooltipX = hoverState.hasOverriddenPosition() ? hoverState.getOverriddenTooltipX() : tokenX;
@@ -341,7 +356,7 @@ public class TokenHoverRenderer {
if (hasScrollbar) {
int scrollbarX = x + boxWidth - PADDING;
int scrollbarTrackTop = y + PADDING;
int scrollbarTrackHeight = visibleContentHeight;
int scrollbarTrackHeight = visibleContentHeight - 4; // leave room for resize handle
// Track
Gui.drawRect(scrollbarX, scrollbarTrackTop, scrollbarX + 3,
scrollbarTrackTop + scrollbarTrackHeight, 0x40888888);
@@ -349,9 +364,12 @@ public class TokenHoverRenderer {
float scrollRatio = (float) visibleContentHeight / totalContentHeight;
int thumbHeight = Math.max(6, (int)(scrollbarTrackHeight * scrollRatio));
int effectiveMaxScroll = totalContentHeight - visibleContentHeight;
// Clamp scrollProgress to [0,1] — guards against stale offset after resize shrinks content
float scrollProgress = effectiveMaxScroll > 0
? (float) hoverState.getTooltipScrollOffset() / effectiveMaxScroll : 0f;
? Math.min(1f, (float) hoverState.getTooltipScrollOffset() / effectiveMaxScroll) : 0f;
int thumbY = scrollbarTrackTop + (int)((scrollbarTrackHeight - thumbHeight) * scrollProgress);
// Clamp thumb within track bounds defensively
thumbY = Math.max(scrollbarTrackTop, Math.min(scrollbarTrackTop + scrollbarTrackHeight - thumbHeight, thumbY));
// Store thumb bounds in HoverState for drag/hover detection
hoverState.setScrollbarThumb(scrollbarX, thumbY, thumbHeight, scrollbarTrackTop, scrollbarTrackHeight);
// Highlight thumb when hovered or dragging (darker = active, like AutocompleteMenu)
@@ -362,6 +380,24 @@ public class TokenHoverRenderer {
int thumbColor = thumbActive ? 0xFFCCCCCC : 0xFF808080;
Gui.drawRect(scrollbarX, thumbY, scrollbarX + 3, thumbY + thumbHeight, thumbColor);
}
// Draw resize handle at bottom-right corner (outside scissor, same as scrollbar)
{
int mouseX = hoverState.getLastMouseX();
int mouseY = hoverState.getLastMouseY();
boolean resizeActive = hoverState.isResizingTooltip()
|| hoverState.isMouseOverResizeHandle(mouseX, mouseY);
int dotColor = resizeActive ? 0xFFCCCCCC : 0x80888888;
int rhX = x + boxWidth - 2;
int rhY = y + boxHeight - 2;
// Three-dot diagonal pattern (◢)
Gui.drawRect(rhX - 1, rhY - 1, rhX, rhY, dotColor);
Gui.drawRect(rhX - 3, rhY - 1, rhX - 2, rhY, dotColor);
Gui.drawRect(rhX - 1, rhY - 3, rhX, rhY - 2, dotColor);
Gui.drawRect(rhX - 5, rhY - 1, rhX - 4, rhY, dotColor);
Gui.drawRect(rhX - 3, rhY - 3, rhX - 2, rhY - 2, dotColor);
Gui.drawRect(rhX - 1, rhY - 5, rhX, rhY - 4, dotColor);
}
}
/**