From e0529caee0922d37bffa4a5da2b38bc54055b897 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sun, 2 Feb 2025 18:21:15 -0800 Subject: [PATCH] Beefy 2D updates --- BeefLibs/Beefy2D/src/geom/Rect.bf | 1 + .../Beefy2D/src/theme/dark/DarkTooltip.bf | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/BeefLibs/Beefy2D/src/geom/Rect.bf b/BeefLibs/Beefy2D/src/geom/Rect.bf index 61997792..b14504f1 100644 --- a/BeefLibs/Beefy2D/src/geom/Rect.bf +++ b/BeefLibs/Beefy2D/src/geom/Rect.bf @@ -262,6 +262,7 @@ namespace Beefy.geom } } + typealias RectI32 = Rect; typealias Rect = Rect; typealias RectD = Rect; } diff --git a/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf b/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf index 131457ce..3fe64668 100644 --- a/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf +++ b/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf @@ -96,6 +96,21 @@ namespace Beefy.theme.dark Detach(); } + public static Point CalcSize(StringView text, float x = 0, float y = 0) + { + var font = DarkTheme.sDarkTheme.mSmallFont; + float minWidth = 0; + float minHeight = 0; + + BFApp.sApp.GetWorkspaceRectFrom((.)x, (.)y, 0, 0, var workspaceX, var workspaceY, var workspaceWidth, var workspaceHeight); + + FontMetrics fontMetrics = .(); + float height = font.Draw(null, text, x, y, 0, 0, FontOverflowMode.Overflow, &fontMetrics); + float tooltipWidth = Math.Max(fontMetrics.mMaxWidth + GS!(32), minWidth); + float tooltipHeight = Math.Clamp(height + GS!(16), minHeight, workspaceHeight); + return .(tooltipWidth, tooltipHeight); + } + void Attach(Widget widget) { if (mRelWidget != null) @@ -251,12 +266,15 @@ namespace Beefy.theme.dark if (mAllowMouseOutside) return; + Rect widgetRect = .(0, 0, mRelWidget.mWidth, mRelWidget.mHeight); + mRelWidgetMouseInsets?.ApplyTo(ref widgetRect); + float rootX; float rootY; - mRelWidget.SelfToRootTranslate(0, 0, out rootX, out rootY); + mRelWidget.SelfToRootTranslate(widgetRect.mX, widgetRect.mY, out rootX, out rootY); - Rect checkRect = Rect(rootX, rootY, mRelWidget.mWidth, mRelWidget.mHeight); - mRelWidgetMouseInsets?.ApplyTo(ref checkRect); + Rect checkRect = Rect(rootX, rootY, widgetRect.mWidth, widgetRect.mHeight); + if ((mRelWidget.mWidgetWindow != null) && (mRelWidget.mWidgetWindow.mHasMouseInside)) { if (checkRect.Contains(mRelWidget.mWidgetWindow.mClientMouseX, mRelWidget.mWidgetWindow.mClientMouseY)) @@ -444,15 +462,6 @@ namespace Beefy.theme.dark SetLastMouseWidget(null); sMouseStillTicks = -1; } - - if (numOverWidgets > 1) - { - //int a = 0; - Debug.WriteLine("numOverWidgets > 1"); - } - - - //Debug.Assert(numOverWidgets <= 1); } } }