2023-05-11 18:57:47 +00:00
|
|
|
//
|
|
|
|
// StatusEditPollView.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 5/11/23.
|
|
|
|
// Copyright © 2023 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Pachyderm
|
|
|
|
|
2023-05-13 19:00:03 +00:00
|
|
|
class StatusEditPollView: UIStackView, StatusContentPollView {
|
|
|
|
|
|
|
|
private var titleLabels: [EmojiLabel] = []
|
2023-05-11 18:57:47 +00:00
|
|
|
|
|
|
|
init() {
|
|
|
|
super.init(frame: .zero)
|
|
|
|
|
|
|
|
axis = .vertical
|
|
|
|
alignment = .leading
|
|
|
|
spacing = 4
|
|
|
|
}
|
|
|
|
|
|
|
|
required init(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUI(poll: StatusEdit.Poll?, emojis: [Emoji]) {
|
|
|
|
arrangedSubviews.forEach { $0.removeFromSuperview() }
|
2023-05-13 19:00:03 +00:00
|
|
|
titleLabels = []
|
2023-05-11 18:57:47 +00:00
|
|
|
|
|
|
|
for option in poll?.options ?? [] {
|
|
|
|
// the edit poll doesn't actually include the multiple value
|
2023-05-28 19:19:45 +00:00
|
|
|
let icon = PollOptionCheckboxView()
|
2023-05-11 18:57:47 +00:00
|
|
|
icon.readOnly = false // this is a lie, but it's only used for stylistic changes
|
|
|
|
let label = EmojiLabel()
|
|
|
|
label.text = option.title
|
|
|
|
label.setEmojis(emojis, identifier: Optional<String>.none)
|
2023-05-13 19:00:03 +00:00
|
|
|
titleLabels.append(label)
|
2023-05-11 18:57:47 +00:00
|
|
|
let stack = UIStackView(arrangedSubviews: [
|
|
|
|
icon,
|
|
|
|
label,
|
|
|
|
])
|
|
|
|
stack.axis = .horizontal
|
|
|
|
stack.alignment = .center
|
|
|
|
stack.spacing = 8
|
|
|
|
addArrangedSubview(stack)
|
|
|
|
}
|
|
|
|
}
|
2023-05-13 19:00:03 +00:00
|
|
|
|
|
|
|
func estimateHeight(effectiveWidth: CGFloat) -> CGFloat {
|
|
|
|
var height: CGFloat = 0
|
|
|
|
height += CGFloat(arrangedSubviews.count - 1) * 4
|
|
|
|
let labelWidth = effectiveWidth /* checkbox size: */ - 20 /* spacing: */ - 8
|
|
|
|
for titleLabel in titleLabels {
|
|
|
|
height += titleLabel.sizeThatFits(CGSize(width: labelWidth, height: UIView.layoutFittingCompressedSize.height)).height
|
|
|
|
}
|
|
|
|
return height
|
|
|
|
}
|
2023-05-11 18:57:47 +00:00
|
|
|
|
|
|
|
}
|