feat: add appearance/position introduce

This commit is contained in:
allsochen committed 2024-08-05 18:01:44 +08:00
1 parent 4af5add03b
commit e6b32bc5ea
2 files changed
+17 -17

No files matched your search

@@ -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 {
@@ -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()