mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
working on jumbomoji
This commit is contained in:
4 files changed
+87
-11
No files matched your search
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// JumboMoji.swift
|
||||
// StickerSlack
|
||||
//
|
||||
// Created by neon443 on 03/05/2026.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct JumboMoji {
|
||||
var width: Int
|
||||
var height: Int
|
||||
var baseName: String
|
||||
var type: JumboMoji.Style
|
||||
var items: [String]
|
||||
|
||||
// init(baseName: String, items: [String]) {
|
||||
// let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) }
|
||||
//
|
||||
//
|
||||
// let coordinates = itemsBaseNameRemoved.map { $0.dropLast($0.split(separator: "-").last?.count ?? 0) }.split(separator: "-").map { Int(String($0)) }
|
||||
// self.width = width
|
||||
// self.height = height
|
||||
// self.baseName = baseName
|
||||
// self.type = type
|
||||
// self.items = items
|
||||
// }
|
||||
|
||||
enum Style {
|
||||
case grid
|
||||
case btn
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,36 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
Section("Debug") {
|
||||
NavigationLink {
|
||||
EmojiCollectionView(
|
||||
hoarder: hoarder,
|
||||
items: [
|
||||
"btn-3kh0-1",
|
||||
"btn-3kh0-2",
|
||||
"btn-3kh0-3",
|
||||
"btn-antinft-1",
|
||||
"btn-antinft-2",
|
||||
"btn-antinft-3",
|
||||
"btn-bsky-1",
|
||||
"btn-bsky-2",
|
||||
"btn-bsky-3",
|
||||
"btn-gideon-1",
|
||||
"btn-gideon-2",
|
||||
"btn-gideon-3",
|
||||
"btn-macos-1",
|
||||
"btn-macos-2",
|
||||
"btn-macos-3",
|
||||
"btn-microhate-1",
|
||||
"btn-microhate-2",
|
||||
"btn-microhate-3"
|
||||
],
|
||||
pack: nil,
|
||||
width: 3,
|
||||
style: .jumboMoji
|
||||
)
|
||||
} label: {
|
||||
Label("jumbomoji", systemImage: "square.split.2x2")
|
||||
}
|
||||
NavigationLink {
|
||||
EmojiCollectionView(
|
||||
hoarder: hoarder,
|
||||
|
||||
@@ -68,6 +68,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
case plain
|
||||
case plainWithMenu
|
||||
case full
|
||||
case jumboMoji
|
||||
}
|
||||
|
||||
final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout {
|
||||
@@ -104,7 +105,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
self.width = width
|
||||
self.style = style
|
||||
|
||||
layout.minimumInteritemSpacing = 8
|
||||
layout.minimumInteritemSpacing = style == .jumboMoji ? 0 : 8
|
||||
super.init(collectionViewLayout: layout)
|
||||
|
||||
self.dataSource = UICollectionViewDiffableDataSource<Int, String>(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in
|
||||
@@ -129,7 +130,7 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
) -> UICollectionViewCell {
|
||||
let cell: PlainEmojiCollectionViewCell
|
||||
switch style {
|
||||
case .plain, .plainWithMenu:
|
||||
case .plain, .plainWithMenu, .jumboMoji:
|
||||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
|
||||
case .full:
|
||||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell
|
||||
@@ -179,7 +180,12 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
) -> CGSize {
|
||||
let totalWidth = collectionView.bounds.width
|
||||
let availWidth = totalWidth-(collectionView.contentInset.left*2)
|
||||
let cols = max(1, floor(availWidth/width))
|
||||
let cols: CGFloat
|
||||
if style == .jumboMoji {
|
||||
cols = width
|
||||
} else {
|
||||
cols = max(1, floor(availWidth/width))
|
||||
}
|
||||
let totalSpacing = layout.minimumInteritemSpacing * (cols - 1)
|
||||
let itemWidth = (availWidth-totalSpacing)/cols
|
||||
let defaultSize = CGSize(width: itemWidth, height: itemWidth)
|
||||
@@ -204,15 +210,14 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
EmojiCollectionView.Coordinator.labelSizeDict[itemWidth] = [emojiName: labelHeight]
|
||||
}
|
||||
}
|
||||
|
||||
let font = UIFont.preferredFont(forTextStyle: .caption1)
|
||||
let rect = (emojiName as NSString).boundingRect(
|
||||
with: CGSize(width: itemWidth, height: .greatestFiniteMagnitude),
|
||||
options: [.usesLineFragmentOrigin, .usesFontLeading],
|
||||
attributes: [.font: font],
|
||||
context: nil
|
||||
)
|
||||
return CGSize(width: itemWidth, height: itemWidth+labelHeight+4)
|
||||
// let font = UIFont.preferredFont(forTextStyle: .caption1)
|
||||
// let rect = (emojiName as NSString).boundingRect(
|
||||
// with: CGSize(width: itemWidth, height: .greatestFiniteMagnitude),
|
||||
// options: [.usesLineFragmentOrigin, .usesFontLeading],
|
||||
// attributes: [.font: font],
|
||||
// context: nil
|
||||
// )
|
||||
}
|
||||
|
||||
override func collectionView(
|
||||
|
||||