Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI
fix(tkinter): keep geometry round trip stable on hidpi and macos
Krish Kalaria9a4c821c577a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 555e888..f3e5765 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -204,6 +204,7 @@ The newest work. Details for some items follow in the sections below.- **Python, hidden Tk root:** BUI's hidden Tk root (started before the first window on macOS, and by the Tk host) became `tkinter._default_root`, so a real tkinter program's `StringVar()` bound to the hidden interpreter and its widgets never saw the value.- **tkinter on HiDPI:** a window fitting its content (and `simpledialog` windows) was scaled twice, so it came out twice too large on Retina displays and other scaled screens.- **tkinter on macOS:** `Menu` defaults to `tearoff=0`, like Tk on Aqua.+- **`geometry()` round trip:** `root.geometry(root.geometry())` doubled the window on Retina displays and other scaled screens, and on macOS moved it down by the title bar. The getter now reports logical pixels, and on macOS `wm("pos")` sets the content's position, the one `wm_get("pos")` reports.### Changed- **Text looks like Blender's:** Inter, Blender's UI font, is embedded and is the default face on every platform. The portable stb_truetype engine is now the default on Windows too. `-DBUI_TEXT_GDI=ON` (Rust: the `gdi-text` feature) restores GDI and system fonts. `BUI_TEXT_STB` and `portable-text` are now no-ops.diff --git a/bindings/python/bui/tksyntax/_core.py b/bindings/python/bui/tksyntax/_core.pyindex bf6a910..be61713 100644--- a/bindings/python/bui/tksyntax/_core.py+++ b/bindings/python/bui/tksyntax/_core.py@@ -2025,9 +2025,10 @@ class Wm:def wm_geometry(self, newGeometry=None):"""'WxH+X+Y' (any part optional); without an argument, the current."""if newGeometry is None:+ scale = buipy.kit_scale()w, h = self._window.sizepos = self._window.wm_get("pos") or (0, 0)- return "%dx%d+%d+%d" % (w, h, pos[0], pos[1])+ return "%dx%d+%d+%d" % (round(w / scale), round(h / scale), pos[0], pos[1])m = re.match(r"^\s*(?:(\d+)x(\d+))?\s*(?:([+-]-?\d+)([+-]-?\d+))?\s*$",str(newGeometry))if not m:diff --git a/bindings/python/tests/test_tk_compat.py b/bindings/python/tests/test_tk_compat.pyindex 844b563..d45318d 100644--- a/bindings/python/tests/test_tk_compat.py+++ b/bindings/python/tests/test_tk_compat.py@@ -559,6 +559,7 @@ def test_hidden_root_is_not_default_root():_FIT_AT_SCALE = """+import sysimport bui, buipyfrom bui import hostfrom bui.tksyntax import Label, Listbox, Tk, Toplevel, simpledialog@@ -575,6 +576,15 @@ if host.native_available():need, got = win._node.natural(), win._window.sizeassert 0 <= got[0] - need[0] <= 1 and 0 <= got[1] - need[1] <= 1, (need, got)assert buipy.kit_scale() == 2.0+ # geometry() round trips (the position: macOS so far; Win32 and X11 still set the+ # frame's and report the content's)+ before = root.geometry()+ root.geometry(before)+ root.update()+ after = root.geometry()+ if sys.platform != "darwin":+ before, after = before.split("+")[0], after.split("+")[0]+ assert after == before, (before, after)root.destroy()"""diff --git a/kit/intern/kit_window_cocoa.m b/kit/intern/kit_window_cocoa.mindex 72d2c95..cae873b 100644--- a/kit/intern/kit_window_cocoa.m+++ b/kit/intern/kit_window_cocoa.m@@ -1519,8 +1519,10 @@ void BK_window_wm(BKWindow *win, const char *key, double a, double b)return;}@autoreleasepool {- if (!strcmp(key, "pos")) {- [nw setFrameTopLeftPoint:NSMakePoint(a, primary_height() - b)];+ if (!strcmp(key, "pos")) { /* the content's top-left, as wm_get reports it */+ const NSRect f = [nw frame];+ const CGFloat title = NSMaxY(f) - NSMaxY([nw contentRectForFrameRect:f]);+ [nw setFrameTopLeftPoint:NSMakePoint(a, primary_height() - b + title)];}else if (!strcmp(key, "minsize") || !strcmp(key, "maxsize")) {const int mini = key[1] == 'i';