-
-
Notifications
You must be signed in to change notification settings - Fork 64
Fix/progess spinner resizing #238
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
Open
MiaKoring
wants to merge
12
commits into
stackotter:main
Choose a base branch
from
MiaKoring:fix/ProgessSpinnerResizing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ba361de
Fixed ProgressViewResizing on AppKitBackend
MiaKoring 660f678
added min height&width to prevent pushing it too small
MiaKoring 6879d40
now the minWidth actually takes effect (max(min(x, y), 10)
MiaKoring c3bc981
Made ProgressView resizability optional through .resizable()
MiaKoring 4645c19
changed .resizable() to modify a copy instead of Initializing with al…
MiaKoring b0cc977
formatting and naming
MiaKoring b615c3c
Merge branch 'stackotter:main' into fix/ProgessSpinnerResizing
MiaKoring 8927187
changing AppKits ProgressSpinner size through replacing it with a spi…
MiaKoring 6d7049a
Added minHeight to ControlsExample to make it not spawn with 0 height…
MiaKoring ea80229
added a guard to not recreate ProgressSpinners on AppKit when the siz…
MiaKoring dcfb676
Implemented requested changes
MiaKoring 0a24c59
Merge branch 'main' into fix/ProgessSpinnerResizing
MiaKoring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ public struct ProgressView<Label: View>: View { | |
| private var label: Label | ||
| private var progress: Double? | ||
| private var kind: Kind | ||
| private var isSpinnerResizable: Bool = false | ||
|
|
||
| private enum Kind { | ||
| case spinner | ||
|
|
@@ -23,7 +24,7 @@ public struct ProgressView<Label: View>: View { | |
| private var progressIndicator: some View { | ||
| switch kind { | ||
| case .spinner: | ||
| ProgressSpinnerView() | ||
| ProgressSpinnerView(isResizable: isSpinnerResizable) | ||
| case .bar: | ||
| ProgressBarView(value: progress) | ||
| } | ||
|
|
@@ -50,6 +51,14 @@ public struct ProgressView<Label: View>: View { | |
| self.kind = .bar | ||
| self.progress = value.map(Double.init) | ||
| } | ||
|
|
||
| /// Makes the ProgressView resize to fit the available space. | ||
| /// Only affects ``Kind/spinner``. | ||
| public func resizable(_ isResizable: Bool = true) -> Self { | ||
| var progressView = self | ||
| progressView.isSpinnerResizable = isResizable | ||
| return progressView | ||
| } | ||
| } | ||
|
|
||
| extension ProgressView where Label == EmptyView { | ||
|
|
@@ -101,7 +110,11 @@ extension ProgressView where Label == Text { | |
| } | ||
|
|
||
| struct ProgressSpinnerView: ElementaryView { | ||
| init() {} | ||
| let isResizable: Bool | ||
|
|
||
| init(isResizable: Bool = false) { | ||
| self.isResizable = isResizable | ||
| } | ||
|
|
||
| func asWidget<Backend: AppBackend>(backend: Backend) -> Backend.Widget { | ||
| backend.createProgressSpinner() | ||
|
|
@@ -113,16 +126,40 @@ struct ProgressSpinnerView: ElementaryView { | |
| environment: EnvironmentValues, | ||
| backend: Backend | ||
| ) -> ViewLayoutResult { | ||
| let size = ViewSize(backend.naturalSize(of: widget)) | ||
| return ViewLayoutResult.leafView(size: size) | ||
| let naturalSize = backend.naturalSize(of: widget) | ||
|
|
||
| guard isResizable else { | ||
| // Required to reset its size when resizability | ||
| // gets changed at runtime | ||
| return ViewLayoutResult.leafView(size: ViewSize(naturalSize)) | ||
| } | ||
|
|
||
| let minimumDimension: Double | ||
|
|
||
| if let proposedWidth = proposedSize.width, | ||
| let proposedHeight = proposedSize.height | ||
| { | ||
| minimumDimension = max(min(proposedWidth, proposedHeight), 0) | ||
| } else { | ||
| minimumDimension = Double(min(naturalSize.x, naturalSize.y)) | ||
| } | ||
|
|
||
| return ViewLayoutResult.leafView( | ||
| size: .init(minimumDimension, minimumDimension) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| ) | ||
| } | ||
|
|
||
| func commit<Backend: AppBackend>( | ||
| _ widget: Backend.Widget, | ||
| layout: ViewLayoutResult, | ||
| environment: EnvironmentValues, | ||
| backend: Backend | ||
| ) {} | ||
| ) { | ||
| // Doesn't change the rendered size of ProgressSpinner | ||
| // on UIKitBackend, but still sets container size to | ||
| // (width: n, height: n) n = min(proposedSize.x, proposedSize.y) | ||
| backend.setSize(ofProgressSpinner: widget, to: layout.size.vector) | ||
| } | ||
| } | ||
|
|
||
| struct ProgressBarView: ElementaryView { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.