Refine editor window host structure and utility chrome
This commit is contained in:
@@ -38,6 +38,20 @@ bool IsVerboseResizeTraceEnabled() {
|
||||
return s_enabled;
|
||||
}
|
||||
|
||||
bool IsChromeButtonTarget(Host::BorderlessWindowChromeHitTarget target) {
|
||||
return target == Host::BorderlessWindowChromeHitTarget::PinButton ||
|
||||
target == Host::BorderlessWindowChromeHitTarget::MinimizeButton ||
|
||||
target == Host::BorderlessWindowChromeHitTarget::MaximizeRestoreButton ||
|
||||
target == Host::BorderlessWindowChromeHitTarget::CloseButton;
|
||||
}
|
||||
|
||||
float ResolveLeadingChromeButtonLeft(
|
||||
const Host::BorderlessWindowChromeLayout& layout) {
|
||||
return layout.pinButtonRect.width > 0.0f
|
||||
? layout.pinButtonRect.x
|
||||
: layout.minimizeButtonRect.x;
|
||||
}
|
||||
|
||||
float ResolveDetachedTabWidth(
|
||||
std::string_view text,
|
||||
const UIEditorTextMeasurer* textMeasurer) {
|
||||
@@ -54,7 +68,7 @@ float ResolveDetachedTabWidth(
|
||||
|
||||
UIRect BuildDetachedTitleLogoRect(const Host::BorderlessWindowChromeLayout& layout) {
|
||||
const float availableLeft = layout.titleBarRect.x;
|
||||
const float availableRight = layout.minimizeButtonRect.x;
|
||||
const float availableRight = ResolveLeadingChromeButtonLeft(layout);
|
||||
const float centeredX = std::floor(
|
||||
layout.titleBarRect.x + layout.titleBarRect.width * 0.5f - kTitleBarLogoExtent * 0.5f);
|
||||
const float clampedX = (std::max)(
|
||||
@@ -227,6 +241,15 @@ const Host::BorderlessWindowChromeState& EditorWindowChromeController::GetChrome
|
||||
return m_chromeState;
|
||||
}
|
||||
|
||||
void EditorWindowChromeController::InitializeWindowChrome(EditorWindow& window) {
|
||||
if (!window.GetChromePolicy().topmostByDefault) {
|
||||
SetWindowTopmost(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyWindowTopmost(window, true);
|
||||
}
|
||||
|
||||
bool EditorWindowChromeController::HandleSystemCommand(
|
||||
EditorWindow& window,
|
||||
EditorContext& editorContext,
|
||||
@@ -463,10 +486,7 @@ bool EditorWindowChromeController::UpdateChromeHover(EditorWindow& window, LPARA
|
||||
}
|
||||
|
||||
const Host::BorderlessWindowChromeHitTarget hitTarget = HitTestChrome(window, lParam);
|
||||
const Host::BorderlessWindowChromeHitTarget buttonTarget =
|
||||
hitTarget == Host::BorderlessWindowChromeHitTarget::MinimizeButton ||
|
||||
hitTarget == Host::BorderlessWindowChromeHitTarget::MaximizeRestoreButton ||
|
||||
hitTarget == Host::BorderlessWindowChromeHitTarget::CloseButton
|
||||
const Host::BorderlessWindowChromeHitTarget buttonTarget = IsChromeButtonTarget(hitTarget)
|
||||
? hitTarget
|
||||
: Host::BorderlessWindowChromeHitTarget::None;
|
||||
if (GetHoveredChromeTarget() == buttonTarget) {
|
||||
@@ -486,6 +506,7 @@ bool EditorWindowChromeController::HandleChromeButtonDown(EditorWindow& window,
|
||||
const HWND hwnd = window.GetHwnd();
|
||||
const Host::BorderlessWindowChromeHitTarget hitTarget = HitTestChrome(window, lParam);
|
||||
switch (hitTarget) {
|
||||
case Host::BorderlessWindowChromeHitTarget::PinButton:
|
||||
case Host::BorderlessWindowChromeHitTarget::MinimizeButton:
|
||||
case Host::BorderlessWindowChromeHitTarget::MaximizeRestoreButton:
|
||||
case Host::BorderlessWindowChromeHitTarget::CloseButton:
|
||||
@@ -525,9 +546,7 @@ bool EditorWindowChromeController::HandleChromeButtonUp(
|
||||
}
|
||||
|
||||
const Host::BorderlessWindowChromeHitTarget pressedTarget = GetPressedChromeTarget();
|
||||
if (pressedTarget != Host::BorderlessWindowChromeHitTarget::MinimizeButton &&
|
||||
pressedTarget != Host::BorderlessWindowChromeHitTarget::MaximizeRestoreButton &&
|
||||
pressedTarget != Host::BorderlessWindowChromeHitTarget::CloseButton) {
|
||||
if (!IsChromeButtonTarget(pressedTarget)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -692,7 +711,8 @@ Host::BorderlessWindowChromeLayout EditorWindowChromeController::ResolveChromeLa
|
||||
|
||||
return Host::BuildBorderlessWindowChromeLayout(
|
||||
UIRect(0.0f, 0.0f, clientWidthDips, kBorderlessTitleBarHeightDips),
|
||||
leadingOccupiedRight);
|
||||
leadingOccupiedRight,
|
||||
window.GetChromePolicy().showTopmostButton);
|
||||
}
|
||||
|
||||
bool EditorWindowChromeController::ShouldUseDetachedTitleBarTabStrip(
|
||||
@@ -828,7 +848,8 @@ void EditorWindowChromeController::AppendChrome(
|
||||
drawList,
|
||||
layout,
|
||||
GetChromeState(),
|
||||
IsBorderlessWindowMaximized());
|
||||
IsBorderlessWindowMaximized(),
|
||||
IsWindowTopmost());
|
||||
}
|
||||
|
||||
void EditorWindowChromeController::ApplyResizeCursorHoverPriority() {
|
||||
@@ -907,6 +928,35 @@ bool EditorWindowChromeController::ApplyPredictedWindowRectTransition(
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorWindowChromeController::SetWindowTopmost(bool topmost) {
|
||||
m_runtimeState.SetWindowTopmost(topmost);
|
||||
}
|
||||
|
||||
bool EditorWindowChromeController::IsWindowTopmost() const {
|
||||
return m_runtimeState.IsWindowTopmost();
|
||||
}
|
||||
|
||||
bool EditorWindowChromeController::ApplyWindowTopmost(EditorWindow& window, bool topmost) {
|
||||
const HWND hwnd = window.GetHwnd();
|
||||
if (hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetWindowPos(
|
||||
hwnd,
|
||||
topmost ? HWND_TOPMOST : HWND_NOTOPMOST,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SetWindowTopmost(topmost);
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorWindowChromeController::ToggleMaximizeRestore(
|
||||
EditorWindow& window,
|
||||
EditorContext& editorContext,
|
||||
@@ -949,6 +999,9 @@ void EditorWindowChromeController::ExecuteChromeAction(
|
||||
}
|
||||
|
||||
switch (target) {
|
||||
case Host::BorderlessWindowChromeHitTarget::PinButton:
|
||||
ApplyWindowTopmost(window, !IsWindowTopmost());
|
||||
break;
|
||||
case Host::BorderlessWindowChromeHitTarget::MinimizeButton:
|
||||
ShowWindow(hwnd, SW_MINIMIZE);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user