Comments (3)
It's an interesting problem! Without reviewing the more specific issue you raised later, I put this together as an attempt to capture what you specified. If you use a DynamicSplit()
, it shows a "Split" button that increments the nSplits
state to redraw the view. The starting NestedHSplit
recursively creates alternating NestedVSplits
and NestedHSplits
until the passed-in nSplits
is 0. If you need to retain the split state, I would use a property based on the value of nSplits at each instantiation.
struct DynamicSplit: View {
@State var nSplits: Int = 0
var body: some View {
VStack {
let primordialView = Color.red
let newView = Color.green
Button("Split") { nSplits += 1 }
if nSplits > 0 {
NestedHSplit(nSplits: nSplits, primary: { primordialView }, secondary: { newView })
} else {
primordialView
}
}
}
}
struct NestedHSplit<P: View, S : View>: View {
let nSplits: Int
var primary: P
var secondary: S
var body: some View {
if nSplits == 0 {
primary
} else {
primary.hSplit { NestedVSplit(nSplits: nSplits - 1, primary: { secondary }, secondary: { primary } ) }
}
}
init(nSplits: Int, @ViewBuilder primary: @escaping ()->P, @ViewBuilder secondary: @escaping ()->S ) {
self.nSplits = nSplits
self.primary = primary()
self.secondary = secondary()
}
}
struct NestedVSplit<P: View, S : View>: View {
let nSplits: Int
var primary: P
var secondary: S
var body: some View {
if nSplits == 0 {
primary
} else {
primary.vSplit { NestedHSplit(nSplits: nSplits - 1, primary: { secondary }, secondary: { primary } ) }
}
}
init(nSplits: Int, @ViewBuilder primary: @escaping ()->P, @ViewBuilder secondary: @escaping ()->S ) {
self.nSplits = nSplits
self.primary = primary()
self.secondary = secondary()
}
}
from splitview.
That works perfectly, thank you! Will modify it to behavior closer to Xcode's split pane behavior. Also greetings from Palo Alto!
from splitview.
Feel free to re-open if needed.
from splitview.
Related Issues (20)
- Constraints for Sliding Splitters
- Set SplitView Constraints by absolute number HOT 1
- Sticky buttons in secondary views or on press repeat HOT 4
- Feature: minimum split size HOT 8
- Bug: splitter line should be invisible when hidden HOT 2
- divider's visual bug HOT 11
- Option to offset views instead of changing frame size HOT 5
- Breakpoints & animations HOT 1
- Hidden view still visible partly HOT 4
- Custom splitter using drag-to-hide
- Setting fraction programmatically (after the split view is shown already) HOT 2
- CustomSplitter disappears when constraints is set HOT 4
- Bug when hiding splitview while using minimum fractions HOT 3
- Default splitter HOT 2
- Issue When Dragging a Splitter Outside the Parent Window on MacOS HOT 4
- Instantiating from a simpler format? HOT 1
- Change cursor on Mac when inside splitter HOT 4
- UserDefaults - working ? HOT 6
- Set SplitView Constraints Maximum HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from splitview.