Files
workinf_Blender_Wasm/tools/web/measure-outliner-desktop.py
mes123456 5ce5625f2e feat(web): workbench Outliner matches the desktop Layout geometry
The desktop golden comes from Blender's own laid-out screen data
(tools/web/measure-outliner-desktop.py, blender 5.2.0 LTS, factory
Layout at 1920x1080): right column 339 px, Outliner area 339x189 under
a 26 px header, 20 px rows, 14 px per-level indent (0.7 * UI_UNIT_X).
The workbench derives the right width and the Outliner/timeline split
from those ratios so it reproduces the area at the reference size and
scales elsewhere.

The headed suite grows outliner-metrics-web with +-1 px assertions,
and the runner now materializes inline base64 attachments so the
checker can compare the measured boxes against the golden.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-30 04:21:08 +08:00

103 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""Read the desktop Outliner geometry from Blender's own laid-out screen data.
blender --factory-startup --background \
--python tools/web/measure-outliner-desktop.py -- --out <abs json>
The factory Layout screen is the reference the web workbench mirrors. The rects
below come from the screen/region layout Blender itself produced (background mode
lays the startup screen out at the factory window size), never from hand-typed
numbers. Every value the web side must match is emitted verbatim:
* the OUTLINER area rect (the user asked for the same area size as desktop),
* its HEADER region height,
* the widget unit (`U.widget_unit`), which is the tree row height
(`UI_UNIT_Y` in interface code) at the factory dpi/scale,
* the per-level tree indent (0.7 * UI_UNIT_X, `UI_TREEVIEW_INDENT`).
"""
import json
import sys
import bpy
def _take(flag: str):
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
if flag in argv:
index = argv.index(flag)
if index + 1 < len(argv):
return argv[index + 1]
return None
OUT = _take("--out")
if not OUT:
raise SystemExit("measure-outliner-desktop: pass -- --out <absolute path>")
screen = bpy.data.screens.get("Layout")
if screen is None:
raise SystemExit("measure-outliner-desktop: the factory Layout screen is missing")
areas = []
for area in screen.areas:
areas.append({
"type": area.type,
"x": area.x,
"y": area.y,
"width": area.width,
"height": area.height,
"regions": [
{"type": region.type, "x": region.x, "y": region.y,
"width": region.width, "height": region.height}
for region in area.regions
],
})
outliner = next((area for area in areas if area["type"] == "OUTLINER"), None)
if outliner is None:
raise SystemExit("measure-outliner-desktop: the Layout screen has no OUTLINER area")
if outliner["width"] <= 0 or outliner["height"] <= 0:
raise SystemExit(f"measure-outliner-desktop: the OUTLINER rect is empty: {outliner}")
header = next((region for region in outliner["regions"] if region["type"] == "HEADER"), None)
if header is None or header["height"] <= 0:
raise SystemExit(f"measure-outliner-desktop: the OUTLINER area has no laid-out HEADER: {outliner}")
# `U.widget_unit` = round(UI_UNIT_X * ui_scale * dpi / 72); UI_UNIT_X is 20 at
# the factory scale. This is the value tree rows use as their height.
prefs = bpy.context.preferences
dpi = float(prefs.system.dpi)
ui_scale = float(prefs.view.ui_scale)
widget_unit = round(20.0 * ui_scale * dpi / 72.0)
metrics = {
"schemaVersion": 1,
"source": {
"binary": bpy.app.binary_path,
"version": bpy.app.version_string,
"factoryStartup": True,
"screen": "Layout",
},
"preferences": {"dpi": dpi, "uiScale": ui_scale, "widgetUnit": widget_unit},
"contentExtent": {
"width": max(area["x"] + area["width"] for area in areas),
"height": max(area["y"] + area["height"] for area in areas),
},
"areas": areas,
"outliner": {
"x": outliner["x"],
"y": outliner["y"],
"width": outliner["width"],
"height": outliner["height"],
"headerHeight": header["height"],
"rowHeight": widget_unit,
"indentPerLevel": round(0.7 * widget_unit),
},
}
with open(OUT, "w", encoding="utf-8") as handle:
json.dump(metrics, handle, indent=2, sort_keys=False)
handle.write("\n")
print(f"outliner-metrics -> {OUT} ({outliner['width']}x{outliner['height']}, "
f"header {header['height']}, row {widget_unit})")