Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Improve custom toolbar design
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jul 17, 2023
1 parent decdef7 commit 79d4022
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion Sources/ColibriComponents/Model/Data/ToolbarAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public struct ToolbarAction: Identifiable {
icon
}
.customToolbarItem(padding: padding)
.foregroundColor(isOn ? .accentColor : .primary)
}
.buttonStyle(CustomToolbarButton())
.help(title)
Expand Down
11 changes: 1 addition & 10 deletions Sources/ColibriComponents/Model/Data/ToolbarGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,9 @@ public struct ToolbarGroup: Identifiable, View {
}
}
.background(
.thickMaterial.opacity(hover ? 1 : .toolbarGroupBackground),
.secondary.opacity((hover || actions.allSatisfy { $0.isOn }) ? .toolbarGroupSecondaryBackground : 0),
in: rectangle
)
.background(.secondary.opacity(hover ? .toolbarGroupSecondaryBackground : 0), in: rectangle)
.animation(
.default.speed(.hoverAnimationSpeed).delay(hover ? .toolbarGroupAnimationDelay : 0),
value: hover
)
.overlay {
rectangle
.stroke(.secondary.opacity(.toolbarStrokeOpacity))
}
.onHover { hover = $0 }
if addSpacer {
Spacer()
Expand Down
7 changes: 6 additions & 1 deletion Sources/ColibriComponents/Model/Extensions/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extension Array: View where Element == ToolbarGroup {
}
.padding(.customToolbarPadding)
.frame(height: .customToolbarHeight)
.offset(y: .customToolbarOffsetCorrection)
}

}
Expand Down Expand Up @@ -105,7 +106,11 @@ struct Array_Previews: PreviewProvider, View {
}
ToolbarGroup {
ToolbarAction(.init(), systemSymbol: .circle) {
testCount = 0
if testCount == 0 {
testCount = 1
} else {
testCount = 0
}
}
.isOn(testCount == 0)
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/ColibriComponents/Model/Extensions/CGFloat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ extension CGFloat {
/// The side length of a custom toolbar item.
internal static var customToolbarSideLength: Self { 20 }
/// The padding of a custom toolbar.
internal static var customToolbarPadding: Self { 10 }
internal static var customToolbarPadding: Self { 5 }
/// The corner radius in many user interface elements.
public static var colibriCornerRadius: Self { 10 }
/// The height of a custom toolbar.
internal static var customToolbarHeight: Self { 40 }
internal static var customToolbarHeight: Self { 20 }
/// The scale of the button of a custom toolbar action that is not pressed.
internal static var customToolbarButtonNotPressedScale: Self { 0.6 }
/// The minimum width of an item in a ``SelectionItemPicker``.
Expand All @@ -38,6 +38,8 @@ extension CGFloat {
internal static var freeformBackgroundSidelength: Self { 22 }
/// The sidelength of the image in the foreground of a Freeform toolbar.
internal static var freeformForegroundSidelength: Self { 13 }
/// An offset for the custom toolbar.
internal static var customToolbarOffsetCorrection: Self { 2 }

}

Expand Down
4 changes: 1 addition & 3 deletions Sources/ColibriComponents/Model/Extensions/Double.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ extension Double {
/// The opacity of the background of a custom toolbar group that is not hovered.
internal static var toolbarGroupBackground: Self { 0.5 }
/// The opacity of the secondary background of a custom toolbar group that is hovered.
internal static var toolbarGroupSecondaryBackground: Self { 0.2 }
internal static var toolbarGroupSecondaryBackground: Self { 0.05 }
/// The speed of hover animations.
public static var hoverAnimationSpeed: Self { 2 }
/// The delay of the hover animation in a custom toolbar group when the hovering starts.
internal static var toolbarGroupAnimationDelay: Self { 0.2 }
/// The opacity of the stroke in custom toolbars.
internal static var toolbarStrokeOpacity: Self { 0.2 }
/// The opacity of the background of a selection item if selected.
internal static var selectionSymbolBackgroundOpacity: Self { 0.1 }
/// The opacity of the background of a selection item if hovered.
Expand Down

0 comments on commit 79d4022

Please sign in to comment.