Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
Rename column and row count functions to better describe that they compute their results, and don't just return them

Change return value of `computeColumnAndRowCounts(forSwatchCount:)` to `(Int, Int)` instead of `(Double, Int)`
  • Loading branch information
jordanbaird committed Nov 1, 2023
1 parent 8b6673a commit 8c6accc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extension ColorWellPopover.LayoutView {
let (columnCount, topRowSpacing) = {
switch configuration.layout.kind {
case let .grid(_, _, _, topRowSpacing):
return (configuration.columnCount(), topRowSpacing)
return (configuration.computeColumnCount(), topRowSpacing)
}
}()

Expand Down
17 changes: 9 additions & 8 deletions Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ extension ColorWell {

// MARK: Instance Methods

func columnAndRowCounts(forSwatchCount swatchCount: Int) -> (columnCount: Double, rowCount: Int) {
func computeColumnAndRowCounts(forSwatchCount swatchCount: Int) -> (columnCount: Int, rowCount: Int) {
let swatchCountDbl = Double(swatchCount)
let columnCount: Double = {
let columnCountDbl: Double = {
switch layout.kind {
case let .grid(columnCount, _, _, _):
if let columnCount {
Expand All @@ -191,23 +191,24 @@ extension ColorWell {
}
}()

let rowCount = Int((swatchCountDbl / columnCount).rounded(.up))
let rowCount = Int((swatchCountDbl / columnCountDbl).rounded(.up))
let columnCount = Int(columnCountDbl)
return (columnCount, rowCount)
}

func columnCount() -> Int {
Int(columnAndRowCounts(forSwatchCount: colors.count).columnCount)
func computeColumnCount() -> Int {
computeColumnAndRowCounts(forSwatchCount: colors.count).columnCount
}

func rowCount() -> Int {
columnAndRowCounts(forSwatchCount: colors.count).rowCount
func computeRowCount() -> Int {
computeColumnAndRowCounts(forSwatchCount: colors.count).rowCount
}

func computeSwatchSize() -> NSSize {
if let swatchSize {
return swatchSize
}
let rowCount = rowCount()
let rowCount = computeRowCount()
if rowCount < 6 {
return NSSize(width: 30, height: 30)
}
Expand Down

0 comments on commit 8c6accc

Please sign in to comment.