Prechádzať zdrojové kódy

Fix titlebar widget icon clipping and add custom layout-fluid asset

Stop masking TitlebarIconButton layer to a circle on small controls so
corner-heavy bitmap icons are not clipped. Add widget_custom_icon imageset
with scaled layout-fluid sources and titlebar sizing helper.

Made-with: Cursor
huzaifahayat12 3 mesiacov pred
rodič
commit
92c2af375d

+ 19 - 0
google_apps/Assets.xcassets/widget_custom_icon.imageset/Contents.json

@@ -0,0 +1,19 @@
+{
+  "images" : [
+    {
+      "filename" : "widget_custom_icon.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "widget_custom_icon@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
+

BIN
google_apps/Assets.xcassets/widget_custom_icon.imageset/widget_custom_icon.png


BIN
google_apps/Assets.xcassets/widget_custom_icon.imageset/widget_custom_icon@2x.png


+ 27 - 1
google_apps/InAppBrowserWindow.swift

@@ -25,7 +25,10 @@ private final class TitlebarIconButton: NSButton {
     private func commonInit() {
         wantsLayer = true
         layer?.cornerRadius = 5
-        layer?.masksToBounds = true
+        // Do not mask the button’s bounds to the rounded rect: on a ~10×10 pt control,
+        // cornerRadius 5 + masksToBounds clips to a *circle* and cuts off corner-heavy
+        // bitmap icons (e.g. layout grid). SF Symbols stay fine due to built-in padding.
+        layer?.masksToBounds = false
     }
 
     override func updateTrackingAreas() {
@@ -87,6 +90,26 @@ private final class TitlebarIconButton: NSButton {
     }
 }
 
+/// Scales a bundled template image to a logical point size for the titlebar (SF Symbols here use 12pt; bitmap icons often need ~14pt to read the same optically).
+private func makeTitlebarSizedTemplateImage(named name: String, pointSize: CGFloat, layoutMarginFraction: CGFloat = 0) -> NSImage? {
+    guard let source = NSImage(named: name) else { return nil }
+    let logicalSize = NSSize(width: pointSize, height: pointSize)
+    let image = NSImage(size: logicalSize, flipped: false) { rect in
+        NSGraphicsContext.current?.imageInterpolation = .high
+        let inset = min(rect.width, rect.height) * layoutMarginFraction
+        let drawRect = rect.insetBy(dx: inset, dy: inset)
+        source.draw(
+            in: drawRect,
+            from: NSRect(origin: .zero, size: source.size),
+            operation: .sourceOver,
+            fraction: 1.0
+        )
+        return true
+    }
+    image.isTemplate = true
+    return image
+}
+
 final class InAppBrowserWindowManager {
     static let shared = InAppBrowserWindowManager()
 
@@ -232,6 +255,9 @@ final class InAppBrowserWindowController: NSWindowController, NSWindowDelegate {
             fallbackSymbolName: "square.on.square"
         )
 
+        // Bundled PNG: 1x = layout-fluid-3, 2x = layout-fluid-4 @ 48px — slightly larger than 12pt symbols so the full glyph reads clearly.
+        widgetButton.image = makeTitlebarSizedTemplateImage(named: "widget_custom_icon", pointSize: 14, layoutMarginFraction: 0)
+
         // Center site identity (logo + app/site name).
         siteIconView = NSImageView()
         siteIconView.translatesAutoresizingMaskIntoConstraints = false