Skip to content
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

hugo/feature/Add Gradient class #560

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
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
41 changes: 23 additions & 18 deletions Modules/RobotKit/Sources/Robot+Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SwiftUI

// MARK: - Robot.Color

// swiftlint:disable nesting identifier_name line_length
// swiftlint:disable nesting

public extension Robot {
struct Color {
Expand All @@ -26,22 +26,9 @@ public extension Robot {
self = color
}

public init(r: UInt8, g: UInt8, b: UInt8) {
self.robotRGB = [r, g, b]
self.screenRGB = [r, g, b]
}

public init(fromGradient colors: (Color, Color), at position: Float) {
let positionClamped = max(min(position, 1), 0)
let (r1, g1, b1) = (Float(colors.0.robotRGB[0]), Float(colors.0.robotRGB[1]), Float(colors.0.robotRGB[2]))
let (r2, g2, b2) = (Float(colors.1.robotRGB[0]), Float(colors.1.robotRGB[1]), Float(colors.1.robotRGB[2]))

let r = UInt8(r1 + (r2 - r1) * positionClamped)
let g = UInt8(g1 + (g2 - g1) * positionClamped)
let b = UInt8(b1 + (b2 - b1) * positionClamped)

self.robotRGB = [r, g, b]
self.screenRGB = [r, g, b]
public init(red: UInt8, green: UInt8, blue: UInt8) {
self.robotRGB = [red, green, blue]
self.screenRGB = [red, green, blue]
}

// MARK: Public
Expand All @@ -58,6 +45,24 @@ public extension Robot {
)
}

public var robotUiColor: UIColor {
UIColor(
red: Double(self.robotRGB[0]) / 255.0,
green: Double(self.robotRGB[1]) / 255.0,
blue: Double(self.robotRGB[2]) / 255.0,
alpha: 1.0
)
}

public var screenUiColor: UIColor {
UIColor(
red: Double(self.screenRGB[0]) / 255.0,
green: Double(self.screenRGB[1]) / 255.0,
blue: Double(self.screenRGB[2]) / 255.0,
alpha: 1.0
)
}
Comment on lines +48 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi tu as besoin de passer par UIColor? pourquoi pas une simple struct?

Comment on lines +48 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public var robotUiColor: UIColor {
UIColor(
red: Double(self.robotRGB[0]) / 255.0,
green: Double(self.robotRGB[1]) / 255.0,
blue: Double(self.robotRGB[2]) / 255.0,
alpha: 1.0
)
}
public var screenUiColor: UIColor {
UIColor(
red: Double(self.screenRGB[0]) / 255.0,
green: Double(self.screenRGB[1]) / 255.0,
blue: Double(self.screenRGB[2]) / 255.0,
alpha: 1.0
)
}
public var robotUIColor: UIColor {
UIColor(
red: Double(self.robotRGB[0]) / 255.0,
green: Double(self.robotRGB[1]) / 255.0,
blue: Double(self.robotRGB[2]) / 255.0,
alpha: 1.0
)
}
public var screenUIColor: UIColor {
UIColor(
red: Double(self.screenRGB[0]) / 255.0,
green: Double(self.screenRGB[1]) / 255.0,
blue: Double(self.screenRGB[2]) / 255.0,
alpha: 1.0
)
}


// MARK: Private

private enum ColorString: String {
Expand Down Expand Up @@ -120,4 +125,4 @@ public extension Robot.Color {
static let yellow: Robot.Color = .init(robot: 255, 255, 0, screen: 251, 232, 0)
}

// swiftlint:enable nesting identifier_name line_length
// swiftlint:enable nesting