working on jumbomoji

This commit is contained in:
neon443 committed 2026-05-03 20:10:07 +01:00
1 parent 0294e4b60b
commit 8be16d7c0e
4 files changed
+87 -11

No files matched your search

+33
View File
@@ -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
}
}
+30
View File
@@ -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(
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.