Skip to content

Commit

Permalink
UI: Make images work in messages again (northpolesec#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox authored Nov 11, 2024
1 parent ed20199 commit 1f41f0c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Source/gui/SNTMessageView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI

import santa_common_SNTConfigurator

public let MAX_OUTER_VIEW_WIDTH = 560.0
Expand Down Expand Up @@ -48,7 +49,7 @@ public struct SNTMessageView<Content: View>: View {

Spacer()

Text(AttributedString(blockMessage))
AttributedText(blockMessage)
.multilineTextAlignment(.center)
.padding([.leading, .trailing], 15.0)
.fixedSize()
Expand Down Expand Up @@ -161,3 +162,19 @@ public func DismissButton(
.keyboardShortcut(.escape, modifiers: .command)
.help("⌘ Esc")
}

// AttributedText is like Text() but it supports all the features of NSAttributedString()
// by using NSTextField under the hood.
struct AttributedText: NSViewRepresentable {
private let attributedString: NSAttributedString

init(_ attributedString: NSAttributedString) {
self.attributedString = attributedString
}

func makeNSView(context: Context) -> NSTextField {
NSTextField(labelWithAttributedString: self.attributedString)
}

func updateNSView(_ textField: NSTextField, context: Context) {}
}

0 comments on commit 1f41f0c

Please sign in to comment.