From 09e62558158b1d0f31091b58320d4050833a9fb6 Mon Sep 17 00:00:00 2001 From: M4n0x Date: Tue, 17 Nov 2026 18:43:04 +0100 Subject: [PATCH 1/3] feat: offer labels above metric values and meters Add a label, value and meter Display choice for native metric widgets. Preserve source order, profile editing and undo, and keep 100% visible. Fixes #783 --- Sources/StableBar/WidgetSettings.swift | 45 +++- Tests/StableBarTests/BatteryTests.swift | 2 +- Tests/StableBarTests/DiskTests.swift | 2 +- Tests/StableBarTests/MetricDisplayTests.swift | 65 +++++ docs/create-a-widget.md | 4 +- scenes/labeled-metric-built-in.json | 250 ++++++++++++++++++ scenes/labeled-metric-island.json | 250 ++++++++++++++++++ scenes/settings-labeled-metric.json | 54 ++++ 8 files changed, 663 insertions(+), 9 deletions(-) create mode 100644 Tests/StableBarTests/MetricDisplayTests.swift create mode 100644 scenes/labeled-metric-built-in.json create mode 100644 scenes/labeled-metric-island.json create mode 100644 scenes/settings-labeled-metric.json diff --git a/Sources/StableBar/WidgetSettings.swift b/Sources/StableBar/WidgetSettings.swift index e79a058f..5a63e135 100644 --- a/Sources/StableBar/WidgetSettings.swift +++ b/Sources/StableBar/WidgetSettings.swift @@ -146,7 +146,7 @@ struct WidgetClockFormat { /// battery, whose icon is its battery block, `volume` for sound, `cpu`, `memory` or both, in /// order, for system, and `disk` for disk. enum WidgetMetricDisplay: String, CaseIterable { - case standard, changes, icon, value, meter, graph, custom + case standard, changes, icon, value, meter, labelValueMeter, graph, custom var title: String { switch self { @@ -155,6 +155,7 @@ enum WidgetMetricDisplay: String, CaseIterable { case .icon: "Icon only" case .value: "Value only" case .meter: "Meter and value" + case .labelValueMeter: "Label, value and meter" case .graph: "Graph and value" case .custom: "Custom layout" } @@ -182,6 +183,10 @@ enum WidgetMetricDisplay: String, CaseIterable { case .icon where sources == ["percent"]: return .null case .standard where sources == ["disk"]: return .null case .custom: return nil + case .labelValueMeter: + let columns = sources.map(metricColumn) + return columns.count == 1 ? columns[0] + : .object(["type": .string("row"), "style": .object(["spacing": .number(14)]), "children": .array(columns)]) default: return .object(["type": .string("row"), "children": .array(sources.flatMap(blocks))]) } } @@ -192,11 +197,7 @@ enum WidgetMetricDisplay: String, CaseIterable { case "memory": .object(["type": .string("symbol"), "name": .string("memorychip")]) default: .object(["type": .string("symbol"), "source": .string("icon")]) } - let text: ConfigurationValue = source == "memory" - ? .object(["type": .string("row"), "style": .object(["spacing": .number(0)]), "children": .array([ - .object(["type": .string("field"), "field": .string("memory")]), .object(["type": .string("text"), "text": .string("%")]) - ])]) - : .object(["type": .string("field"), "field": .string("text")]) + let text = Self.valueBlock(for: source) switch self { case .icon: return [icon] case .value: return [text] @@ -212,10 +213,42 @@ enum WidgetMetricDisplay: String, CaseIterable { } } + private static func valueBlock(for source: String) -> ConfigurationValue { + source == "memory" + ? .object(["type": .string("row"), "style": .object(["spacing": .number(0)]), "children": .array([ + .object(["type": .string("field"), "field": .string("memory")]), .object(["type": .string("text"), "text": .string("%")]) + ])]) + : .object(["type": .string("field"), "field": .string("text")]) + } + + private func metricColumn(for source: String) -> ConfigurationValue { + let label = ["percent": "BAT", "volume": "VOL", "cpu": "CPU", "memory": "MEM", "disk": "DISK"][source] ?? source.uppercased() + var value = Self.valueBlock(for: source) + if case var .object(properties) = value { + var style: [String: ConfigurationValue] = [:] + if case let .object(existing)? = properties["style"] { style = existing } + style["width"] = .number(37) + properties["style"] = .object(style) + properties["alignment"] = .string("trailing") + value = .object(properties) + } + return .object(["type": .string("column"), "style": .object(["spacing": .number(1), "width": .number(73)]), "children": .array([ + .object(["type": .string("row"), "style": .object(["spacing": .number(0)]), "children": .array([ + .object(["type": .string("text"), "text": .string(label), "role": .string("key"), "alignment": .string("leading"), + "style": .object(["fontWeight": .string("medium"), "width": .number(36)])]), value + ])]), + .object(["type": .string("column"), "style": .object(["paddingTop": .number(2)]), "children": .array([ + .object(["type": .string("progress"), "source": .string(source), "height": .number(4), "role": .string("meter")]) + ])]) + ])]) + } + static func current(_ layout: ConfigurationValue?, sources: [String]) -> Self { if layout == nil || layout == .null { return choices(for: sources[0])[0] } + if layout == Self.labelValueMeter.layout(for: sources) { return .labelValueMeter } guard case let .object(properties) = layout, properties["type"] == .string("row") else { return .custom } return choices(for: sources[0]).first { + guard $0 != .labelValueMeter else { return false } guard case let .object(candidate)? = $0.layout(for: sources) else { return false } return candidate["children"] == properties["children"] } ?? .custom diff --git a/Tests/StableBarTests/BatteryTests.swift b/Tests/StableBarTests/BatteryTests.swift index e92761af..8d7014e8 100644 --- a/Tests/StableBarTests/BatteryTests.swift +++ b/Tests/StableBarTests/BatteryTests.swift @@ -131,7 +131,7 @@ private func battery(_ extra: [String: Any] = [:]) -> [String: Any] { } @Test func batteryDisplayStartsWithTheBatteryAloneAndUsesItAsTheIcon() { - #expect(WidgetMetricDisplay.choices(for: "percent") == [.icon, .standard, .value, .meter, .graph, .custom]) + #expect(WidgetMetricDisplay.choices(for: "percent") == [.icon, .standard, .value, .meter, .labelValueMeter, .graph, .custom]) #expect(WidgetMetricDisplay.icon.layout(for: ["percent"]) == .null) #expect(WidgetMetricDisplay.current(nil, sources: ["percent"]) == .icon) let battery: ConfigurationValue = .object(["type": .string("battery")]) diff --git a/Tests/StableBarTests/DiskTests.swift b/Tests/StableBarTests/DiskTests.swift index 8de12822..d3af40ae 100644 --- a/Tests/StableBarTests/DiskTests.swift +++ b/Tests/StableBarTests/DiskTests.swift @@ -84,7 +84,7 @@ func diskStateIsStrictlyAboveItsThreshold(available: Int64, state: String) { } @Test func diskDisplayOffersMeterAndValueButNoGraph() throws { - #expect(WidgetMetricDisplay.choices(for: "disk") == [.standard, .icon, .value, .meter, .custom]) + #expect(WidgetMetricDisplay.choices(for: "disk") == [.standard, .icon, .value, .meter, .labelValueMeter, .custom]) #expect(WidgetMetricDisplay.standard.layout(for: ["disk"]) == .null) #expect(WidgetMetricDisplay.current(nil, sources: ["disk"]) == .standard) for choice in WidgetMetricDisplay.choices(for: "disk") where choice != .custom { diff --git a/Tests/StableBarTests/MetricDisplayTests.swift b/Tests/StableBarTests/MetricDisplayTests.swift new file mode 100644 index 00000000..f21a54f8 --- /dev/null +++ b/Tests/StableBarTests/MetricDisplayTests.swift @@ -0,0 +1,65 @@ +import Foundation +import Testing +@testable import StableBar + +@Test(arguments: ["percent", "volume", "cpu", "memory", "disk"]) +func labeledMetricColumnsRoundTripAndKeepTheExistingDefaults(source: String) throws { + let choices = WidgetMetricDisplay.choices(for: source) + let meter = try #require(choices.firstIndex(of: .meter)) + #expect(choices[meter + 1] == .labelValueMeter) + let layout = try #require(WidgetMetricDisplay.labelValueMeter.layout(for: [source])) + #expect(WidgetMetricDisplay.current(layout, sources: [source]) == .labelValueMeter) + let block = try layout.decoded(PopupBlock.self) + guard case let .column(children) = block.content else { Issue.record("Expected a metric column"); return } + #expect(block.style.width == 73) + guard case let .row(header) = children[0].content, case let .text(label) = header[0].content else { + Issue.record("Expected a label and value header"); return + } + #expect(label == ["percent": "BAT", "volume": "VOL", "cpu": "CPU", "memory": "MEM", "disk": "DISK"][source]) + #expect(header[0].role == .key) + #expect(header[1].alignment == .trailing) + #expect(header[1].style.width == 37) + guard case let .column(meter) = children[1].content, + case let .progress(metric, height, _) = meter[0].content else { Issue.record("Expected a meter"); return } + #expect(metric == source) + #expect(height == 4) + #expect(meter[0].role == .meter) + #expect(children[1].style.paddingTop == 2) + #expect(WidgetMetricDisplay.current(nil, sources: [source]) != .labelValueMeter) +} + +@Test func labeledSystemMetricsKeepTheirOrderAndCustomSizingStaysCustom() throws { + for metrics in WidgetSystemMetrics.allCases { + let layout = try #require(WidgetMetricDisplay.labelValueMeter.layout(for: metrics.sources)) + #expect(WidgetSystemMetrics.current(layout) == metrics) + #expect(WidgetMetricDisplay.current(layout, sources: metrics.sources) == .labelValueMeter) + if metrics.sources.count == 2 { + let block = try layout.decoded(PopupBlock.self) + #expect(block.style.spacing == 14) + } + guard case var .object(changed) = layout else { continue } + changed["style"] = .object(["spacing": .number(20)]) + #expect(WidgetMetricDisplay.current(.object(changed), sources: metrics.sources) == .custom) + } +} + +@Test @MainActor func aMetricDisplayEditStaysInItsProfileAndCanBeUndone() throws { + let fixture = try ThemeGalleryFixture(#"{"widgets":[{"id":"disk","type":"disk","position":"right","onClick":"open-disk"}],"profiles":[{"name":"fern","configuration":{}}]}"#) + defer { fixture.close() } + let store = try fixture.store() + defer { store.stop() } + let editor = ConfigurationEditor(store: store) + editor.editBar(for: "fern") + let before = try fixture.document() + editor.set(["layout": try #require(WidgetMetricDisplay.labelValueMeter.layout(for: ["disk"]))], for: "disk") + try editor.history.flush() + #expect(editor.error == nil) + #expect(store.configuration?.widgets.first?.position == .right) + #expect(store.configuration?.widgets.first?.onClick == "open-disk") + #expect(WidgetMetricDisplay.current(editor.properties(for: "disk")["layout"], sources: ["disk"]) == .labelValueMeter) + let document = try fixture.document() + let widgets = try #require(document["widgets"]).decoded([[String: ConfigurationValue]].self) + #expect(widgets[0]["layout"] == nil) + editor.undo() + #expect(try fixture.document() == before) +} diff --git a/docs/create-a-widget.md b/docs/create-a-widget.md index b1171c5d..83129558 100644 --- a/docs/create-a-widget.md +++ b/docs/create-a-widget.md @@ -118,7 +118,9 @@ dist/StableBar.app/Contents/MacOS/StableBar --config "$scratch/config.json" A widget without `layout` draws a default layout made of the same blocks: a `row` of its icon (`symbol`) and text (`field`), at least a line of text tall even when it shows only the icon. Its digits all have the same width, so a number that changes, such as a CPU percentage, doesn't resize the widget. Battery draws a [`battery`](popups.md) block, like the battery in the macOS menu bar: its fill follows the charge and turns red at 10 % or less on battery power, a bolt shows it charging, and a plug shows the Mac on its adapter without charging. An orange badge appears when macOS recommends servicing the battery, the condition System Settings shows under Battery Health. Its percentage is in its tooltip, with the time left or until full and “Service recommended” when it applies. A Mac without a battery shows a plug and AC. Sound shows only its speaker icon, whose waves show the volume: none at zero, then one, two or three. The icon keeps the width of three waves, so the widget doesn't change size between levels. After the volume changes, the new volume fades in beside it for a moment, its digits rolling while it keeps changing, then fades out. Muting hides it at once. Hovering it shows a volume slider, with the volume, that changes the volume as you drag: in a tooltip under the widget, or beside the icon with [Open hover controls inline](#controls-on-hover). Inline, on the right of the bar the slider opens to the icon's left, so the icon stays under the pointer; elsewhere it opens to the right. A Sound widget with a `layout` of its own, including a **Display** choice other than its default, has no slider. The bar animates the Sound widget's width as the volume and the inline slider come and go, unless Reduce Motion is on. Other script and provider widgets whose output has a `value` show a 40 × 16 `graph` before them, and active-app widgets show the app's icon instead of a `symbol`. Workspaces and spacers keep their own views. A `layout` replaces the default layout, so block options work on built-in widgets too, for example an app name that scrolls when it doesn't fit: `"layout": { "type": "field", "field": "text", "scrollSpeed": 30, "style": { "maxWidth": 120 } }`. -For battery, sound, system and disk, **Settings → Bar → Content → Display** offers icon and value, icon only, value only, meter and value, or graph and value. Battery starts with icon only, its default, and its icon in every choice is its battery; sound starts with icon, value on change, its default, and system with graph and value. Disk starts with icon and value, and has no graph, since it keeps no history. For system, **Shows** chooses **CPU**, its default, **Memory**, **CPU and memory** or **Memory and CPU**; each gets its own symbol and value, drawn as Display says, and memory's graph draws `series.memory`. This also works with named battery/audio/system/disk providers and package widgets. Choices use the existing `layout` configuration and support Undo; a hand-written layout stays marked **Custom layout** until you choose another display. +For battery, sound, system and disk, **Settings → Bar → Content → Display** offers icon and value, icon only, value only, meter and value, **Label, value and meter**, or graph and value. Battery starts with icon only, its default, and its icon in every choice is its battery; sound starts with icon, value on change, its default, and system with graph and value. Disk starts with icon and value, and has no graph, since it keeps no history. For system, **Shows** chooses **CPU**, its default, **Memory**, **CPU and memory** or **Memory and CPU**; each gets its own symbol and value, drawn as Display says, and memory's graph draws `series.memory`. This also works with named battery/audio/system/disk providers and package widgets. Choices use the existing `layout` configuration and support Undo; a hand-written layout stays marked **Custom layout** until you choose another display. + +**Label, value and meter** puts a short label and a right-aligned percentage above a progress line. System keeps CPU and memory in the selected order, each in its own column. This is a widget layout choice, so it stays selected when you change themes. `overlay` uses the same blocks, aligned to the widget's bottom edge. It occupies no space and does not intercept clicks. This supports an underline, playback progress or a graph underneath the label. diff --git a/scenes/labeled-metric-built-in.json b/scenes/labeled-metric-built-in.json new file mode 100644 index 00000000..ae348831 --- /dev/null +++ b/scenes/labeled-metric-built-in.json @@ -0,0 +1,250 @@ +{ + "$schema": "../scene.schema.json", + "configuration": { + "theme": {"id": "built-in"}, + "widgets": [ + { + "id": "system-9", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "style": {"spacing": 14}, + "children": [ + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} + ] + }, + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + { + "type": "row", + "style": {"spacing": 0, "width": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} + ] + } + ] + }, + "provider": "system-9" + }, + { + "id": "disk-9", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + ] + }, + "provider": "disk-9" + }, + { + "id": "battery-9", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} + ] + }, + "provider": "battery-9" + }, + { + "id": "audio-9", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} + ] + }, + "provider": "audio-9" + }, + { + "id": "system-100", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "style": {"spacing": 14}, + "children": [ + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} + ] + }, + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + { + "type": "row", + "style": {"spacing": 0, "width": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} + ] + } + ] + }, + "provider": "system-100" + }, + { + "id": "disk-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + ] + }, + "provider": "disk-100" + }, + { + "id": "battery-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} + ] + }, + "provider": "battery-100" + }, + { + "id": "audio-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} + ] + }, + "provider": "audio-100" + } + ], + "providers": { + "system-9": {"type": "system"}, + "disk-9": {"type": "disk"}, + "battery-9": {"type": "battery"}, + "audio-9": {"type": "audio"}, + "system-100": {"type": "system"}, + "disk-100": {"type": "disk"}, + "battery-100": {"type": "battery"}, + "audio-100": {"type": "audio"} + } + }, + "outputs": { + "system-9": {"text": "9%", "value": 0.09, "values": {"cpu": 0.09, "memory": 0.09}, "fields": {"memory": "9"}}, + "disk-9": {"text": "9%", "value": 0.09, "values": {"disk": 0.09}, "fields": {"memory": "9"}}, + "battery-9": {"text": "9%", "value": 0.09, "values": {"percent": 0.09}, "fields": {"memory": "9"}}, + "audio-9": {"text": "9%", "value": 0.09, "values": {"volume": 0.09}, "fields": {"memory": "9"}}, + "system-100": {"text": "100%", "value": 1.0, "values": {"cpu": 1.0, "memory": 1.0}, "fields": {"memory": "100"}}, + "disk-100": {"text": "100%", "value": 1.0, "values": {"disk": 1.0}, "fields": {"memory": "100"}}, + "battery-100": {"text": "100%", "value": 1.0, "values": {"percent": 1.0}, "fields": {"memory": "100"}}, + "audio-100": {"text": "100%", "value": 1.0, "values": {"volume": 1.0}, "fields": {"memory": "100"}} + }, + "draw": "bar", + "width": 1280 +} diff --git a/scenes/labeled-metric-island.json b/scenes/labeled-metric-island.json new file mode 100644 index 00000000..e4fe1ff1 --- /dev/null +++ b/scenes/labeled-metric-island.json @@ -0,0 +1,250 @@ +{ + "$schema": "../scene.schema.json", + "configuration": { + "theme": {"id": "island"}, + "widgets": [ + { + "id": "system-9", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "style": {"spacing": 14}, + "children": [ + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} + ] + }, + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + { + "type": "row", + "style": {"spacing": 0, "width": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} + ] + } + ] + }, + "provider": "system-9" + }, + { + "id": "disk-9", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + ] + }, + "provider": "disk-9" + }, + { + "id": "battery-9", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} + ] + }, + "provider": "battery-9" + }, + { + "id": "audio-9", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} + ] + }, + "provider": "audio-9" + }, + { + "id": "system-100", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "style": {"spacing": 14}, + "children": [ + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} + ] + }, + { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + { + "type": "row", + "style": {"spacing": 0, "width": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} + ] + } + ] + }, + "provider": "system-100" + }, + { + "id": "disk-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + ] + }, + "provider": "disk-100" + }, + { + "id": "battery-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} + ] + }, + "provider": "battery-100" + }, + { + "id": "audio-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} + ] + }, + "provider": "audio-100" + } + ], + "providers": { + "system-9": {"type": "system"}, + "disk-9": {"type": "disk"}, + "battery-9": {"type": "battery"}, + "audio-9": {"type": "audio"}, + "system-100": {"type": "system"}, + "disk-100": {"type": "disk"}, + "battery-100": {"type": "battery"}, + "audio-100": {"type": "audio"} + } + }, + "outputs": { + "system-9": {"text": "9%", "value": 0.09, "values": {"cpu": 0.09, "memory": 0.09}, "fields": {"memory": "9"}}, + "disk-9": {"text": "9%", "value": 0.09, "values": {"disk": 0.09}, "fields": {"memory": "9"}}, + "battery-9": {"text": "9%", "value": 0.09, "values": {"percent": 0.09}, "fields": {"memory": "9"}}, + "audio-9": {"text": "9%", "value": 0.09, "values": {"volume": 0.09}, "fields": {"memory": "9"}}, + "system-100": {"text": "100%", "value": 1.0, "values": {"cpu": 1.0, "memory": 1.0}, "fields": {"memory": "100"}}, + "disk-100": {"text": "100%", "value": 1.0, "values": {"disk": 1.0}, "fields": {"memory": "100"}}, + "battery-100": {"text": "100%", "value": 1.0, "values": {"percent": 1.0}, "fields": {"memory": "100"}}, + "audio-100": {"text": "100%", "value": 1.0, "values": {"volume": 1.0}, "fields": {"memory": "100"}} + }, + "draw": "bar", + "width": 1280 +} diff --git a/scenes/settings-labeled-metric.json b/scenes/settings-labeled-metric.json new file mode 100644 index 00000000..9c926555 --- /dev/null +++ b/scenes/settings-labeled-metric.json @@ -0,0 +1,54 @@ +{ + "$schema": "../scene.schema.json", + "configuration": { + "theme": {"id": "built-in"}, + "widgets": [ + { + "id": "disk-100", + "type": "provider", + "position": "left", + "layout": { + "type": "column", + "style": {"spacing": 1, "width": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + ] + }, + {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + ] + }, + "provider": "disk-100" + } + ], + "providers": { + "system-9": {"type": "system"}, + "disk-9": {"type": "disk"}, + "battery-9": {"type": "battery"}, + "audio-9": {"type": "audio"}, + "system-100": {"type": "system"}, + "disk-100": {"type": "disk"}, + "battery-100": {"type": "battery"}, + "audio-100": {"type": "audio"} + } + }, + "outputs": { + "system-9": {"text": "9%", "value": 0.09, "values": {"cpu": 0.09, "memory": 0.09}, "fields": {"memory": "9"}}, + "disk-9": {"text": "9%", "value": 0.09, "values": {"disk": 0.09}, "fields": {"memory": "9"}}, + "battery-9": {"text": "9%", "value": 0.09, "values": {"percent": 0.09}, "fields": {"memory": "9"}}, + "audio-9": {"text": "9%", "value": 0.09, "values": {"volume": 0.09}, "fields": {"memory": "9"}}, + "system-100": {"text": "100%", "value": 1.0, "values": {"cpu": 1.0, "memory": 1.0}, "fields": {"memory": "100"}}, + "disk-100": {"text": "100%", "value": 1.0, "values": {"disk": 1.0}, "fields": {"memory": "100"}}, + "battery-100": {"text": "100%", "value": 1.0, "values": {"percent": 1.0}, "fields": {"memory": "100"}}, + "audio-100": {"text": "100%", "value": 1.0, "values": {"volume": 1.0}, "fields": {"memory": "100"}} + }, + "draw": "settings", + "width": 680, + "widget": "disk-100", + "tab": "content", + "height": 640 +} From d10fad63c6ebbb10dfc3d7bcc548bf0468e3678c Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis Date: Tue, 17 Nov 2026 20:17:26 +0100 Subject: [PATCH 2/3] fix: let another Display choice replace label, value and meter cleanly Wrap the choice in a plain row, as the other choices are, so an edit that merges the next choice into it leaves no width or spacing behind, in the main file or in a profile. Use minimum widths, so a theme with a larger font, such as Catppuccin, widens the column instead of cutting 100% short, and draw the second scene with Catppuccin instead of the retired Island. Test switching to every other choice, rows with a style of their own, and the per-metric warnings of the two columns. --- Sources/StableBar/WidgetSettings.swift | 15 +- Tests/StableBarTests/MetricDisplayTests.swift | 75 ++- docs/create-a-widget.md | 4 +- scenes/labeled-metric-built-in.json | 380 ++++++++++++---- scenes/labeled-metric-catppuccin.json | 430 ++++++++++++++++++ scenes/labeled-metric-island.json | 250 ---------- scenes/settings-labeled-metric.json | 87 +++- 7 files changed, 860 insertions(+), 381 deletions(-) create mode 100644 scenes/labeled-metric-catppuccin.json delete mode 100644 scenes/labeled-metric-island.json diff --git a/Sources/StableBar/WidgetSettings.swift b/Sources/StableBar/WidgetSettings.swift index 5a63e135..976fb627 100644 --- a/Sources/StableBar/WidgetSettings.swift +++ b/Sources/StableBar/WidgetSettings.swift @@ -184,9 +184,12 @@ enum WidgetMetricDisplay: String, CaseIterable { case .standard where sources == ["disk"]: return .null case .custom: return nil case .labelValueMeter: + // A plain row on top, like the other choices: editing merges a new layout into the old one, so a top-level + // style here would stay behind on the next choice. let columns = sources.map(metricColumn) - return columns.count == 1 ? columns[0] + let content = columns.count == 1 ? columns[0] : .object(["type": .string("row"), "style": .object(["spacing": .number(14)]), "children": .array(columns)]) + return .object(["type": .string("row"), "children": .array([content])]) default: return .object(["type": .string("row"), "children": .array(sources.flatMap(blocks))]) } } @@ -221,21 +224,23 @@ enum WidgetMetricDisplay: String, CaseIterable { : .object(["type": .string("field"), "field": .string("text")]) } + /// A label and value over a meter. The widths are minimums: 100% fits 37 points in Built-in's and Fern's fonts, and a + /// theme with a larger or bolder font, such as Catppuccin's 13 pt medium, widens the column instead of cutting it. private func metricColumn(for source: String) -> ConfigurationValue { let label = ["percent": "BAT", "volume": "VOL", "cpu": "CPU", "memory": "MEM", "disk": "DISK"][source] ?? source.uppercased() var value = Self.valueBlock(for: source) if case var .object(properties) = value { var style: [String: ConfigurationValue] = [:] if case let .object(existing)? = properties["style"] { style = existing } - style["width"] = .number(37) + style["minWidth"] = .number(37) properties["style"] = .object(style) properties["alignment"] = .string("trailing") value = .object(properties) } - return .object(["type": .string("column"), "style": .object(["spacing": .number(1), "width": .number(73)]), "children": .array([ + return .object(["type": .string("column"), "style": .object(["spacing": .number(1), "minWidth": .number(73)]), "children": .array([ .object(["type": .string("row"), "style": .object(["spacing": .number(0)]), "children": .array([ .object(["type": .string("text"), "text": .string(label), "role": .string("key"), "alignment": .string("leading"), - "style": .object(["fontWeight": .string("medium"), "width": .number(36)])]), value + "style": .object(["fontWeight": .string("medium"), "minWidth": .number(36)])]), value ])]), .object(["type": .string("column"), "style": .object(["paddingTop": .number(2)]), "children": .array([ .object(["type": .string("progress"), "source": .string(source), "height": .number(4), "role": .string("meter")]) @@ -245,10 +250,8 @@ enum WidgetMetricDisplay: String, CaseIterable { static func current(_ layout: ConfigurationValue?, sources: [String]) -> Self { if layout == nil || layout == .null { return choices(for: sources[0])[0] } - if layout == Self.labelValueMeter.layout(for: sources) { return .labelValueMeter } guard case let .object(properties) = layout, properties["type"] == .string("row") else { return .custom } return choices(for: sources[0]).first { - guard $0 != .labelValueMeter else { return false } guard case let .object(candidate)? = $0.layout(for: sources) else { return false } return candidate["children"] == properties["children"] } ?? .custom diff --git a/Tests/StableBarTests/MetricDisplayTests.swift b/Tests/StableBarTests/MetricDisplayTests.swift index f21a54f8..2b46ffad 100644 --- a/Tests/StableBarTests/MetricDisplayTests.swift +++ b/Tests/StableBarTests/MetricDisplayTests.swift @@ -9,16 +9,20 @@ func labeledMetricColumnsRoundTripAndKeepTheExistingDefaults(source: String) thr #expect(choices[meter + 1] == .labelValueMeter) let layout = try #require(WidgetMetricDisplay.labelValueMeter.layout(for: [source])) #expect(WidgetMetricDisplay.current(layout, sources: [source]) == .labelValueMeter) - let block = try layout.decoded(PopupBlock.self) - guard case let .column(children) = block.content else { Issue.record("Expected a metric column"); return } - #expect(block.style.width == 73) + let row = try layout.decoded(PopupBlock.self) + guard case let .row(top) = row.content, top.count == 1, case let .column(children) = top[0].content else { + Issue.record("Expected a metric column in a plain row"); return + } + #expect(row.style == WidgetStyle()) + let block = top[0] + #expect(block.style.minWidth == 73) guard case let .row(header) = children[0].content, case let .text(label) = header[0].content else { Issue.record("Expected a label and value header"); return } #expect(label == ["percent": "BAT", "volume": "VOL", "cpu": "CPU", "memory": "MEM", "disk": "DISK"][source]) #expect(header[0].role == .key) #expect(header[1].alignment == .trailing) - #expect(header[1].style.width == 37) + #expect(header[1].style.minWidth == 37) guard case let .column(meter) = children[1].content, case let .progress(metric, height, _) = meter[0].content else { Issue.record("Expected a meter"); return } #expect(metric == source) @@ -35,10 +39,14 @@ func labeledMetricColumnsRoundTripAndKeepTheExistingDefaults(source: String) thr #expect(WidgetMetricDisplay.current(layout, sources: metrics.sources) == .labelValueMeter) if metrics.sources.count == 2 { let block = try layout.decoded(PopupBlock.self) - #expect(block.style.spacing == 14) + guard case let .row(top) = block.content else { Issue.record("Expected a row"); continue } + #expect(top.first?.style.spacing == 14) } - guard case var .object(changed) = layout else { continue } - changed["style"] = .object(["spacing": .number(20)]) + guard case var .object(changed) = layout, case var .array(children) = changed["children"], + case var .object(content) = children[0] else { continue } + content["style"] = .object(["spacing": .number(20)]) + children[0] = .object(content) + changed["children"] = .array(children) #expect(WidgetMetricDisplay.current(.object(changed), sources: metrics.sources) == .custom) } } @@ -63,3 +71,56 @@ func labeledMetricColumnsRoundTripAndKeepTheExistingDefaults(source: String) thr editor.undo() #expect(try fixture.document() == before) } + +@Test(arguments: [false, true]) @MainActor +func switchingAwayFromLabelValueAndMeterLeavesNothingBehind(inProfile: Bool) throws { + let fixture = try ThemeGalleryFixture(#"{"widgets":[{"id":"disk","type":"disk","position":"right"},{"id":"system","type":"system","position":"right"}],"profiles":[{"name":"fern","configuration":{}}]}"#) + defer { fixture.close() } + let store = try fixture.store() + defer { store.stop() } + let editor = ConfigurationEditor(store: store) + if inProfile { editor.editBar(for: "fern") } + for (id, sources) in [("disk", ["disk"]), ("system", ["memory", "cpu"])] { + for choice in WidgetMetricDisplay.choices(for: sources[0]) where choice != .labelValueMeter && choice != .custom { + editor.set(["layout": try #require(WidgetMetricDisplay.labelValueMeter.layout(for: sources))], for: id) + editor.set(["layout": try #require(choice.layout(for: sources))], for: id) + try editor.history.flush() + #expect(editor.error == nil) + let layout = editor.properties(for: id)["layout"] + #expect(WidgetMetricDisplay.current(layout, sources: sources) == choice, "\(id) \(choice)") + if case .object = choice.layout(for: sources) { #expect(layout == choice.layout(for: sources), "\(id) \(choice)") } + } + } +} + +@Test func aStyledRowKeepsItsChoiceAcrossLabelValueAndMeter() throws { + for sources in [["disk"], ["cpu", "memory"]] { + for choice in [WidgetMetricDisplay.labelValueMeter, .meter] { + guard case var .object(layout) = choice.layout(for: sources) else { Issue.record("Expected a layout"); continue } + layout["style"] = .object(["paddingHorizontal": .number(4)]) + #expect(WidgetMetricDisplay.current(.object(layout), sources: sources) == choice) + } + } +} + +@Test func labeledSystemColumnsWarnEachMetricApart() throws { + for sources in [["cpu", "memory"], ["memory", "cpu"]] { + let configuration = try ConfigurationValue.object([ + "providers": .object(["system": .object(["type": .string("system")])]), + "widgets": .array([.object(["id": .string("system"), "type": .string("system"), "position": .string("right"), + "details": .bool(true), "layout": try #require(WidgetMetricDisplay.labelValueMeter.layout(for: sources))])]) + ]).decoded(Configuration.self) + let widget = configuration.widgets[0] + guard case let .row(top)? = widget.layout?.content, case let .row(columns)? = top.first?.content else { + Issue.record("Expected two columns in a row"); continue + } + #expect(columns.count == 2) + for (cpu, memory) in [(0.95, 0.5), (0.5, 0.95)] { + let output = ScriptOutput(text: "\(Int(cpu * 100))%", icon: "cpu", fields: ["pressure": "normal", "thermal": "nominal"], + values: ["cpu": cpu, "memory": memory]) + let states = widgetDataStates(output, widget: widget, providers: configuration.providers) + let expected = sources.map { ($0 == "cpu" ? cpu : memory) > 0.9 ? "warning" : nil } + #expect(columns.map { StyleStates(data: states.widget, parts: states.parts).scoped(to: $0).data } == expected, "\(sources) cpu \(cpu)") + } + } +} diff --git a/docs/create-a-widget.md b/docs/create-a-widget.md index 83129558..6a9d684b 100644 --- a/docs/create-a-widget.md +++ b/docs/create-a-widget.md @@ -118,9 +118,9 @@ dist/StableBar.app/Contents/MacOS/StableBar --config "$scratch/config.json" A widget without `layout` draws a default layout made of the same blocks: a `row` of its icon (`symbol`) and text (`field`), at least a line of text tall even when it shows only the icon. Its digits all have the same width, so a number that changes, such as a CPU percentage, doesn't resize the widget. Battery draws a [`battery`](popups.md) block, like the battery in the macOS menu bar: its fill follows the charge and turns red at 10 % or less on battery power, a bolt shows it charging, and a plug shows the Mac on its adapter without charging. An orange badge appears when macOS recommends servicing the battery, the condition System Settings shows under Battery Health. Its percentage is in its tooltip, with the time left or until full and “Service recommended” when it applies. A Mac without a battery shows a plug and AC. Sound shows only its speaker icon, whose waves show the volume: none at zero, then one, two or three. The icon keeps the width of three waves, so the widget doesn't change size between levels. After the volume changes, the new volume fades in beside it for a moment, its digits rolling while it keeps changing, then fades out. Muting hides it at once. Hovering it shows a volume slider, with the volume, that changes the volume as you drag: in a tooltip under the widget, or beside the icon with [Open hover controls inline](#controls-on-hover). Inline, on the right of the bar the slider opens to the icon's left, so the icon stays under the pointer; elsewhere it opens to the right. A Sound widget with a `layout` of its own, including a **Display** choice other than its default, has no slider. The bar animates the Sound widget's width as the volume and the inline slider come and go, unless Reduce Motion is on. Other script and provider widgets whose output has a `value` show a 40 × 16 `graph` before them, and active-app widgets show the app's icon instead of a `symbol`. Workspaces and spacers keep their own views. A `layout` replaces the default layout, so block options work on built-in widgets too, for example an app name that scrolls when it doesn't fit: `"layout": { "type": "field", "field": "text", "scrollSpeed": 30, "style": { "maxWidth": 120 } }`. -For battery, sound, system and disk, **Settings → Bar → Content → Display** offers icon and value, icon only, value only, meter and value, **Label, value and meter**, or graph and value. Battery starts with icon only, its default, and its icon in every choice is its battery; sound starts with icon, value on change, its default, and system with graph and value. Disk starts with icon and value, and has no graph, since it keeps no history. For system, **Shows** chooses **CPU**, its default, **Memory**, **CPU and memory** or **Memory and CPU**; each gets its own symbol and value, drawn as Display says, and memory's graph draws `series.memory`. This also works with named battery/audio/system/disk providers and package widgets. Choices use the existing `layout` configuration and support Undo; a hand-written layout stays marked **Custom layout** until you choose another display. +For battery, sound, system and disk, **Settings → Bar → Content → Display** offers icon and value, icon only, value only, meter and value, label, value and meter, or graph and value. Battery starts with icon only, its default, and its icon in every choice is its battery; sound starts with icon, value on change, its default, and system with graph and value. Disk starts with icon and value, and has no graph, since it keeps no history. For system, **Shows** chooses **CPU**, its default, **Memory**, **CPU and memory** or **Memory and CPU**; each gets its own symbol and value, drawn as Display says, and memory's graph draws `series.memory`. This also works with named battery/audio/system/disk providers and package widgets. Choices use the existing `layout` configuration and support Undo; a hand-written layout stays marked **Custom layout** until you choose another display. -**Label, value and meter** puts a short label and a right-aligned percentage above a progress line. System keeps CPU and memory in the selected order, each in its own column. This is a widget layout choice, so it stays selected when you change themes. +**Label, value and meter** puts a short label and a right-aligned percentage on one line, above a progress line. The label uses the `key` role and the line the `meter` role, so a theme styles both, and the column widens when a theme's font needs more room for 100%. System keeps CPU and memory in the selected order, each in its own column. This is a widget layout choice, so it stays selected when you change themes. `overlay` uses the same blocks, aligned to the widget's bottom edge. It occupies no space and does not intercept clicks. This supports an underline, playback progress or a graph underneath the label. diff --git a/scenes/labeled-metric-built-in.json b/scenes/labeled-metric-built-in.json index ae348831..e07fbabc 100644 --- a/scenes/labeled-metric-built-in.json +++ b/scenes/labeled-metric-built-in.json @@ -9,41 +9,66 @@ "position": "left", "layout": { "type": "row", - "style": {"spacing": 14}, "children": [ { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", + "style": {"spacing": 14}, "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "CPU", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}] + } ] }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} - ] - }, - { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, { "type": "row", - "style": {"spacing": 0, "width": 37}, - "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], - "alignment": "trailing" + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "MEM", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + { + "type": "row", + "style": {"spacing": 0, "minWidth": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}] } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} + } ] } ] @@ -55,18 +80,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "DISK", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + } ] }, "provider": "disk-9" @@ -76,18 +116,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "BAT", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} + } ] }, "provider": "battery-9" @@ -97,18 +152,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "VOL", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} + } ] }, "provider": "audio-9" @@ -119,41 +189,66 @@ "position": "left", "layout": { "type": "row", - "style": {"spacing": 14}, "children": [ { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", + "style": {"spacing": 14}, "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "CPU", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}] + } ] }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} - ] - }, - { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, { "type": "row", - "style": {"spacing": 0, "width": 37}, - "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], - "alignment": "trailing" + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "MEM", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + { + "type": "row", + "style": {"spacing": 0, "minWidth": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}] } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} + } ] } ] @@ -165,18 +260,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "DISK", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + } ] }, "provider": "disk-100" @@ -186,18 +296,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "BAT", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} + } ] }, "provider": "battery-100" @@ -207,18 +332,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "VOL", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} + } ] }, "provider": "audio-100" @@ -236,14 +376,54 @@ } }, "outputs": { - "system-9": {"text": "9%", "value": 0.09, "values": {"cpu": 0.09, "memory": 0.09}, "fields": {"memory": "9"}}, - "disk-9": {"text": "9%", "value": 0.09, "values": {"disk": 0.09}, "fields": {"memory": "9"}}, - "battery-9": {"text": "9%", "value": 0.09, "values": {"percent": 0.09}, "fields": {"memory": "9"}}, - "audio-9": {"text": "9%", "value": 0.09, "values": {"volume": 0.09}, "fields": {"memory": "9"}}, - "system-100": {"text": "100%", "value": 1.0, "values": {"cpu": 1.0, "memory": 1.0}, "fields": {"memory": "100"}}, - "disk-100": {"text": "100%", "value": 1.0, "values": {"disk": 1.0}, "fields": {"memory": "100"}}, - "battery-100": {"text": "100%", "value": 1.0, "values": {"percent": 1.0}, "fields": {"memory": "100"}}, - "audio-100": {"text": "100%", "value": 1.0, "values": {"volume": 1.0}, "fields": {"memory": "100"}} + "system-9": { + "text": "9%", + "value": 0.09, + "values": {"cpu": 0.09, "memory": 0.09}, + "fields": {"memory": "9"} + }, + "disk-9": { + "text": "9%", + "value": 0.09, + "values": {"disk": 0.09}, + "fields": {"memory": "9"} + }, + "battery-9": { + "text": "9%", + "value": 0.09, + "values": {"percent": 0.09}, + "fields": {"memory": "9"} + }, + "audio-9": { + "text": "9%", + "value": 0.09, + "values": {"volume": 0.09}, + "fields": {"memory": "9"} + }, + "system-100": { + "text": "100%", + "value": 1.0, + "values": {"cpu": 1.0, "memory": 1.0}, + "fields": {"memory": "100"} + }, + "disk-100": { + "text": "100%", + "value": 1.0, + "values": {"disk": 1.0}, + "fields": {"memory": "100"} + }, + "battery-100": { + "text": "100%", + "value": 1.0, + "values": {"percent": 1.0}, + "fields": {"memory": "100"} + }, + "audio-100": { + "text": "100%", + "value": 1.0, + "values": {"volume": 1.0}, + "fields": {"memory": "100"} + } }, "draw": "bar", "width": 1280 diff --git a/scenes/labeled-metric-catppuccin.json b/scenes/labeled-metric-catppuccin.json new file mode 100644 index 00000000..1750fe88 --- /dev/null +++ b/scenes/labeled-metric-catppuccin.json @@ -0,0 +1,430 @@ +{ + "$schema": "../scene.schema.json", + "configuration": { + "theme": {"id": "catppuccin"}, + "widgets": [ + { + "id": "system-9", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "row", + "style": {"spacing": 14}, + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "CPU", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}] + } + ] + }, + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "MEM", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + { + "type": "row", + "style": {"spacing": 0, "minWidth": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}] + } + ] + } + ] + } + ] + }, + "provider": "system-9" + }, + { + "id": "disk-9", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "DISK", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}] + } + ] + } + ] + }, + "provider": "disk-9" + }, + { + "id": "battery-9", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "BAT", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}] + } + ] + } + ] + }, + "provider": "battery-9" + }, + { + "id": "audio-9", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "VOL", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}] + } + ] + } + ] + }, + "provider": "audio-9" + }, + { + "id": "system-100", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "row", + "style": {"spacing": 14}, + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "CPU", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}] + } + ] + }, + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "MEM", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + { + "type": "row", + "style": {"spacing": 0, "minWidth": 37}, + "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], + "alignment": "trailing" + } + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}] + } + ] + } + ] + } + ] + }, + "provider": "system-100" + }, + { + "id": "disk-100", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "DISK", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}] + } + ] + } + ] + }, + "provider": "disk-100" + }, + { + "id": "battery-100", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "BAT", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}] + } + ] + } + ] + }, + "provider": "battery-100" + }, + { + "id": "audio-100", + "type": "provider", + "position": "left", + "layout": { + "type": "row", + "children": [ + { + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, + "children": [ + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "VOL", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}] + } + ] + } + ] + }, + "provider": "audio-100" + } + ], + "providers": { + "system-9": {"type": "system"}, + "disk-9": {"type": "disk"}, + "battery-9": {"type": "battery"}, + "audio-9": {"type": "audio"}, + "system-100": {"type": "system"}, + "disk-100": {"type": "disk"}, + "battery-100": {"type": "battery"}, + "audio-100": {"type": "audio"} + } + }, + "outputs": { + "system-9": { + "text": "9%", + "value": 0.09, + "values": {"cpu": 0.09, "memory": 0.09}, + "fields": {"memory": "9"} + }, + "disk-9": { + "text": "9%", + "value": 0.09, + "values": {"disk": 0.09}, + "fields": {"memory": "9"} + }, + "battery-9": { + "text": "9%", + "value": 0.09, + "values": {"percent": 0.09}, + "fields": {"memory": "9"} + }, + "audio-9": { + "text": "9%", + "value": 0.09, + "values": {"volume": 0.09}, + "fields": {"memory": "9"} + }, + "system-100": { + "text": "100%", + "value": 1.0, + "values": {"cpu": 1.0, "memory": 1.0}, + "fields": {"memory": "100"} + }, + "disk-100": { + "text": "100%", + "value": 1.0, + "values": {"disk": 1.0}, + "fields": {"memory": "100"} + }, + "battery-100": { + "text": "100%", + "value": 1.0, + "values": {"percent": 1.0}, + "fields": {"memory": "100"} + }, + "audio-100": { + "text": "100%", + "value": 1.0, + "values": {"volume": 1.0}, + "fields": {"memory": "100"} + } + }, + "draw": "bar", + "width": 1280 +} diff --git a/scenes/labeled-metric-island.json b/scenes/labeled-metric-island.json deleted file mode 100644 index e4fe1ff1..00000000 --- a/scenes/labeled-metric-island.json +++ /dev/null @@ -1,250 +0,0 @@ -{ - "$schema": "../scene.schema.json", - "configuration": { - "theme": {"id": "island"}, - "widgets": [ - { - "id": "system-9", - "type": "provider", - "position": "left", - "layout": { - "type": "row", - "style": {"spacing": 14}, - "children": [ - { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} - ] - }, - { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - { - "type": "row", - "style": {"spacing": 0, "width": 37}, - "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], - "alignment": "trailing" - } - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} - ] - } - ] - }, - "provider": "system-9" - }, - { - "id": "disk-9", - "type": "provider", - "position": "left", - "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} - ] - }, - "provider": "disk-9" - }, - { - "id": "battery-9", - "type": "provider", - "position": "left", - "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} - ] - }, - "provider": "battery-9" - }, - { - "id": "audio-9", - "type": "provider", - "position": "left", - "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} - ] - }, - "provider": "audio-9" - }, - { - "id": "system-100", - "type": "provider", - "position": "left", - "layout": { - "type": "row", - "style": {"spacing": 14}, - "children": [ - { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "CPU", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "cpu", "height": 4, "role": "meter"}]} - ] - }, - { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "MEM", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - { - "type": "row", - "style": {"spacing": 0, "width": 37}, - "children": [{"type": "field", "field": "memory"}, {"type": "text", "text": "%"}], - "alignment": "trailing" - } - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "memory", "height": 4, "role": "meter"}]} - ] - } - ] - }, - "provider": "system-100" - }, - { - "id": "disk-100", - "type": "provider", - "position": "left", - "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} - ] - }, - "provider": "disk-100" - }, - { - "id": "battery-100", - "type": "provider", - "position": "left", - "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "BAT", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "percent", "height": 4, "role": "meter"}]} - ] - }, - "provider": "battery-100" - }, - { - "id": "audio-100", - "type": "provider", - "position": "left", - "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, - "children": [ - { - "type": "row", - "style": {"spacing": 0}, - "children": [ - {"type": "text", "text": "VOL", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} - ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "volume", "height": 4, "role": "meter"}]} - ] - }, - "provider": "audio-100" - } - ], - "providers": { - "system-9": {"type": "system"}, - "disk-9": {"type": "disk"}, - "battery-9": {"type": "battery"}, - "audio-9": {"type": "audio"}, - "system-100": {"type": "system"}, - "disk-100": {"type": "disk"}, - "battery-100": {"type": "battery"}, - "audio-100": {"type": "audio"} - } - }, - "outputs": { - "system-9": {"text": "9%", "value": 0.09, "values": {"cpu": 0.09, "memory": 0.09}, "fields": {"memory": "9"}}, - "disk-9": {"text": "9%", "value": 0.09, "values": {"disk": 0.09}, "fields": {"memory": "9"}}, - "battery-9": {"text": "9%", "value": 0.09, "values": {"percent": 0.09}, "fields": {"memory": "9"}}, - "audio-9": {"text": "9%", "value": 0.09, "values": {"volume": 0.09}, "fields": {"memory": "9"}}, - "system-100": {"text": "100%", "value": 1.0, "values": {"cpu": 1.0, "memory": 1.0}, "fields": {"memory": "100"}}, - "disk-100": {"text": "100%", "value": 1.0, "values": {"disk": 1.0}, "fields": {"memory": "100"}}, - "battery-100": {"text": "100%", "value": 1.0, "values": {"percent": 1.0}, "fields": {"memory": "100"}}, - "audio-100": {"text": "100%", "value": 1.0, "values": {"volume": 1.0}, "fields": {"memory": "100"}} - }, - "draw": "bar", - "width": 1280 -} diff --git a/scenes/settings-labeled-metric.json b/scenes/settings-labeled-metric.json index 9c926555..8f0e0572 100644 --- a/scenes/settings-labeled-metric.json +++ b/scenes/settings-labeled-metric.json @@ -8,18 +8,33 @@ "type": "provider", "position": "left", "layout": { - "type": "column", - "style": {"spacing": 1, "width": 73}, + "type": "row", "children": [ { - "type": "row", - "style": {"spacing": 0}, + "type": "column", + "style": {"spacing": 1, "minWidth": 73}, "children": [ - {"type": "text", "text": "DISK", "role": "key", "alignment": "leading", "style": {"fontWeight": "medium", "width": 36}}, - {"type": "field", "field": "text", "alignment": "trailing", "style": {"width": 37}} + { + "type": "row", + "style": {"spacing": 0}, + "children": [ + { + "type": "text", + "text": "DISK", + "role": "key", + "alignment": "leading", + "style": {"fontWeight": "medium", "minWidth": 36} + }, + {"type": "field", "field": "text", "alignment": "trailing", "style": {"minWidth": 37}} + ] + }, + { + "type": "column", + "style": {"paddingTop": 2}, + "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}] + } ] - }, - {"type": "column", "style": {"paddingTop": 2}, "children": [{"type": "progress", "source": "disk", "height": 4, "role": "meter"}]} + } ] }, "provider": "disk-100" @@ -37,14 +52,54 @@ } }, "outputs": { - "system-9": {"text": "9%", "value": 0.09, "values": {"cpu": 0.09, "memory": 0.09}, "fields": {"memory": "9"}}, - "disk-9": {"text": "9%", "value": 0.09, "values": {"disk": 0.09}, "fields": {"memory": "9"}}, - "battery-9": {"text": "9%", "value": 0.09, "values": {"percent": 0.09}, "fields": {"memory": "9"}}, - "audio-9": {"text": "9%", "value": 0.09, "values": {"volume": 0.09}, "fields": {"memory": "9"}}, - "system-100": {"text": "100%", "value": 1.0, "values": {"cpu": 1.0, "memory": 1.0}, "fields": {"memory": "100"}}, - "disk-100": {"text": "100%", "value": 1.0, "values": {"disk": 1.0}, "fields": {"memory": "100"}}, - "battery-100": {"text": "100%", "value": 1.0, "values": {"percent": 1.0}, "fields": {"memory": "100"}}, - "audio-100": {"text": "100%", "value": 1.0, "values": {"volume": 1.0}, "fields": {"memory": "100"}} + "system-9": { + "text": "9%", + "value": 0.09, + "values": {"cpu": 0.09, "memory": 0.09}, + "fields": {"memory": "9"} + }, + "disk-9": { + "text": "9%", + "value": 0.09, + "values": {"disk": 0.09}, + "fields": {"memory": "9"} + }, + "battery-9": { + "text": "9%", + "value": 0.09, + "values": {"percent": 0.09}, + "fields": {"memory": "9"} + }, + "audio-9": { + "text": "9%", + "value": 0.09, + "values": {"volume": 0.09}, + "fields": {"memory": "9"} + }, + "system-100": { + "text": "100%", + "value": 1.0, + "values": {"cpu": 1.0, "memory": 1.0}, + "fields": {"memory": "100"} + }, + "disk-100": { + "text": "100%", + "value": 1.0, + "values": {"disk": 1.0}, + "fields": {"memory": "100"} + }, + "battery-100": { + "text": "100%", + "value": 1.0, + "values": {"percent": 1.0}, + "fields": {"memory": "100"} + }, + "audio-100": { + "text": "100%", + "value": 1.0, + "values": {"volume": 1.0}, + "fields": {"memory": "100"} + } }, "draw": "settings", "width": 680, From 46f7188dd31758137ff420a2f79381d4626287fe Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis Date: Tue, 17 Nov 2026 23:01:09 +0100 Subject: [PATCH 3/3] test: save label, value and meter before switching to another choice Settings merges an edit of the same paths into the pending one, so the test now saves the labeled layout first, as picking a choice does, and switches away from what the file holds. --- Tests/StableBarTests/MetricDisplayTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/StableBarTests/MetricDisplayTests.swift b/Tests/StableBarTests/MetricDisplayTests.swift index 2b46ffad..7fad7e6e 100644 --- a/Tests/StableBarTests/MetricDisplayTests.swift +++ b/Tests/StableBarTests/MetricDisplayTests.swift @@ -83,6 +83,8 @@ func switchingAwayFromLabelValueAndMeterLeavesNothingBehind(inProfile: Bool) thr for (id, sources) in [("disk", ["disk"]), ("system", ["memory", "cpu"])] { for choice in WidgetMetricDisplay.choices(for: sources[0]) where choice != .labelValueMeter && choice != .custom { editor.set(["layout": try #require(WidgetMetricDisplay.labelValueMeter.layout(for: sources))], for: id) + // Saved first: Settings merges an edit of the same paths into the pending one, which never reaches the file. + try editor.history.flush() editor.set(["layout": try #require(choice.layout(for: sources))], for: id) try editor.history.flush() #expect(editor.error == nil)