-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Primary/Secondary/Tertiary/QuaternaryContentStyle (#419)
- Loading branch information
1 parent
4a7748a
commit 2efa80a
Showing
9 changed files
with
195 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
104 changes: 104 additions & 0 deletions
104
Sources/TokamakCore/Shapes/ShapeStyles/ContentStyles.swift
This file contains 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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2020-2021 Tokamak contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Created by Carson Katri on 7/7/21. | ||
// | ||
|
||
@frozen public struct PrimaryContentStyle { | ||
@inlinable | ||
public init() {} | ||
} | ||
|
||
extension PrimaryContentStyle: ShapeStyle { | ||
public func _apply(to shape: inout _ShapeStyle_Shape) { | ||
if !shape.inRecursiveStyle, | ||
let foregroundStyle = shape.environment._foregroundStyle | ||
{ | ||
if foregroundStyle.styles.primary is Self { | ||
shape.inRecursiveStyle = true | ||
} | ||
foregroundStyle.styles.primary._apply(to: &shape) | ||
} else { | ||
shape.result = .color(shape.environment.foregroundColor ?? .primary) | ||
} | ||
} | ||
|
||
public static func _apply(to shape: inout _ShapeStyle_ShapeType) {} | ||
} | ||
|
||
@frozen public struct SecondaryContentStyle { | ||
@inlinable | ||
public init() {} | ||
} | ||
|
||
extension SecondaryContentStyle: ShapeStyle { | ||
public func _apply(to shape: inout _ShapeStyle_Shape) { | ||
if !shape.inRecursiveStyle, | ||
let foregroundStyle = shape.environment._foregroundStyle | ||
{ | ||
if foregroundStyle.styles.secondary is Self { | ||
shape.inRecursiveStyle = true | ||
} | ||
foregroundStyle.styles.secondary._apply(to: &shape) | ||
} else { | ||
shape.result = .color((shape.environment.foregroundColor ?? .primary).opacity(0.5)) | ||
} | ||
} | ||
|
||
public static func _apply(to shape: inout _ShapeStyle_ShapeType) {} | ||
} | ||
|
||
@frozen public struct TertiaryContentStyle { | ||
@inlinable | ||
public init() {} | ||
} | ||
|
||
extension TertiaryContentStyle: ShapeStyle { | ||
public func _apply(to shape: inout _ShapeStyle_Shape) { | ||
if !shape.inRecursiveStyle, | ||
let foregroundStyle = shape.environment._foregroundStyle | ||
{ | ||
if foregroundStyle.styles.tertiary is Self { | ||
shape.inRecursiveStyle = true | ||
} | ||
foregroundStyle.styles.tertiary._apply(to: &shape) | ||
} else { | ||
shape.result = .color((shape.environment.foregroundColor ?? .primary).opacity(0.3)) | ||
} | ||
} | ||
|
||
public static func _apply(to shape: inout _ShapeStyle_ShapeType) {} | ||
} | ||
|
||
@frozen public struct QuaternaryContentStyle { | ||
@inlinable | ||
public init() {} | ||
} | ||
|
||
extension QuaternaryContentStyle: ShapeStyle { | ||
public func _apply(to shape: inout _ShapeStyle_Shape) { | ||
if !shape.inRecursiveStyle, | ||
let foregroundStyle = shape.environment._foregroundStyle | ||
{ | ||
if foregroundStyle.styles.tertiary is Self { | ||
shape.inRecursiveStyle = true | ||
} | ||
foregroundStyle.styles.tertiary._apply(to: &shape) | ||
} else { | ||
shape.result = .color((shape.environment.foregroundColor ?? .primary).opacity(0.2)) | ||
} | ||
} | ||
|
||
public static func _apply(to shape: inout _ShapeStyle_ShapeType) {} | ||
} |
This file contains 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 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 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 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 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 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
Binary file added
BIN
+1.02 KB
Tests/TokamakStaticHTMLTests/__Snapshots__/RenderingTests/testContentStyles.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.