Skip to content

Commit

Permalink
mac/title: use enum for material values instead of generic integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Akemi committed Dec 28, 2024
1 parent 4063cdf commit 4dbf81c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 deletions.
21 changes: 21 additions & 0 deletions osdep/mac/app_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ enum {
MAC_APPEAR_VIBRANT_DARK_HC,
};

enum {
MAC_MAT_TITLEBAR = 0,
MAC_MAT_SELECTION,
MAC_MAT_MENU,
MAC_MAT_POPOVER,
MAC_MAT_SIDEBAR,
MAC_MAT_HEADER_VIEW,
MAC_MAT_SHEET,
MAC_MAT_WINDOW_BACKGROUND,
MAC_MAT_HUD_WINDOW,
MAC_MAT_FULL_SCREEN,
MAC_MAT_TOOL_TIP,
MAC_MAT_CONTENT_BACKGROUND,
MAC_MAT_UNDER_WINDOW_BACKGROUND,
MAC_MAT_UNDER_PAGE_BACKGROUND,
MAC_MAT_DARK,
MAC_MAT_LIGHT,
MAC_MAT_MEDIUM_LIGHT,
MAC_MAT_ULTRA_DARK,
};

enum {
MAC_CSP_AUTO = -1,
MAC_CSP_DISPLAY_P3,
Expand Down
25 changes: 18 additions & 7 deletions osdep/mac/app_bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,24 @@
{"vibrantLightHighContrast", MAC_APPEAR_VIBRANT_LIGHT_HC},
{"vibrantDarkHighContrast", MAC_APPEAR_VIBRANT_DARK_HC})},
{"macos-title-bar-material", OPT_CHOICE(macos_title_bar_material,
{"titlebar", 0}, {"selection", 1}, {"menu", 2},
{"popover", 3}, {"sidebar", 4}, {"headerView", 5},
{"sheet", 6}, {"windowBackground", 7}, {"hudWindow", 8},
{"fullScreen", 9}, {"toolTip", 10}, {"contentBackground", 11},
{"underWindowBackground", 12}, {"underPageBackground", 13},
{"dark", 14}, {"light", 15}, {"mediumLight", 16},
{"ultraDark", 17})},
{"titlebar", MAC_MAT_TITLEBAR},
{"selection", MAC_MAT_SELECTION},
{"menu", MAC_MAT_MENU},
{"popover", MAC_MAT_POPOVER},
{"sidebar", MAC_MAT_SIDEBAR},
{"headerView", MAC_MAT_HEADER_VIEW},
{"sheet", MAC_MAT_SHEET},
{"windowBackground", MAC_MAT_WINDOW_BACKGROUND},
{"hudWindow", MAC_MAT_HUD_WINDOW},
{"fullScreen", MAC_MAT_FULL_SCREEN},
{"toolTip", MAC_MAT_TOOL_TIP},
{"contentBackground", MAC_MAT_CONTENT_BACKGROUND},
{"underWindowBackground", MAC_MAT_UNDER_WINDOW_BACKGROUND},
{"underPageBackground", MAC_MAT_UNDER_PAGE_BACKGROUND},
{"dark", MAC_MAT_DARK},
{"light", MAC_MAT_LIGHT},
{"mediumLight", MAC_MAT_MEDIUM_LIGHT},
{"ultraDark", MAC_MAT_ULTRA_DARK})},
{"macos-title-bar-color", OPT_COLOR(macos_title_bar_color)},
{"macos-fs-animation-duration",
OPT_CHOICE(macos_fs_animation_duration, {"default", -1}),
Expand Down
38 changes: 19 additions & 19 deletions video/out/mac/title_bar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ class TitleBar: NSVisualEffectView {
}

func set(material: Int32) {
self.material = { switch material {
case 0: return .titlebar
case 1: return .selection
case 2: return .menu
case 3: return .popover
case 4: return .sidebar
case 5: return .headerView
case 6: return .sheet
case 7: return .windowBackground
case 8: return .hudWindow
case 9: return .fullScreenUI
case 10: return .toolTip
case 11: return .contentBackground
case 12: return .underWindowBackground
case 13: return .underPageBackground
case 14: return .dark
case 15: return .light
case 16: return .mediumLight
case 17: return .ultraDark
self.material = { switch Int(material) {
case MAC_MAT_TITLEBAR: return .titlebar
case MAC_MAT_SELECTION: return .selection
case MAC_MAT_MENU: return .menu
case MAC_MAT_POPOVER: return .popover
case MAC_MAT_SIDEBAR: return .sidebar
case MAC_MAT_HEADER_VIEW: return .headerView
case MAC_MAT_SHEET: return .sheet
case MAC_MAT_WINDOW_BACKGROUND: return .windowBackground
case MAC_MAT_HUD_WINDOW: return .hudWindow
case MAC_MAT_FULL_SCREEN: return .fullScreenUI
case MAC_MAT_TOOL_TIP: return .toolTip
case MAC_MAT_CONTENT_BACKGROUND: return .contentBackground
case MAC_MAT_UNDER_WINDOW_BACKGROUND: return .underWindowBackground
case MAC_MAT_UNDER_PAGE_BACKGROUND: return .underPageBackground
case MAC_MAT_DARK: return .dark
case MAC_MAT_LIGHT: return .light
case MAC_MAT_MEDIUM_LIGHT: return .mediumLight
case MAC_MAT_ULTRA_DARK: return .ultraDark
default: return .titlebar
}
}()
Expand Down

0 comments on commit 4dbf81c

Please sign in to comment.