Skip to content

Commit 968827b

Browse files
committed
Allow custom sizing
1 parent 75edbbb commit 968827b

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

Sources/GateEngine/UI/ScrollView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ open class ScrollView: View {
4343
self.offset.interpolate(to: destinationOffset, .linear(factor))
4444
}
4545

46-
override public init() {
47-
super.init()
46+
override init(size: Size2? = nil) {
47+
super.init(size: size)
4848
self.addSubview(contentView)
4949
}
5050

Sources/GateEngine/UI/SplitViewController.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
import Foundation
99

1010
final class SplitViewDividerControl: Control {
11+
var isEnabled: Bool = true
1112
override func canBeHit() -> Bool {
12-
return true
13+
return isEnabled
1314
}
1415

1516
let divider = View()
1617

1718
var isDragging: Bool = false
1819

19-
override init() {
20-
super.init()
21-
divider.backgroundColor = .red
20+
override init(size: Size2? = nil) {
21+
super.init(size: size)
22+
divider.backgroundColor = .darkGray
2223
self.addSubview(divider)
2324
}
2425

@@ -79,14 +80,19 @@ final class SplitViewDividerControl: Control {
7980
}
8081

8182
public final class SplitView: View {
82-
var dividerXOffset: Float = 230 {
83+
public var canResizeSidebar: Bool = true {
84+
didSet {
85+
dividerControl.isEnabled = self.canResizeSidebar
86+
}
87+
}
88+
public var dividerXOffset: Float = 300 {
8389
didSet {
8490
self.setNeedsUpdateConstraints()
8591
}
8692
}
8793

8894
let dividerControl: SplitViewDividerControl = SplitViewDividerControl()
89-
func addSidebarView(_ sidebarView: View, contentView: View) {
95+
public func addSidebarView(_ sidebarView: View, contentView: View) {
9096
for subview in subviews {
9197
subview.removeFromSuperview()
9298
}
@@ -95,8 +101,8 @@ public final class SplitView: View {
95101
self.addSubview(dividerControl)
96102
}
97103

98-
public override init() {
99-
super.init()
104+
public override init(size: Size2? = nil) {
105+
super.init(size: size)
100106

101107
}
102108

@@ -151,7 +157,7 @@ open class SplitViewController: ViewController {
151157
self.splitView.addSidebarView(children[0].view, contentView: children[1].view)
152158
}
153159

154-
var splitView: SplitView {
160+
public var splitView: SplitView {
155161
return self.view as! SplitView
156162
}
157163

Sources/GateEngine/UI/View.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ open class View {
4242
}
4343
}
4444

45-
public init() {
46-
45+
public init(size: Size2? = nil) {
46+
if let size {
47+
self.widthAnchor.constrain(to: size.width)
48+
self.heightAnchor.constrain(to: size.height)
49+
}
4750
}
4851

4952
public var interfaceScale: Float {
@@ -128,11 +131,13 @@ open class View {
128131
var _superview: View? = self.superView
129132
while let superview = _superview {
130133
if superview.renderingMode == .offScreen {
134+
frame.position += window!.offScreenRendering.frameForView(superview).position / interfaceScale
131135
break
136+
}else{
137+
frame.position += superview.bounds.position
138+
frame.position += superview.frame.position
139+
_superview = superview.superView
132140
}
133-
frame.position += superview.bounds.position
134-
frame.position += superview.frame.position
135-
_superview = superview.superView
136141
}
137142
_representationFrame = frame * interfaceScale
138143
return _representationFrame!

0 commit comments

Comments
 (0)