ps
This commit is contained in:
1 parent
30476a880d
commit
7c8bbe6473
3 files changed
+50
-20
No files matched your search
@@ -80,16 +80,18 @@ final class RenderGLView: NSOpenGLView {
|
||||
|
||||
override func reshape() {
|
||||
super.reshape()
|
||||
otherPrintStderr("RenderGLView reshape bounds \(bounds) backing \(convertToBacking(bounds))")
|
||||
needsDisplay = true
|
||||
renderSet(F.didReshape, true)
|
||||
|
||||
let ps = renderPixelSize(self)
|
||||
renderSet(F.reshapePixelSize, ps)
|
||||
}
|
||||
|
||||
override func viewDidChangeBackingProperties() {
|
||||
super.viewDidChangeBackingProperties()
|
||||
otherPrintStderr("RenderGLView viewDidChangeBackingProperties bounds \(bounds) backing \(convertToBacking(bounds))")
|
||||
needsDisplay = true
|
||||
renderSet(F.didChangeBacking, true)
|
||||
|
||||
let ps = renderPixelSize(self)
|
||||
renderSet(F.backingPixelSize, ps)
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
|
||||
+12
-2
@@ -7,12 +7,12 @@ output:
|
||||
RenderContext:
|
||||
type: context
|
||||
fields:
|
||||
didChangeBacking: Bool
|
||||
backingPixelSize: [Int32]
|
||||
didLaunch: Bool
|
||||
didReshape: Bool
|
||||
didSetup: Bool
|
||||
isReadyToRender: Bool
|
||||
pixelSize: [Int32]
|
||||
reshapePixelSize: [Int32]
|
||||
|
||||
RenderComponent:
|
||||
type: component
|
||||
@@ -32,6 +32,16 @@ RenderComponent:
|
||||
c.recentField == F.didLaunch
|
||||
then:
|
||||
c.pixelSize = [1, 1]
|
||||
2. Upon resize:
|
||||
if:
|
||||
c.recentField == F.reshapePixelSize
|
||||
then:
|
||||
c.pixelSize = c.reshapePixelSize
|
||||
3. Upon DPI change:
|
||||
if:
|
||||
c.recentField == F.backingPixelSize
|
||||
then:
|
||||
c.pixelSize = c.backingPixelSize
|
||||
|
||||
RootComponent:
|
||||
type: component
|
||||
|
||||
@@ -119,37 +119,34 @@ func registerOneliners<T>(
|
||||
|
||||
// Context field names for static type check
|
||||
public struct F {
|
||||
public static let backingPixelSize = "backingPixelSize"
|
||||
public static let count = "count"
|
||||
public static let countText = "countText"
|
||||
public static let didChangeBacking = "didChangeBacking"
|
||||
public static let didClickIncrement = "didClickIncrement"
|
||||
public static let didLaunch = "didLaunch"
|
||||
public static let didReshape = "didReshape"
|
||||
public static let didSetup = "didSetup"
|
||||
public static let isReadyToRender = "isReadyToRender"
|
||||
public static let pixelSize = "pixelSize"
|
||||
public static let reshapePixelSize = "reshapePixelSize"
|
||||
|
||||
}
|
||||
public struct RenderContext: DialectContext {
|
||||
public var didChangeBacking = Bool()
|
||||
public var backingPixelSize = [Int32]()
|
||||
public var didLaunch = Bool()
|
||||
public var didReshape = Bool()
|
||||
public var didSetup = Bool()
|
||||
public var isReadyToRender = Bool()
|
||||
public var pixelSize = [Int32]()
|
||||
public var reshapePixelSize = [Int32]()
|
||||
|
||||
public var recentField = ""
|
||||
|
||||
public func field<T>(_ name: String) -> T {
|
||||
if (name == "didChangeBacking") {
|
||||
return didChangeBacking as! T
|
||||
if (name == "backingPixelSize") {
|
||||
return backingPixelSize as! T
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
return didLaunch as! T
|
||||
}
|
||||
else if (name == "didReshape") {
|
||||
return didReshape as! T
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
return didSetup as! T
|
||||
}
|
||||
@@ -159,6 +156,9 @@ public struct RenderContext: DialectContext {
|
||||
else if (name == "pixelSize") {
|
||||
return pixelSize as! T
|
||||
}
|
||||
else if (name == "reshapePixelSize") {
|
||||
return reshapePixelSize as! T
|
||||
}
|
||||
|
||||
return "unknown-field-name" as! T
|
||||
}
|
||||
@@ -167,15 +167,12 @@ public struct RenderContext: DialectContext {
|
||||
_ name: String,
|
||||
_ value: Any
|
||||
) {
|
||||
if (name == "didChangeBacking") {
|
||||
didChangeBacking = value as! Bool
|
||||
if (name == "backingPixelSize") {
|
||||
backingPixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
didLaunch = value as! Bool
|
||||
}
|
||||
else if (name == "didReshape") {
|
||||
didReshape = value as! Bool
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
didSetup = value as! Bool
|
||||
}
|
||||
@@ -185,6 +182,9 @@ public struct RenderContext: DialectContext {
|
||||
else if (name == "pixelSize") {
|
||||
pixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "reshapePixelSize") {
|
||||
reshapePixelSize = value as! [Int32]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -285,6 +285,24 @@ func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext {
|
||||
return c
|
||||
}
|
||||
|
||||
/* 2. Upon resize */
|
||||
if
|
||||
c.recentField == F.reshapePixelSize
|
||||
{
|
||||
c.pixelSize = c.reshapePixelSize
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
/* 3. Upon DPI change */
|
||||
if
|
||||
c.recentField == F.backingPixelSize
|
||||
{
|
||||
c.pixelSize = c.backingPixelSize
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
|
||||
Reference in new issue
Block a user