feat: added Mini widget to the Sensors module. It has quite a lot of limitations and only one sensor could be visualized (I hope understandable why) (#2029)

This commit is contained in:
Serhiy Mytrovtsiy
2024-08-23 20:34:10 +02:00
parent bdbaeb8c4d
commit bcabd48fa4
7 changed files with 159 additions and 46 deletions

View File

@@ -1275,7 +1275,7 @@ public class PreferencesSection: NSStackView {
}
public func delete(_ id: String) {
let views = self.container.subviews.filter({ $0.identifier != nil })
let views = self.container.subviews
views.enumerated().forEach { (i, v) in
guard v.identifier?.rawValue == id else { return }
if self.container.subviews.indices.contains(i-1) {
@@ -1286,19 +1286,31 @@ public class PreferencesSection: NSStackView {
}
v.removeFromSuperview()
}
return
}
public func contains(_ id: String) -> Bool {
self.container.subviews.contains(where: { $0.identifier?.rawValue == id })
}
public func toggleVisibility(_ at: Int, newState: Bool) {
public func setRowVisibility(_ at: Int, newState: Bool) {
for i in self.container.subviews.indices where i/2 == at && Double(i).remainder(dividingBy: 2) == 0 {
self.container.subviews[i-1].isHidden = !newState
self.container.subviews[i].isHidden = !newState
}
}
public func setRowVisibility(_ id: String, newState: Bool) {
guard let at = self.container.subviews.firstIndex(where: { $0.identifier?.rawValue == id }) else { return }
self.setRowVisibility(at/2, newState: newState)
}
public func setRowVisibility(_ row: PreferencesRow, newState: Bool) {
guard let at = self.container.subviews.firstIndex(where: { $0 == row }) else { return }
self.setRowVisibility(at/2, newState: newState)
}
public func findRow(_ id: String) -> PreferencesRow? {
let rows: [PreferencesRow] = self.container.subviews.filter({ $0 is PreferencesRow }).compactMap({ $0 as? PreferencesRow })
return rows.first(where: { $0.identifier?.rawValue == id })
}
}
private class PreferencesSeparator: NSView {
@@ -1341,6 +1353,11 @@ public class PreferencesRow: NSStackView {
fatalError("init(coder:) has not been implemented")
}
public func replaceComponent(with view: NSView) {
self.subviews.removeLast()
self.addArrangedSubview(view)
}
private func text(_ title: String? = nil, _ description: String? = nil) -> NSView {
let view: NSStackView = NSStackView()
view.orientation = .vertical