Build Status Platforms Matrix

WindowTreatment

WindowTreatment 是一小组类和扩展,旨在帮助处理 NSWindow 及其相关功能。

集成

Swift 包管理器

dependencies: [
    .package(url: "https://github.com/ChimeHQ/WindowTreatment")
]

SwiftUI 视图修饰符

observeCurrentWindow() // puts the current window object into the environment
observeWindowState()   // makes WindowStateKey available in the environment

WindowTitlebarAwareView

一个简单的容器视图,可以更容易地将内容正确定位在宿主 NSWindow 的标题栏下方。 这实际上是一件相当深奥的事情,但当您的 NSWindow 具有透明标题栏时,这可能至关重要。

let titlebarAwareView = WindowTitlebarAwareView()

// myView will always be correctly position below the containing window's
// titlebar region, and react accordingly if the titlebar size/state changes

titlebarAwareView.contentView = myView
// ...

WindowTitlebarAwareViewController

一个包装控制器,在需要将 WindowTitlebarAwareView 与仅接受 NSViewControllers 的系统(例如 NSSplitViewController)一起使用的情况下很有用。

WindowStateObserver

围绕 NSWindow 状态的观察器的包装器,用于 keymain 和选项卡功能。 对于响应这些更改的 UI 更新非常有用。 尤其是选项卡状态,在所有情况下正确观察都非常具有挑战性。

WindowStateAwareView

一个超简单的类,它使用 WindowStateObserver,并为需要根据宿主窗口的主/键状态更改其外观的 NSView 子类提供了一个良好的基础。

ApplicationWindowState

一个跟踪应用程序窗口中更改的类,简化了依赖于所有窗口状态的逻辑。

NSWindow 扩展

尺寸调整便利功能

// simple method to size a window to pleasing dimensions relative to its screen

window.makeReasonableSize()

标题栏透明度助手

// This method also handles the height adjustments needed when removing transparency
window.titlebarTransparentWithFullSizeContent = true

window.usesFullSizeContentView = true

NSView 扩展

窗口状态

self.windowIsMain
self.windowIsKey
self.windowIsOnActiveSpace

贡献和协作

我很乐意收到您的来信! 问题或拉取请求都可以。 Matrix spaceDiscord 都可用于实时帮助,但我强烈倾向于以文档的形式回答。 您也可以在这里找到我。

我更喜欢协作,如果您有类似的项目,我很乐意找到合作的方式。

我更喜欢使用制表符进行缩进,以提高可访问性。 但是,我宁愿您使用您想要的系统并提出 PR,也不要因为空格而犹豫。

通过参与此项目,您同意遵守贡献者行为准则