-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwiftUI Style .foo() wrappers #88
Conversation
0733fd2
to
0f9fd85
Compare
1) SwiftUI methods I really like this, and actually added similar functions in a side project over the weekend for some custom "view modifiers". I think it's both easier to read and write - I often start out with a base element like a label, and in the current form it's clunky to repeatedly wrap it in elements, and often "obscures" the real UI. 2) Stack improvements StackChild: I think this makes sense, having named static methods instead of having to read the docs for grow/shrink priority every time seems great (jokes aside, the names are way more readable and beginner friendly). Operators: I'm not a huge fan of custom operators for UI, since they're not very discoverable, lead to divergence in code style (since it doesn't make sense to remove the functions) and it just doesn't "feel right" to me. Not a super strong opinion here though :) |
@kylebshr re operators: generally agree, but I think there's a time and place for them, eg common operations like this. As long as you can do everything without operators that you can do with them, I feel it's fine. |
@kyleve: TODO: Split Stack changes out into a new PR
|
I've removed the stack changes from this PR |
41f0ffb
to
827f9bc
Compare
827f9bc
to
5da4863
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after comments!
55aa13a
to
3d89548
Compare
Haha, didn’t realize the init had a default, I don’t like it there for the same reason but I’ll let you decide!
… On May 5, 2020, at 8:05 PM, Kyle Van Essen ***@***.***> wrote:
@kyleve commented on this pull request.
In BlueprintUI/Sources/Layout/Aligned.swift:
> @@ -111,3 +111,23 @@ public struct Aligned: Element {
}
}
}
+
+public extension Element {
+ /// Wraps the element in an `Aligned` element with the provided parameters.
+ ///
+ /// - parameters:
+ /// - vertically: The vertical alignment. Defaults to `.centered`.
+ /// - horizontally: The horizontal alignment. Defaults to `.centered`.
+ ///
+ func aligned(
+ vertically: Aligned.VerticalAlignment = .center,
Eh, what the hell, removing the default
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
0e1e6d1
to
be14258
Compare
Popping in for a comment on Stack Improvements, even though this is merged. IMO you get a bit more clarity about what is being added when the Element proceeds the stacking traits. Was dabbling and added a similar StackChild, with the flex traits using function builders (like this PR adds) so you could get:
I like @kyleve's use of fixed a lot!
|
This PR implements SwiftUI-style wrappers which I think improve the succinctness and readability of Blueprint code.
The main file to check out for updates/examples to written consumer code is
ViewController.swift
.SwiftUI-Style
.foo()
methods for wrapping typesBefore this change, if you wanted to have a scroll view, which wrapped a box, which wrapped an inset, which wrapped a constrained size, which wrapped a label (and so on), the code would look something like this:
Which obviously is pretty verbose... It's nice that from the shape of the code you see what's going on, but it's pretty hard to follow in practice, especially if these inner statements get broken up into intermediary variables.
After this change, to write this code, this becomes like the following, similar to SwiftUI: