Skip to content

Commit 646a400

Browse files
committed
feat: auto-convert pixels to percentage on Todo Mode unit change
1 parent 8481990 commit 646a400

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Rectangle/PrefsWindow/SettingsViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,13 @@ class SettingsViewController: NSViewController {
152152
Logger.log("Expected a pop up button to have a selected item with a valid tag matching a value of TodoSidebarWidthUnit. Got: \(String(describing: tag))")
153153
return
154154
}
155-
156155
Defaults.todoSidebarWidthUnit.value = unit
157156

157+
let toPixels = (unit == .pixels)
158+
let newValue = TodoManager.convertWidth(Defaults.todoSidebarWidth.value, toPixels: toPixels)
159+
Defaults.todoSidebarWidth.value = newValue
160+
todoAppWidthField.stringValue = String(newValue)
161+
158162
TodoManager.moveAllIfNeeded(false)
159163
}
160164

Rectangle/TodoMode/TodoManager.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ class TodoManager {
246246
}
247247
}
248248

249+
static func convertWidth(_ value: Float, toPixels: Bool) -> Float {
250+
TodoManager.refreshTodoScreen()
251+
guard let screenWidth = TodoManager.todoScreen?.frame.width else { return value }
252+
253+
if toPixels {
254+
return ((value * 0.01) * Float(screenWidth)).rounded()
255+
} else {
256+
return ((value / Float(screenWidth)) * 100).rounded()
257+
}
258+
}
259+
249260
static func execute(parameters: ExecutionParameters) -> Bool {
250261
if [.leftTodo, .rightTodo].contains(parameters.action) {
251262
moveAll()

0 commit comments

Comments
 (0)