@@ -9,15 +9,16 @@ protocol MainSectionGrid { } | |||||
extension Main { | extension Main { | ||||
enum SectionGrid { | enum SectionGrid { | ||||
static func setupCore(_ core: Main.Core) { | static func setupCore(_ core: Main.Core) { | ||||
let side = 50 | |||||
let space = 20 | |||||
let gap = side + space | |||||
// Расставляем кнопки в сетке 4x4. | // Расставляем кнопки в сетке 4x4. | ||||
for btn in core.buttons { | |||||
let id = btn.tag | |||||
let row = Int(id / 4) | |||||
btn.frame = CGRect(x: gap + (id - row * 4) * gap, y: gap + row * gap, width: side, height: side) | |||||
for (id, p) in memoryItemPositions(M()).enumerated() { | |||||
let btn = core.buttons[id] | |||||
btn.frame = | |||||
CGRect( | |||||
x: p.0, | |||||
y: p.1, | |||||
width: memorySide(), | |||||
height: memorySide() | |||||
) | |||||
btn.backgroundColor = .blue | btn.backgroundColor = .blue | ||||
} | } | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
import Foundation | import Foundation | ||||
protocol MItemsCount { | |||||
var itemsCount: Int { get } | |||||
struct M { | |||||
var itemsCount: Int = 16 | |||||
} | } | ||||
func memorySide() -> CGFloat { | func memorySide() -> CGFloat { | ||||
@@ -16,7 +16,7 @@ func memoryGap() -> CGFloat { | |||||
return memorySide() + memorySpace() | return memorySide() + memorySpace() | ||||
} | } | ||||
func memoryItemPositions(M: MItemsCount) -> [(CGFloat, CGFloat)] { | |||||
func memoryItemPositions(_ M: M) -> [(CGFloat, CGFloat)] { | |||||
var pos = [(CGFloat, CGFloat)]() | var pos = [(CGFloat, CGFloat)]() | ||||
for i in stride(from: 0, to: M.itemsCount, by: 1) { | for i in stride(from: 0, to: M.itemsCount, by: 1) { | ||||
let row = floor(Double(i) / 4) | let row = floor(Double(i) / 4) | ||||
@@ -19,7 +19,7 @@ | |||||
} | } | ||||
function memoryItemPositions(M) { | function memoryItemPositions(M) { | ||||
var pos = []; | |||||
var pos = [] | |||||
for (var i = 0; i < M.itemsCount; i++) { | for (var i = 0; i < M.itemsCount; i++) { | ||||
let row = Math.floor(i / 4) | let row = Math.floor(i / 4) | ||||
let x = memoryGap() + (i - row * 4) * memoryGap() | let x = memoryGap() + (i - row * 4) * memoryGap() | ||||