feat: updated GPU portal view

This commit is contained in:
Serhiy Mytrovtsiy
2024-01-23 19:12:14 +01:00
parent 7ed9b9f4d3
commit b392a9732c
3 changed files with 85 additions and 29 deletions

View File

@@ -350,6 +350,29 @@ public func popupRow(_ view: NSView, n: CGFloat = 0, title: String, value: Strin
return (labelView, valueView)
}
public func portalRow(_ v: NSStackView, title: String) -> ValueField {
let view: NSStackView = NSStackView()
view.orientation = .horizontal
view.distribution = .fillProportionally
view.spacing = 1
let labelView: LabelField = LabelField(title)
labelView.font = NSFont.systemFont(ofSize: 11, weight: .regular)
let valueView: ValueField = ValueField()
valueView.font = NSFont.systemFont(ofSize: 12, weight: .regular)
view.addArrangedSubview(labelView)
view.addArrangedSubview(NSView())
view.addArrangedSubview(valueView)
v.addArrangedSubview(view)
view.widthAnchor.constraint(equalTo: v.widthAnchor).isActive = true
return valueView
}
public func popupWithColorRow(_ view: NSView, color: NSColor, n: CGFloat, title: String, value: String) -> (NSView, LabelField, ValueField) {
let rowView: NSView = NSView(frame: NSRect(x: 0, y: 22*n, width: view.frame.width, height: 22))

View File

@@ -85,7 +85,7 @@ public class GPU: Module {
public init() {
self.popupView = Popup()
self.settingsView = Settings("GPU")
self.portalView = Portal("GPU")
self.portalView = Portal(.GPU)
self.notificationsView = Notifications(.GPU)
super.init(
@@ -139,7 +139,7 @@ public class GPU: Module {
return
}
self.portalView.loadCallback(selectedGPU)
self.portalView.callback(selectedGPU)
self.notificationsView.usageCallback(utilization)
self.menuBar.widgets.filter{ $0.isActive }.forEach { (w: Widget) in

View File

@@ -12,51 +12,84 @@
import Cocoa
import Kit
public class Portal: NSStackView, Portal_p {
public var name: String
public class Portal: PortalWrapper {
private var circle: HalfCircleGraphView? = nil
private var usageField: NSTextField? = nil
private var renderField: NSTextField? = nil
private var tilerField: NSTextField? = nil
private var initialized: Bool = false
init(_ name: String) {
self.name = name
super.init(frame: NSRect.zero)
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
self.layer?.cornerRadius = 3
self.orientation = .vertical
self.distribution = .fillEqually
self.spacing = Constants.Popup.spacing*2
self.edgeInsets = NSEdgeInsets(
top: Constants.Popup.spacing*2,
public override func load() {
let view = NSStackView()
view.orientation = .horizontal
view.distribution = .fillEqually
view.spacing = Constants.Popup.spacing*2
view.edgeInsets = NSEdgeInsets(
top: 0,
left: Constants.Popup.spacing*2,
bottom: 0,
right: Constants.Popup.spacing*2
)
self.addArrangedSubview(PortalHeader(name))
self.circle = HalfCircleGraphView()
self.circle!.toolTip = localizedString("GPU usage")
self.addArrangedSubview(self.circle!)
let chartsView = self.charts()
let detailsView = self.details()
self.heightAnchor.constraint(equalToConstant: Constants.Popup.portalHeight).isActive = true
view.addArrangedSubview(chartsView)
view.addArrangedSubview(detailsView)
self.addArrangedSubview(view)
chartsView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
private func charts() -> NSView {
let view = NSStackView()
view.orientation = .vertical
view.distribution = .fillEqually
view.spacing = Constants.Popup.spacing*2
view.edgeInsets = NSEdgeInsets(
top: Constants.Popup.spacing*4,
left: Constants.Popup.spacing*4,
bottom: Constants.Popup.spacing*4,
right: Constants.Popup.spacing*4
)
let chart = HalfCircleGraphView()
chart.toolTip = localizedString("GPU usage")
view.addArrangedSubview(chart)
self.circle = chart
return view
}
public override func updateLayer() {
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
private func details() -> NSView {
let view = NSStackView()
view.orientation = .vertical
view.distribution = .fillEqually
view.spacing = Constants.Popup.spacing*2
self.usageField = portalRow(view, title: "\(localizedString("Usage")):")
self.renderField = portalRow(view, title: "\(localizedString("Render")):")
self.tilerField = portalRow(view, title: "\(localizedString("Tiler")):")
return view
}
public func loadCallback(_ value: GPU_Info) {
internal func callback(_ value: GPU_Info) {
DispatchQueue.main.async(execute: {
if (self.window?.isVisible ?? false) || !self.initialized {
if let value = value.utilization {
self.usageField?.stringValue = "\(Int(value*100))%"
}
if let value = value.renderUtilization {
self.renderField?.stringValue = "\(Int(value*100))%"
}
if let value = value.tilerUtilization {
self.tilerField?.stringValue = "\(Int(value*100))%"
}
self.circle?.setValue(value.utilization!)
self.circle?.setText("\(Int(value.utilization!*100))%")
self.initialized = true