Skip to content

fix: Resize host view after graph height changes so menu re-measures#124

Open
pggpgg wants to merge 1 commit into
macmade:mainfrom
pggpgg:fix/menu-item-clipped-graph
Open

fix: Resize host view after graph height changes so menu re-measures#124
pggpgg wants to merge 1 commit into
macmade:mainfrom
pggpgg:fix/menu-item-clipped-graph

Conversation

@pggpgg
Copy link
Copy Markdown

@pggpgg pggpgg commented May 19, 2026

Summary

The temperature graph in the menu bar dropdown is clipped at the top: only the legend (orange dot + "Temperature" label) is visible at the bottom of the graph box, the sparkline above it gets cut off. Other rows in the same InfoViewController stack view (Thermal Pressure, Temperature value, etc.) can also be clipped depending on layout state.

Before (bug) After (fix)
Clipped graph in the Hot dropdown — only the bottom legend is visible Hot dropdown rendering correctly with full graph and other rows visible

Note: the two screenshots were taken in different system appearances (Dark mode for "before", Light mode for "after"), which is why the menu chrome and graph background look different. GraphView uses NSColor.controlTextColor for its rounded-rect background, and that's a dynamic system color that resolves differently between Dark and Light mode. No color-related code was changed by this PR.

Root cause

InfoViewController.view is installed as a custom view on an NSMenuItem in ApplicationDelegate.applicationDidFinishLaunching:

self.menu.item( withTag: 1 )?.view = infoViewController.view

NSMenu measures the custom view's frame once at this point and caches the result for the menu item's host. It does not observe later Auto Layout changes to the view's intrinsic size.

viewDidLoad initializes graphViewHeight.constant = 0, so the view is initially short. A couple of seconds later, once two temperature samples have been collected, update() does:

self.graphViewHeight.constant = self.graphView?.canDisplay ?? false ? 100 : 0

Auto Layout grows the view to its new height, but the menu item's host frame stays at the original (smaller) value. The bottom-anchored portions of the graph (drawn at rect.origin.y in unflipped coords — the orange dot and "Temperature" label) remain visible, while the top of the graph — including the sparkline — is clipped off by the menu item's container.

Fix

After the constraint change in update():

  1. Detect that the constraint actually changed (avoids re-laying out every refresh tick).
  2. Call view.layoutSubtreeIfNeeded() to flush the pending Auto Layout pass.
  3. Set view.frame.size = view.fittingSize to nudge NSMenu to re-measure the custom view's host item with the new size.

This is the minimal change that gets the menu to respect the dynamic content size.

Test plan

  • Build patched Hot.app, launch, open the dropdown after ~4 seconds (enough time for two temperature samples to populate the graph). Graph is now fully visible.
  • Close and re-open the dropdown several times — graph renders correctly each time.
  • Verified on macOS 26.5 with Xcode 26.5 (Apple Silicon, MacBook Air).

🤖 Generated with Claude Code

The InfoViewController's view is installed as a custom view on an
NSMenuItem (see ApplicationDelegate.applicationDidFinishLaunching).
NSMenu measures the custom view once when the menu item is created
and does not observe later Auto Layout changes.

When the temperature graph becomes displayable, `update()` flips the
graphViewHeight constraint from 0 to 100. Auto Layout grows the
InfoViewController's view, but the menu item's host frame stays at
the original (smaller) height, so the top of the graph and any other
content above the bottom-anchored legend gets clipped off.

Force a layout pass after the constraint change and propagate the
new fitting size to view.frame so the menu re-measures the host item.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pggpgg pggpgg force-pushed the fix/menu-item-clipped-graph branch from 430b509 to 4d591b1 Compare May 19, 2026 20:23
pggpgg added a commit to pggpgg/Hot that referenced this pull request May 19, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pggpgg
Copy link
Copy Markdown
Author

pggpgg commented May 19, 2026

Hey @macmade

Apologies for the potentially clumsy PR, I'm not a professional.

Found your project this week and I really appreciate what you've done with Hot. I experienced a weird visibility issue on Mac OS 26.5 (25F71) using my 13in M5 air, where the top half of the widget just clipped with the top of my screen. I thought I'd grab the repo and try a small targeted fix.

This is the result. I used an assistant and the code may not be up to your standards, but I thought I'd bring it up to your attention nonetheless.

Thanks and have a great day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant