Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ all: $(DIST_DIR)/$(BINARY_NAME)

$(DIST_DIR)/$(BINARY_NAME): $(SRC_DIR)/main.swift
@mkdir -p $(DIST_DIR)
swiftc -O -o $(DIST_DIR)/$(BINARY_NAME) $(SRC_DIR)/main.swift -framework Cocoa
swiftc -O -o $(DIST_DIR)/$(BINARY_NAME) \
$(SRC_DIR)/main.swift \
-framework Cocoa \
-framework SwiftUI

install: $(DIST_DIR)/$(BINARY_NAME)
@echo "Installing to $(PREFIX)/bin..."
Expand Down
32 changes: 10 additions & 22 deletions src/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import Cocoa
import Darwin
import SwiftUI

/// A custom table row view that provides hover and selection effects
class HoverTableRowView: NSTableRowView {
Expand Down Expand Up @@ -507,28 +508,15 @@ class MenuApp: NSObject, NSApplicationDelegate, NSTableViewDataSource, NSTableVi
/// - row: The row for which to provide the view
/// - Returns: The view to display in the table cell
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let cellPadding: CGFloat = 4
let cell = NSTextField(labelWithString: filteredItems[row])
cell.textColor = NSColor.white
cell.backgroundColor = NSColor.clear
cell.isBordered = false
cell.font = NSFont.systemFont(ofSize: 16, weight: .regular)
cell.lineBreakMode = .byTruncatingTail

// Create container for proper padding and hover state
let container = NSView(frame: NSRect(x: 0, y: 0, width: tableView.frame.width, height: tableView.rowHeight))
container.wantsLayer = true

// Center the cell vertically in its container and add side padding
let cellHeight = cell.cell?.cellSize.height ?? 20
let yOffset = (container.frame.height - cellHeight) / 2
cell.frame = NSRect(x: cellPadding,
y: yOffset,
width: container.frame.width - (cellPadding * 2),
height: cellHeight)

container.addSubview(cell)
return container
let text = filteredItems[row]
let hostingView = NSHostingView(rootView:
Text(text)
.font(.system(size: 16, weight: .regular))
.foregroundColor(.white)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.padding(.leading, 4)
)
return hostingView
}

/// Provides a custom row view for the table
Expand Down