@@ -63,30 +63,10 @@ struct MenuBarAppearanceEditor: View {
6363 isDynamicToggle
6464 }
6565 if appearanceManager. configuration. isDynamic {
66- VStack ( alignment: . leading) {
67- HStack {
68- Text ( " Light Appearance " )
69- . font ( . headline)
70- if case . dark = SystemAppearance . current {
71- PreviewButton ( configuration: appearanceManager. configuration. lightModeConfiguration)
72- }
73- }
74- . frame ( height: 16 )
75- MenuBarPartialAppearanceEditor ( configuration: appearanceManager. bindings. configuration. lightModeConfiguration)
76- }
77- VStack ( alignment: . leading) {
78- HStack {
79- Text ( " Dark Appearance " )
80- . font ( . headline)
81- if case . light = SystemAppearance . current {
82- PreviewButton ( configuration: appearanceManager. configuration. darkModeConfiguration)
83- }
84- }
85- . frame ( height: 16 )
86- MenuBarPartialAppearanceEditor ( configuration: appearanceManager. bindings. configuration. darkModeConfiguration)
87- }
66+ LabeledPartialEditor ( appearance: . light)
67+ LabeledPartialEditor ( appearance: . dark)
8868 } else {
89- MenuBarPartialAppearanceEditor ( configuration : appearanceManager . bindings . configuration . staticConfiguration )
69+ StaticPartialEditor ( )
9070 }
9171 IceSection ( " Menu Bar Shape " ) {
9272 shapePicker
@@ -149,7 +129,7 @@ struct MenuBarAppearanceEditor: View {
149129 }
150130}
151131
152- private struct MenuBarPartialAppearanceEditor : View {
132+ private struct UnlabeledPartialEditor : View {
153133 @Binding var configuration : MenuBarAppearancePartialConfiguration
154134
155135 var body : some View {
@@ -235,7 +215,85 @@ private struct MenuBarPartialAppearanceEditor: View {
235215 }
236216}
237217
218+ private struct LabeledPartialEditor : View {
219+ @EnvironmentObject var appearanceManager : MenuBarAppearanceManager
220+ @State private var currentAppearance = SystemAppearance . current
221+ @State private var textFrame = CGRect . zero
222+
223+ let appearance : SystemAppearance
224+
225+ var body : some View {
226+ IceSection {
227+ labelStack
228+ } content: {
229+ partialEditor
230+ }
231+ . bordered ( false )
232+ . dividers ( false )
233+ . onReceive ( NSApp . publisher ( for: \. effectiveAppearance) ) { _ in
234+ currentAppearance = . current
235+ }
236+ }
237+
238+ @ViewBuilder
239+ private var labelStack : some View {
240+ HStack {
241+ Text ( appearance. titleKey)
242+ . font ( . headline)
243+ . onFrameChange ( update: $textFrame)
244+
245+ if currentAppearance != appearance {
246+ previewButton
247+ }
248+ }
249+ . frame ( height: textFrame. height)
250+ }
251+
252+ @ViewBuilder
253+ private var previewButton : some View {
254+ switch appearance {
255+ case . light:
256+ PreviewButton ( configuration: appearanceManager. configuration. lightModeConfiguration)
257+ case . dark:
258+ PreviewButton ( configuration: appearanceManager. configuration. darkModeConfiguration)
259+ }
260+ }
261+
262+ @ViewBuilder
263+ private var partialEditor : some View {
264+ switch appearance {
265+ case . light:
266+ UnlabeledPartialEditor ( configuration: appearanceManager. bindings. configuration. lightModeConfiguration)
267+ case . dark:
268+ UnlabeledPartialEditor ( configuration: appearanceManager. bindings. configuration. darkModeConfiguration)
269+ }
270+ }
271+ }
272+
273+ private struct StaticPartialEditor : View {
274+ @EnvironmentObject var appearanceManager : MenuBarAppearanceManager
275+
276+ var body : some View {
277+ UnlabeledPartialEditor ( configuration: appearanceManager. bindings. configuration. staticConfiguration)
278+ }
279+ }
280+
238281private struct PreviewButton : View {
282+ private struct DummyButton : NSViewRepresentable {
283+ @Binding var isPressed : Bool
284+
285+ func makeNSView( context: Context ) -> NSButton {
286+ let button = NSButton ( )
287+ button. title = " "
288+ button. bezelStyle = . accessoryBarAction
289+ return button
290+ }
291+
292+ func updateNSView( _ nsView: NSButton , context: Context ) {
293+ nsView. isHighlighted = isPressed
294+ }
295+ }
296+
239297 @EnvironmentObject var appearanceManager : MenuBarAppearanceManager
240298
241299 @State private var frame = CGRect . zero
@@ -268,17 +326,3 @@ private struct PreviewButton: View {
268326 . onFrameChange ( update: $frame)
269327 }
270328}
271-
272- private struct DummyButton : NSViewRepresentable {
273- @Binding var isPressed : Bool
274-
275- func makeNSView( context: Context ) -> NSButton {
276- let button = NSButton ( )
277- button. title = " "
278- return button
279- }
280-
281- func updateNSView( _ nsView: NSButton , context: Context ) {
282- nsView. isHighlighted = isPressed
283- }
284- }
0 commit comments