|
|
@@ -7,51 +7,46 @@
|
|
|
|
|
|
namespace sunrise::server::ui::activity_host::tool_window {
|
|
|
|
|
|
-/** The transparent parent moves and resizes while the card owns content scrolling. */
|
|
|
+/** A titled window that moves, resizes and scrolls its own content. */
|
|
|
constexpr ImGuiWindowFlags kWindowFlags =
|
|
|
- ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings
|
|
|
- | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
|
|
|
+ ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings;
|
|
|
|
|
|
-/** Applies a bounded content size and a first-use position. */
|
|
|
-inline void set_next(const ImVec2& authoredPosition, const ImVec2& authoredSize) noexcept {
|
|
|
+/** Applies bounded size constraints and a centered first-use size given as work-area fractions. */
|
|
|
+inline void set_next(const ImVec2& workFraction) noexcept {
|
|
|
namespace scaling = core::ui::scaling::dpi;
|
|
|
- ImVec2 size = scaling::pixels(authoredSize);
|
|
|
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
|
|
if (viewport == nullptr) {
|
|
|
- ImGui::SetNextWindowSize(size, ImGuiCond_FirstUseEver);
|
|
|
return;
|
|
|
}
|
|
|
const float margin = scaling::pixels(16.0F);
|
|
|
const ImVec2 maximum{(std::max)(viewport->WorkSize.x - (margin * 2.0F), 1.0F),
|
|
|
(std::max)(viewport->WorkSize.y - (margin * 2.0F), 1.0F)};
|
|
|
- size.x = (std::min)(size.x, maximum.x);
|
|
|
- size.y = (std::min)(size.y, maximum.y);
|
|
|
const ImVec2 requestedMinimum = scaling::pixels({320.0F, 120.0F});
|
|
|
const ImVec2 minimum{(std::min)(requestedMinimum.x, maximum.x),
|
|
|
(std::min)(requestedMinimum.y, maximum.y)};
|
|
|
+ const ImVec2 size{std::clamp(viewport->WorkSize.x * workFraction.x, minimum.x, maximum.x),
|
|
|
+ std::clamp(viewport->WorkSize.y * workFraction.y, minimum.y, maximum.y)};
|
|
|
ImGui::SetNextWindowSizeConstraints(minimum, maximum);
|
|
|
ImGui::SetNextWindowSize(size, ImGuiCond_FirstUseEver);
|
|
|
-
|
|
|
- const ImVec2 requested = scaling::pixels(authoredPosition);
|
|
|
- const ImVec2 available{(std::max)(viewport->WorkSize.x - size.x, 0.0F),
|
|
|
- (std::max)(viewport->WorkSize.y - size.y, 0.0F)};
|
|
|
- const ImVec2 position{viewport->WorkPos.x + std::clamp(requested.x, 0.0F, available.x),
|
|
|
- viewport->WorkPos.y + std::clamp(requested.y, 0.0F, available.y)};
|
|
|
- ImGui::SetNextWindowPos(position, ImGuiCond_FirstUseEver);
|
|
|
+ ImGui::SetNextWindowPos(viewport->GetWorkCenter(), ImGuiCond_FirstUseEver, {0.5F, 0.5F});
|
|
|
}
|
|
|
|
|
|
-/** Begins a transparent movable parent whose entire visible surface is the child card. */
|
|
|
-[[nodiscard]] inline bool begin(const char* id,
|
|
|
- bool& open,
|
|
|
- const ImVec2& authoredPosition,
|
|
|
- const ImVec2& authoredSize) noexcept {
|
|
|
- set_next(authoredPosition, authoredSize);
|
|
|
- ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4{});
|
|
|
- ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0F);
|
|
|
- ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{});
|
|
|
+/** Begins a movable, resizable window whose title bar reads as a raised Sunrise panel. */
|
|
|
+[[nodiscard]] inline bool begin(const char* id, bool& open, const ImVec2& workFraction) noexcept {
|
|
|
+ namespace scaling = core::ui::scaling::dpi;
|
|
|
+ set_next(workFraction);
|
|
|
+ // Dear ImGui reads these only while Begin draws the frame, so the body keeps the theme.
|
|
|
+ // The same colour whether focused or not, so focus never lights the bar up.
|
|
|
+ const ImGuiStyle& style = ImGui::GetStyle();
|
|
|
+ const ImVec4 titleBackground = style.Colors[ImGuiCol_ChildBg];
|
|
|
+ ImGui::PushStyleColor(ImGuiCol_TitleBg, titleBackground);
|
|
|
+ ImGui::PushStyleColor(ImGuiCol_TitleBgActive, titleBackground);
|
|
|
+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
|
|
|
+ ImVec2{style.FramePadding.x, scaling::pixels(8.0F)});
|
|
|
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, style.WindowBorderSize);
|
|
|
const bool visible = ImGui::Begin(id, &open, kWindowFlags);
|
|
|
ImGui::PopStyleVar(2);
|
|
|
- ImGui::PopStyleColor();
|
|
|
+ ImGui::PopStyleColor(2);
|
|
|
return visible;
|
|
|
}
|
|
|
|