place the floating widgets in one ordered pass
The three widgets over the game world view each cached a rect handed to them by MainWindow's resize, then re-placed themselves from it. But the build button bar re-centers on a building unlock and the controls panel re-fits on a 50 ms timer, neither of which goes through MainWindow, so the rects the others held went stale -- and each widget re-implemented its own avoidance against them. They now implement FloatingPanel and are placed in one ordered pass: the bar takes what it wants, the controls panel steps around the bar, and the selection panel keeps clear of both. A widget that changed size or visibility publishes FloatingLayoutInvalidatedEvent instead of moving itself, because what it may take depends on the widgets placed before it. The rule they step around each other by is one function in lib, where it can be tested without a display -- the only way any of this geometry gets automated cover, screen capture of the world view being blank here. The selection panel keeps its right edge and its vertical centering, but the space it centers in is now what its own column has left free rather than the full-width strip the bar used to reserve. It therefore sits lower than before where the centered bar does not reach it, and it now clears the controls panel, which it previously ignored. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcReq7hVk4KUPhTDKWAG7K
This commit is contained in:
@@ -16,6 +16,7 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TunnelCompletion.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WorldCoordinates.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WorldCamera.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/FloatingPanelPlacement.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SelectionController.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildModeController.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ControlAction.h
|
||||
@@ -32,6 +33,7 @@ SET(SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TunnelCompletion.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WorldCoordinates.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WorldCamera.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/FloatingPanelPlacement.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SelectionController.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildModeController.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ControlAction.cpp
|
||||
|
||||
24
src/lib/core/FloatingPanelPlacement.cpp
Normal file
24
src/lib/core/FloatingPanelPlacement.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "FloatingPanelPlacement.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
int getAvailableBottomPx(const QRect& band, const std::vector<QRect>& occupiedRects,
|
||||
int leftPx, int rightPx, int marginPx)
|
||||
{
|
||||
int bottomPx = band.bottom();
|
||||
for (const QRect& occupied : occupiedRects)
|
||||
{
|
||||
if (occupied.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Only what is actually in the way counts: a widget entirely to one side of this
|
||||
// span is not below it, however tall it is.
|
||||
if (occupied.right() < leftPx || occupied.left() > rightPx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bottomPx = std::min(bottomPx, occupied.top() - marginPx - 1);
|
||||
}
|
||||
return bottomPx;
|
||||
}
|
||||
18
src/lib/core/FloatingPanelPlacement.h
Normal file
18
src/lib/core/FloatingPanelPlacement.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QRect>
|
||||
|
||||
// Geometry for the widgets floating over the game world view (REQ-UI-WORLD-SIZE). Their
|
||||
// owner places them in one ordered pass, each into the space the earlier ones left free,
|
||||
// and these are the rules they place themselves by. Pure geometry -- no widget is
|
||||
// involved, which is what lets the rules be tested without a display.
|
||||
|
||||
// The lowest bottom edge available to a widget occupying the horizontal span
|
||||
// [leftPx, rightPx] inside band: the band's own bottom, or marginPx above the topmost
|
||||
// occupied rectangle whose horizontal extent meets that span. A rectangle beside the
|
||||
// span is not in the way and does not shorten it (REQ-UI-SELECTION-PANEL,
|
||||
// REQ-UI-CONTROLS-PANEL). The result is inclusive, as QRect::bottom() is.
|
||||
int getAvailableBottomPx(const QRect& band, const std::vector<QRect>& occupiedRects,
|
||||
int leftPx, int rightPx, int marginPx);
|
||||
Reference in New Issue
Block a user