Skip to content

Commit

Permalink
Adjust event details size ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Jan 18, 2023
1 parent b467cd1 commit 7532fd0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Calendr/Events/EventDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {
private var animatesClose = true
private var mouseMovedEventMonitor: Any?

private lazy var notesHeightConstraint = notesTextView.height(equalTo: 0)

init(viewModel: EventDetailsViewModel) {

self.viewModel = viewModel
Expand Down Expand Up @@ -66,6 +68,7 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {
view = NSView()

view.widthAnchor.constraint(lessThanOrEqualToConstant: 400).activate()
view.widthAnchor.constraint(greaterThanOrEqualTo: view.heightAnchor, multiplier: 0.5).activate().priority = .dragThatCanResizeWindow

scrollView.hasVerticalScroller = true
scrollView.scrollerStyle = .overlay
Expand All @@ -80,6 +83,9 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {
scrollView.contentView.heightAnchor.constraint(lessThanOrEqualToConstant: 0.8 * NSScreen.main!.visibleFrame.height).activate()

contentStackView.addArrangedSubview(scrollView)
contentStackView.setHuggingPriority(.required, for: .vertical)

detailsStackView.setHuggingPriority(.required, for: .vertical)

view.addSubview(contentStackView)

Expand Down Expand Up @@ -212,11 +218,12 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {

private func addInformation() {

let titleStack = NSStackView(views: [titleLabel, eventTypeIcon, linkBtn]).with(alignment: .firstBaseline)
titleStack.setHuggingPriority(.required, for: .vertical)

if !viewModel.title.isEmpty {
titleLabel.stringValue = viewModel.title
detailsStackView.addArrangedSubview(
NSStackView(views: [titleLabel, eventTypeIcon, linkBtn]).with(alignment: .firstBaseline)
)
detailsStackView.addArrangedSubview(titleStack)
}

if !viewModel.url.isEmpty {
Expand Down Expand Up @@ -256,9 +263,9 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {
detailsStackView.addArrangedSubview(notesTextView)
}

override func viewWillAppear() {
super.viewWillAppear()
notesTextView.height(equalTo: notesTextView.contentSize.height)
override func viewDidLayout() {
super.viewDidLayout()
notesHeightConstraint.constant = notesTextView.contentSize.height
}

private func addParticipants() {
Expand Down Expand Up @@ -302,6 +309,7 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {
}

let stack = NSStackView(views: [status, label])
stack.setHuggingPriority(.required, for: .vertical)
label.setContentCompressionResistancePriority(.required, for: .vertical)

participantsStackView.addArrangedSubview(stack)
Expand All @@ -319,6 +327,8 @@ class EventDetailsViewController: NSViewController, NSPopoverDelegate {
scrollView.contentView.width(equalTo: participantsStackView, constant: 20)
scrollView.contentView.height(equalTo: participantsStackView).priority = .defaultHigh
scrollView.contentView.heightAnchor.constraint(lessThanOrEqualToConstant: 222).activate()

participantsStackView.setHuggingPriority(.required, for: .vertical)
participantsStackView.layoutSubtreeIfNeeded()
participantsStackView.scrollTop()
}
Expand Down

0 comments on commit 7532fd0

Please sign in to comment.