From 2b61760d94690549c7909ecd06a6e8f18f164f6b Mon Sep 17 00:00:00 2001 From: Etienne Roesch Date: Sat, 5 Apr 2025 22:02:22 +0100 Subject: [PATCH] ENH: ScrollViewReader with full-space background colour --- MSG Desktop/ContentView.swift | 88 +++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/MSG Desktop/ContentView.swift b/MSG Desktop/ContentView.swift index 0f3e008..43965c1 100644 --- a/MSG Desktop/ContentView.swift +++ b/MSG Desktop/ContentView.swift @@ -40,51 +40,57 @@ struct ContentView: View { .onPreferenceChange(ViewHeightKey.self) { height in self.imageHeight = height } - - // ScrollView fills remaining height - ScrollViewReader { proxy in - ScrollView { - LazyVStack(alignment: .leading, spacing: 0) { - let lines = appState.output.components(separatedBy: .newlines) - - ForEach(lines.indices, id: \.self) { index in - Text(lines[index]) - .font(.system(.body, design: .monospaced)) - .frame(maxWidth: .infinity, alignment: .leading) + + ZStack { + Color.black + .ignoresSafeArea() + + // ScrollView fills remaining height + ScrollViewReader { proxy in + ScrollView { + LazyVStack(alignment: .leading, spacing: 0) { + let lines = appState.output.components(separatedBy: .newlines) + + ForEach(lines.indices, id: \.self) { index in + Text(lines[index]) + .font(.system(.body, design: .monospaced)) + .frame(maxWidth: .infinity, alignment: .leading) + + } + + Color.clear.frame(height: 1).id("bottom") } - - Color.clear.frame(height: 1).id("bottom") + .padding() } - .padding() - } - .onChange(of: appState.output) { _, _ in - trimLinesIfNeeded() - withAnimation { - proxy.scrollTo("bottom", anchor: .bottom) + .onChange(of: appState.output) { _, _ in + trimLinesIfNeeded() + withAnimation { + proxy.scrollTo("bottom", anchor: .bottom) + } } + + // ScrollView { + // VStack(alignment: .leading) { + // TextEditor(text: $appState.output) + // .font(.system(.body, design: .monospaced)) + // .frame( + // width: geometry.size.width - 60, + // height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding + // ) + // .padding() + // .disabled(true) + // + // Text("") + // .id("bottom") + // } + // } + // .onChange(of: appState.output) { _, _ in + // trimLinesIfNeeded() + // withAnimation { + // proxy.scrollTo("bottom", anchor: .bottom) + // } + // } } - -// ScrollView { -// VStack(alignment: .leading) { -// TextEditor(text: $appState.output) -// .font(.system(.body, design: .monospaced)) -// .frame( -// width: geometry.size.width - 60, -// height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding -// ) -// .padding() -// .disabled(true) -// -// Text("") -// .id("bottom") -// } -// } -// .onChange(of: appState.output) { _, _ in -// trimLinesIfNeeded() -// withAnimation { -// proxy.scrollTo("bottom", anchor: .bottom) -// } -// } } // Buttons