Skip to content

[DText] [DVMod] The basic implementation of DefinedText module #24

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

Merged
merged 26 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b6da7b5
[DV] Add basic border support.
lilingxi01 Dec 21, 2021
3875c2d
[DVMod] Add basic text-related modifiers.
lilingxi01 Dec 21, 2021
7777747
[DText] Initial commit
lilingxi01 Dec 21, 2021
d2baef0
[DText] Add FontSpecs modifier support.
lilingxi01 Dec 21, 2021
5291f20
[DText] Add FontWeight modifier support.
lilingxi01 Dec 21, 2021
59ad974
[DText] Fix a format issue in FontWeight modifier.
lilingxi01 Dec 21, 2021
adf9a98
[DText] Add Preset modifier support.
lilingxi01 Dec 21, 2021
9823bf3
[DText] Add TextColor modifier support.
lilingxi01 Dec 21, 2021
aa04195
[LazyData] Add lazy data type support.
lilingxi01 Dec 21, 2021
a63a747
[DVMod] Add background modifier support.
lilingxi01 Dec 21, 2021
2810e4c
[DContent] Add DefinedContent module.
lilingxi01 Dec 21, 2021
88d021a
[GS] Add a selector for easy selection.
lilingxi01 Dec 21, 2021
8f29516
[DApp-iOS] Optimize the root layer.
lilingxi01 Dec 21, 2021
5c3818e
[DEColor] Fix the error-sending bug.
lilingxi01 Dec 21, 2021
e54841a
[DTextPreset] Add font weight variation support.
lilingxi01 Dec 21, 2021
203a04f
[DTextPreset] Add font weight variation support.
lilingxi01 Dec 21, 2021
5db34e4
[StatusBar] Add status bar style reverse support.
lilingxi01 Dec 21, 2021
b6644b4
[DVMod] Add content color modifier support.
lilingxi01 Dec 21, 2021
dcd2210
[DVMod] Add content color modifier support.
lilingxi01 Dec 21, 2021
1a0cc84
[DText] Support content color modifier.
lilingxi01 Dec 21, 2021
547edc5
[DTextPreset] Support global Preset modifier.
lilingxi01 Dec 22, 2021
c3c7acc
[DVMod] Add global Preset modifier.
lilingxi01 Dec 22, 2021
ca0be61
[DTextPreset] Change protocol to global Preset.
lilingxi01 Dec 22, 2021
166dec5
[DPreset] Add DPreset Protocol.
lilingxi01 Dec 22, 2021
0bc13c5
[Lazy] Optimize the lazy data experience.
lilingxi01 Dec 22, 2021
65b8807
[DVMod] Optimize the frame size modifier.
lilingxi01 Dec 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions Sources/DefinedElements/Frameworks/App/DApp.Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SwiftUI
/// This module is highly embeded, which includes the `WindowGroup` and more.
/// So please do not use it as a scene (which is a component for `WindowGroup`).
///
/// ```
/// ``` swift
/// @main
/// struct YourAppName: DefinedApp {
/// /// Your startup page, which has to be conformed to DefinedPage.
Expand Down Expand Up @@ -58,23 +58,15 @@ public extension DefinedApp {

#if os(iOS)

WindowGroup {
EmptyView()
.onAppear(perform: {
UIApplication.setController(rootView: DefinedViewStack(from: self.start))
})
}
DefinedAppRoot(from: self.start)

#endif

// MARK: > macOS

#if os(macOS)

WindowGroup {
DefinedViewStack(from: self.start_macOS) // TODO: Waiting to be developed
}
.windowStyle(HiddenTitleBarWindowStyle())
DefinedAppRoot()

#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if os(iOS)

import Foundation
import SwiftUI

/// [DE Internal] A root view controller alternative to empower the ability of changing status bar style.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SwiftUI

public extension UIStatusBarStyle {
func reverse() -> UIStatusBarStyle {
return self == .darkContent ? .lightContent : .darkContent
}
}
51 changes: 51 additions & 0 deletions Sources/DefinedElements/Frameworks/Content/DContent.Main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import SwiftUI

/// 界面元素容器 @ DefinedElements
public struct DefinedContent<Content> : DefinedView where Content: View {
///
public var content: () -> Content

///
var layout: DefinedContentLayoutType = .overlay

///
var spacing: CGFloat = 0

///
var alignment: Alignment = .center

/// DefinedContent 构造器
///
/// - Parameters:
/// - layout: 布局类型
/// - alignment: 对齐方式
/// - spacing: 子组件统一间距(默认无间距)
/// - cont: 子元素包裹
public init(_ layout: DefinedContentLayoutType = .overlay,
alignment: Alignment = .center,
spacing: CGFloat = 0,
@ViewBuilder _ cont: @escaping () -> Content) {
// TODO: 寻找如果Content中包含特定元素则提取出来进行状态回调
self.content = cont
self.layout = layout
self.alignment = alignment
self.spacing = spacing
}

/// 界面主体
public var body: some View {
if self.layout == .horizontal {
HStack(alignment: self.alignment.vertical, spacing: self.spacing) {
content()
}
} else if self.layout == .vertical {
VStack(alignment: self.alignment.horizontal, spacing: self.spacing) {
content()
}
} else {
ZStack(alignment: self.alignment) {
content()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

/// [DE]
public enum DefinedContentLayoutType {
///
case overlay

///
case horizontal

///
case vertical
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

/// [GE] A selector for GeneralStatus (including some patterns)
///
/// You are now able to select `all` when choosing General Statuses you want.
/// And you do not have to put all statuses in an array anymore when using `GeneralStatusSelector`.
///
/// # To Developers:
/// For General Statuses, we have a another Enum holding them and basically when developing,
/// we create two methods for different type of input (`GeneralStatus` and `GeneralStatusSelector`).
/// So we do not have to handle General Statuses again when we have `GeneralStatusSelector` as parameter type.
public enum GeneralStatusSelector {
///
case all
}

extension GeneralStatusSelector {
/// [DE Internal]
func getGS() -> [GeneralStatus] {
switch self {
case .all:
return [.default, .loading, .active, .done, .error, .disabled];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ extension Color {
green = Double((hexValue & 0x0000FF00) >> 8) / 255.0
blue = Double(hexValue & 0x000000FF) / 255.0
default:
DefinedWarning(
DefinedWarning.send(
from: "DEColor",
"Invalid RGB string, the number of characters after '#' should be either 3, 4, 6 or 8"
)
}
} else {
DefinedWarning(from: "DEColor", "Scan hex error")
DefinedWarning.send(from: "DEColor", "Scan hex error")
}
self.init(red: red, green: green, blue: blue, opacity: alpha)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import SwiftUI

/// [DE] A configuration class containing everything related to border working for `DefinedView` protocol system.
Expand Down Expand Up @@ -31,6 +30,12 @@ public struct DefinedViewBorderConfiguration {
/// - Parameter inactive: True if the current view does not use `BorderConfiguration`.
public init(inactive: Bool) {
self.inactive = inactive
self.border_def = .default
self.border_loading = .default
self.border_act = .bold
self.border_done = .default
self.border_error = .default
self.border_disabled = .default
}

/// [DE] Create a Border Configuration with corresponding setups.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import SwiftUI

extension View {
/// Since we have `background(_:)` method in SwiftUI,
/// we do not implement the default method for `View`.
}

extension DefinedView {
/// Since we have `background(_:)` method in SwiftUI,
/// we do not implement the default method for other unsupported `DefinedView`.
}

extension DefinedViewModifiedView {
/// [DE] Set the background of current root view.
///
/// - Parameter background: The background of view.
/// - Returns: A view after modifying the background of root view.
///
/// - Important: This function may NOT work if you are using me!
public func background<SomeView: View>(_ background: SomeView) -> some View {
return DefinedViewBackgroundModifier(background: AnyView(background)).modify(view: self)
}

/// [DE] Set the background color of current root view.
///
/// - Parameter background: The background color of view.
/// - Returns: A view after modifying the background color of root view.
///
/// - Important: This function may NOT work if you are using me!
public func background(_ color: Color) -> some View {
return DefinedViewBackgroundModifier(background: AnyView(color)).modify(view: self)
}
}

struct DefinedViewBackgroundModifier : DefinedViewModifier {
var name: String = "Background"

var background: AnyView

init(background: AnyView) {
self.background = background
}

func modify<OtherModifiedViews: DefinedView>(view: DefinedViewModifiedView<OtherModifiedViews>) -> DefinedViewModifiedView<OtherModifiedViews> {
return forceBackground(view: view)
}

func forceBackground<OtherModifiedViews: DefinedView>(view: DefinedViewModifiedView<OtherModifiedViews>) -> DefinedViewModifiedView<OtherModifiedViews> {
print("YES: Modify \(name) (forcely wrapper) for DefinedViewModifiedView correctly!")
return DefinedViewModifiedView(root: view.root, configuration: view.configuration, content: { root in
view.content(root)
.background(self.background)
})
}
}
Loading