Skip to content

Library Usage Chrome

Chris W edited this page Dec 9, 2024 · 3 revisions

Window Chrome

Window chrome adds decorative elements to your code screenshots, making them look like they're being displayed in a real application window. Goshot provides several window chrome styles and extensive customization options.

Available Chrome Styles

  1. macOS Style
  2. Windows Style
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows XP
  3. GNOME Style
    • Adwaita
    • Breeze

Basic Usage

import (
    "github.com/watzon/goshot/pkg/chrome"
    "github.com/watzon/goshot/pkg/render"
)

// Create a canvas with macOS-style chrome
canvas := render.NewCanvas().
    SetChrome(chrome.NewMacChrome(
        chrome.WithTitle("main.go"),
        chrome.WithThemeByName("sequoia", chrome.ThemeVariantDark),
    ))

Chrome Options

All chrome styles support these common configuration options:

chrome.WithTitle("my-file.go")                    // Set window title
chrome.WithThemeByName("theme", ThemeVariantDark) // Set theme by name and variant
chrome.WithVariant(ThemeVariantLight)             // Change theme variant
chrome.WithTitleBar(true)                         // Show/hide title bar
chrome.WithCornerRadius(10)                       // Set window corner radius

macOS Style

The macOS style chrome mimics the appearance of macOS windows, including the iconic traffic light controls.

chrome := chrome.NewMacChrome(
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("sequoia", chrome.ThemeVariantDark),
    chrome.WithCornerRadius(6),
)

Available macOS Themes

  • sequoia - Modern dark theme inspired by macOS Sonoma
  • monterey - Classic macOS Monterey look
  • big-sur - macOS Big Sur style
  • catalina - Classic macOS Catalina look

Windows Style

The Windows style chrome supports multiple Windows versions, each with their own unique appearance:

// Windows 11 style
chrome := chrome.NewWindowsChrome(
    chrome.WindowsStyleWin11,
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("default", chrome.ThemeVariantDark),
    chrome.WithCornerRadius(8),
)

// Windows 10 style
chrome := chrome.NewWindowsChrome(
    chrome.WindowsStyleWin10,
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("default", chrome.ThemeVariantDark),
)

// Windows 8 style
chrome := chrome.NewWindowsChrome(
    chrome.WindowsStyleWin8,
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("default", chrome.ThemeVariantLight),
)

// Windows XP style
chrome := chrome.NewWindowsChrome(
    chrome.WindowsStyleWinXP,
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("default", chrome.ThemeVariantLight),
)

GNOME Style

The GNOME style chrome provides both Adwaita and Breeze themes, matching popular Linux desktop environments.

// Create with Adwaita style
chrome := chrome.NewGNOMEChrome(
    chrome.GNOMEStyleAdwaita,
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("adwaita", chrome.ThemeVariantDark),
)

// Or with Breeze style
chrome := chrome.NewGNOMEChrome(
    chrome.GNOMEStyleBreeze,
    chrome.WithTitle("main.go"),
    chrome.WithThemeByName("breeze", chrome.ThemeVariantDark),
)

Theme Customization

You can create custom themes with detailed control over visual properties:

theme := chrome.Theme{
    Type:    chrome.ThemeTypeMac,  // or ThemeTypeWindows, ThemeTypeGNOME
    Variant: chrome.ThemeVariantDark,
    Name:    "custom",
    Properties: chrome.ThemeProperties{
        // Basic properties
        TitleFont:         "SF Pro",
        TitleText:         color.RGBA{255, 255, 255, 255},
        TitleFontSize:     14,
        TitleBackground:   color.RGBA{30, 30, 30, 255},
        ControlsColor:     color.RGBA{255, 255, 255, 255},
        ContentBackground: color.RGBA{40, 40, 40, 255},
        TextColor:         color.RGBA{255, 255, 255, 255},

        // Extended properties
        AccentColor:        color.RGBA{0, 120, 215, 255},   // Primary accent color
        BorderColor:        color.RGBA{60, 60, 60, 255},    // Window border color
        InactiveTitleBg:    color.RGBA{40, 40, 40, 255},    // Title bar when inactive
        InactiveTitleText:  color.RGBA{128, 128, 128, 255}, // Title text when inactive
        ButtonHoverColor:   color.RGBA{70, 70, 70, 255},    // Button hover state
        ButtonPressedColor: color.RGBA{50, 50, 50, 255},    // Button pressed state
        CornerRadius:       8.0,                            // Window corner radius
        BorderWidth:        1.0,                            // Window border width

        // Additional theme-specific properties
        CustomProperties: map[string]any{
            // Add any theme-specific properties here
        },
    },
}

// Register the custom theme
chrome.DefaultRegistry.RegisterTheme(theme.Type, theme.Name, theme.Variant, theme)

Best Practices

  1. Theme Management

    • Use the theme registry to manage and reuse themes
    • Register custom themes at startup
    • Use theme variants consistently across your application
  2. Performance

    • Chrome objects can be reused across multiple renderings
    • Register custom themes if you'll use them multiple times
    • Use the theme registry to manage theme variants
  3. Customization

    • Start with a built-in theme and customize as needed
    • Consider platform-specific design guidelines
    • Test themes in both light and dark variants