Repository navigation
Let visualizers draw keystrokes in a user-chosen font - #355
Open
anandghegde wants to merge 1 commit into
Open
anandghegde wants to merge 1 commit into
anandghegde wants to merge 1 commit into
Conversation
Closes keycastr#169. Each of the three bundled visualizers already exposes a font size in its preferences, but the typeface has always been hardcoded to the system font. This adds a font family pop-up next to the existing size control in the Default, Minimal and Svelte preference panes, stored per visualizer in default.fontName / minimal.fontName / svelte.fontName. KCFontPopUpButton builds its menu from NSFontManager's available families and renders each family's name in that family, so the list doubles as a specimen sheet. It reads and writes whichever defaults key the nib hands it through fontFamilyDefaultsKey, which keeps one class serving all three panes. Font resolution lives in -[NSUserDefaults fontForKey:size:bold:]. It answers the system font when nothing is stored, and again when the stored family has since been uninstalled or disabled in Font Book, so a visualizer always has something to draw with. Minimal asks for bold and falls back to the family's regular weight rather than substituting a different family when no bold face exists. The stored value is deliberately left alone in that case, so reinstalling a font restores the old selection. In Svelte the chosen font applies to the key label only, not the modifier strip above it, which reads better as system-font iconography. Its shrink-to-fit loop also gained a minimum size, since a user-selectable wide font makes a previously unreachable unbounded loop reachable. NSUserDefaults+Utility.h becomes a public KCVisualizer header so the font resolution is directly testable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #169.
Every bundled visualizer already lets you pick a font size; the typeface has always been hardcoded to the system font. The request in #169 is for fixed-width —
Ivslare indistinguishable in the system font, which matters a lot when you're recording a tutorial — but it's just as useful for matching a visualizer to a theme.What this adds
A Font pop-up in each of the three bundled preference panes, directly above the existing Font Size control (Svelte has no size control, so it sits under "Display All Keystrokes"). Each pane stores its own choice:
default.fontNameminimal.fontNamesvelte.fontNameThe menu lists every installed family, each drawn in its own typeface, so it reads as a specimen sheet rather than a wall of identical text. The first item is "System Font", which is the default and restores today's behaviour exactly.
How it's put together
KCFontPopUpButtonis a smallNSPopUpButtonsubclass that populates itself fromNSFontManagerand reads/writes whichever defaults key the nib hands it viafontFamilyDefaultsKey(a user-defined runtime attribute). One class covers all three panes, and any future visualizer gets font selection by dropping the control into its nib and setting that one attribute.Font resolution is
-[NSUserDefaults fontForKey:size:bold:], sitting next to the existingcolorForKey:/imageForKey:helpers. It always returns something drawable:Minimal is the only visualizer that asks for bold, matching its current
boldSystemFontOfSize:.Two judgement calls worth flagging
Svelte applies the font to the key label only, not the modifier strip above it. That strip is ⌘⌥⇧-style iconography and reads better kept in the system font; a decorative display face makes it much harder to parse at a glance.
Svelte's shrink-to-fit loop gained a minimum size. It previously ran
while (size.width > frame.size.width - 10) fontSize -= 1.0;with no floor. That was unreachable with the system font, but a user-selectable wide face makes it reachable, so it now stops at 8pt.Tests
New
KCFontSelectionTestscovers the resolution rules (unset, empty, installed, bold fallback, uninstalled family) and an integration test that instantiates the Default and Svelte preference views from their nibs and asserts each one has a font pop-up bound to its own key with a populated menu. That last one is what proves the nib wiring actually survives — the legacywrapper.nibbundles can't be diffed usefully by eye.To make the helper testable,
NSUserDefaults+Utility.his now a public header of theKCVisualizerframework.Minimal isn't in that integration test because only
KCDefaultVisualizer.kcpluginandSvelte.kcpluginare copied into the test bundle's plug-ins. Its pane is a plain xib and gets validated when the project builds; I verified all three panes' computed layouts by hand, including re-seating the separator boxes in Default and Minimal, which use autoresizing rather than autolayout and so don't move with the rest of the pane.Both
wrapper.nibbundles were recompiled withibtooland produce no errors or warnings. The full test suite passes.