From e6b32bc5ea4e2b3c5fc50a953a0d20def78979c5 Mon Sep 17 00:00:00 2001 From: allsochen Date: Mon, 5 Aug 2024 18:01:44 +0800 Subject: [PATCH] feat: add appearance/position introduce --- .../generic-components/TableGroupView.swift | 12 +++++++--- .../tabs/AppearanceTab.swift | 22 +++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ui/generic-components/TableGroupView.swift b/src/ui/generic-components/TableGroupView.swift index 24655133..ff9117f7 100644 --- a/src/ui/generic-components/TableGroupView.swift +++ b/src/ui/generic-components/TableGroupView.swift @@ -59,10 +59,16 @@ class TableGroupView: NSStackView { } private func setupView() { - translatesAutoresizingMaskIntoConstraints = false orientation = .vertical spacing = 10 + translatesAutoresizingMaskIntoConstraints = false + widthAnchor.constraint(equalToConstant: self.width).isActive = true + setupTitleView() + setupTableView() + } + + private func setupTitleView() { titleStackView.orientation = .vertical titleStackView.alignment = .left titleStackView.spacing = 2 @@ -113,7 +119,9 @@ class TableGroupView: NSStackView { titleStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true titleStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true titleStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true + } + private func setupTableView() { tableStackView.orientation = .vertical tableStackView.spacing = 0 tableStackView.wantsLayer = true @@ -123,12 +131,10 @@ class TableGroupView: NSStackView { tableStackView.layer?.borderWidth = TableGroupView.borderWidth addArrangedSubview(tableStackView) - // Add constraints to ensure tableView takes up the full width tableStackView.translatesAutoresizingMaskIntoConstraints = false tableStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true tableStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true tableStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true - widthAnchor.constraint(equalToConstant: self.width).isActive = true } func addRow(_ row: Row, onClick: EventClosure? = nil, onMouseEntered: EventClosure? = nil, onMouseExited: EventClosure? = nil) -> RowInfo { diff --git a/src/ui/preferences-window/tabs/AppearanceTab.swift b/src/ui/preferences-window/tabs/AppearanceTab.swift index c689c2c2..69a008f4 100644 --- a/src/ui/preferences-window/tabs/AppearanceTab.swift +++ b/src/ui/preferences-window/tabs/AppearanceTab.swift @@ -511,7 +511,7 @@ class Popover: NSPopover { class AppearanceTab: NSObject { static var shared = AppearanceTab() static let width = CGFloat(650) - static let spacing = CGFloat(20) + static let spacing = CGFloat(30) static var advancedButton: NSButton! @@ -530,25 +530,19 @@ class AppearanceTab: NSObject { stackView.addArrangedSubview(effectsView) stackView.translatesAutoresizingMaskIntoConstraints = false - // 设置stackView的边距约束 let padding = CGFloat(20) - NSLayoutConstraint.activate([ - appearanceView.topAnchor.constraint(equalTo: stackView.topAnchor, constant: padding), - appearanceView.leadingAnchor.constraint(equalTo: stackView.leadingAnchor, constant: padding), - appearanceView.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: -padding), - ]) + appearanceView.topAnchor.constraint(equalTo: stackView.topAnchor, constant: padding).isActive = true + appearanceView.leadingAnchor.constraint(equalTo: stackView.leadingAnchor, constant: padding).isActive = true + appearanceView.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: -padding).isActive = true - // 设置stackView的大小约束 - NSLayoutConstraint.activate([ - stackView.widthAnchor.constraint(equalToConstant: width + 2 * padding), - stackView.heightAnchor.constraint(equalToConstant: 450 + 2 * padding) - ]) + stackView.widthAnchor.constraint(equalToConstant: width + 2 * padding).isActive = true + stackView.heightAnchor.constraint(equalToConstant: 550 + 2 * padding).isActive = true return stackView } private static func makeAppearanceView() -> NSStackView { - let table = TableGroupView(title: "Appearance", width: AppearanceTab.width) + let table = TableGroupView(title: "Appearance", subTitle: "The appearance feature allows for switching between multiple modes of the switcher, with the ability to adjust various display aspects such as size, color, and layout. Each appearance mode has its own unique settings.", width: AppearanceTab.width) _ = table.addRow(leftText: NSLocalizedString("Appearance model", comment: ""), rightViews: LabelAndControl.makeLabelWithImageRadioButtons("", "appearanceModel", AppearanceModelPreference.allCases, extraAction: { _ in toggleAdvancedButton() @@ -562,7 +556,7 @@ class AppearanceTab: NSObject { } private static func makePositionView() -> NSStackView { - let table = TableGroupView(title: "Position", width: AppearanceTab.width) + let table = TableGroupView(title: "Position", subTitle: "When we have multiple monitors, the position feature allows us to decide on which monitor the switcher is displayed, enabling a seamless window moving experience.", width: AppearanceTab.width) _ = table.addRow(leftText: NSLocalizedString("Show on screen", comment: ""), rightViews: LabelAndControl.makeDropdown("showOnScreen", ShowOnScreenPreference.allCases)) table.fit()