Explorar el Código

Show checkmark ticks on selected contacts in the print contacts list.

Makes selection state obvious at a glance and updates rows in place when toggled.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 hace 1 mes
padre
commit
dcce3a10cb
Se han modificado 1 ficheros con 28 adiciones y 2 borrados
  1. 28 2
      smart_printer/PrintContactsView.swift

+ 28 - 2
smart_printer/PrintContactsView.swift

@@ -386,7 +386,11 @@ final class PrintContactsOverlayView: NSView, AppearanceRefreshable {
         } else {
             selectedIDs.insert(identifier)
         }
-        reloadList()
+        let contacts = filteredContacts()
+        for (row, contact) in zip(rowViews, contacts) where contact.identifier == identifier {
+            row.setSelected(selectedIDs.contains(identifier))
+            break
+        }
     }
 
     private func printContacts() {
@@ -424,6 +428,7 @@ private final class ContactRowView: NSControl, AppearanceRefreshable {
     var onToggle: (() -> Void)?
 
     private let nameLabel = NSTextField(labelWithString: "")
+    private let checkmarkView = NSImageView()
     private var isSelected = false
     private let rowHeight: CGFloat
 
@@ -439,12 +444,19 @@ private final class ContactRowView: NSControl, AppearanceRefreshable {
         nameLabel.lineBreakMode = .byTruncatingTail
         nameLabel.translatesAutoresizingMaskIntoConstraints = false
 
+        checkmarkView.translatesAutoresizingMaskIntoConstraints = false
+
         addSubview(nameLabel)
+        addSubview(checkmarkView)
         NSLayoutConstraint.activate([
             heightAnchor.constraint(equalToConstant: rowHeight),
             nameLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
-            nameLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
+            nameLabel.trailingAnchor.constraint(lessThanOrEqualTo: checkmarkView.leadingAnchor, constant: -12),
             nameLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
+            checkmarkView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16),
+            checkmarkView.centerYAnchor.constraint(equalTo: centerYAnchor),
+            checkmarkView.widthAnchor.constraint(equalToConstant: 22),
+            checkmarkView.heightAnchor.constraint(equalToConstant: 22),
         ])
         refreshAppearance()
     }
@@ -452,16 +464,30 @@ private final class ContactRowView: NSControl, AppearanceRefreshable {
     @available(*, unavailable)
     required init?(coder: NSCoder) { nil }
 
+    func setSelected(_ selected: Bool) {
+        isSelected = selected
+        refreshAppearance()
+    }
+
     func refreshAppearance() {
+        let symbolName = isSelected ? "checkmark.circle.fill" : "circle"
+        let symbolWeight: NSFont.Weight = isSelected ? .semibold : .regular
+        if let image = NSImage(systemSymbolName: symbolName, accessibilityDescription: isSelected ? "Selected" : "Not selected") {
+            let config = NSImage.SymbolConfiguration(pointSize: 20, weight: symbolWeight)
+            checkmarkView.image = image.withSymbolConfiguration(config)
+        }
+
         if isSelected {
             layer?.borderWidth = 0
             layer?.backgroundColor = AppTheme.homeActiveBackground.cgColor
             nameLabel.textColor = AppTheme.homeActiveForeground
+            checkmarkView.contentTintColor = AppTheme.homeActiveForeground
         } else {
             layer?.borderWidth = 1
             layer?.borderColor = AppTheme.paywallBorder.cgColor
             layer?.backgroundColor = AppTheme.cardBackground.cgColor
             nameLabel.textColor = AppTheme.textPrimary
+            checkmarkView.contentTintColor = AppTheme.textSecondary
         }
     }