fix: title could be off-center in app-icons appearance (closes #5235)
This commit is contained in:
1 parent
3e95f77cc0
commit
7fdfe4a9ee
1 file changed
+31
-26
@@ -260,42 +260,47 @@ class ThumbnailView: FlippedView {
|
|||||||
if isFocused || (!isFocused && !isHovered) {
|
if isFocused || (!isFocused && !isHovered) {
|
||||||
hoveredView?.label.isHidden = true
|
hoveredView?.label.isHidden = true
|
||||||
focusedView.label.isHidden = false
|
focusedView.label.isHidden = false
|
||||||
updateAppIconsLabelFrame(focusedView)
|
focusedView.updateAppIconsLabelFrame()
|
||||||
} else if isHovered {
|
} else if isHovered {
|
||||||
hoveredView?.label.isHidden = false
|
hoveredView?.label.isHidden = false
|
||||||
focusedView.label.isHidden = true
|
focusedView.label.isHidden = true
|
||||||
if let hoveredView {
|
if let hoveredView {
|
||||||
updateAppIconsLabelFrame(hoveredView)
|
hoveredView.updateAppIconsLabelFrame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getMaxAllowedLabelWidth(_ view: ThumbnailView) -> CGFloat {
|
private func getMaxAllowedLabelWidth() -> CGFloat {
|
||||||
let viewWidth = view.frame.width
|
let viewWidth = frame.width
|
||||||
let maxAllowedWidth = min(viewWidth * 2, ThumbnailsView.thumbnailsWidth)
|
let maxAllowedWidth = min(viewWidth * 2, ThumbnailsView.thumbnailsWidth)
|
||||||
let availableLeftWidth = view.isFirstInRow ? 0 : CGFloat(view.indexInRow) * viewWidth
|
let availableLeftWidth = isFirstInRow ? 0 : CGFloat(indexInRow) * viewWidth
|
||||||
let availableRightWidth = view.isLastInRow ? 0 : CGFloat(view.numberOfViewsInRow - 1 - view.indexInRow) * viewWidth
|
let availableRightWidth = isLastInRow ? 0 : CGFloat(numberOfViewsInRow - 1 - indexInRow) * viewWidth
|
||||||
let totalWidth = availableLeftWidth + availableRightWidth + viewWidth
|
let totalWidth = availableLeftWidth + availableRightWidth + viewWidth
|
||||||
let maxLabelWidth = min(totalWidth, maxAllowedWidth)
|
let maxLabelWidth = min(totalWidth, maxAllowedWidth)
|
||||||
return maxLabelWidth - Appearance.intraCellPadding * 2
|
return maxLabelWidth - Appearance.intraCellPadding * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateAppIconsLabelFrame(_ view: ThumbnailView) {
|
private func updateAppIconsLabelFrame() {
|
||||||
let viewWidth = view.frame.width
|
let viewWidth = frame.width
|
||||||
let labelWidth = view.label.cell!.cellSize.width
|
let labelWidth = label.cell!.cellSize.width
|
||||||
let maxAllowedLabelWidth = getMaxAllowedLabelWidth(view)
|
let padding = (Preferences.appearanceSize == .small ? 0 : ( Preferences.appearanceSize == .medium ? 1 : 2)) * Appearance.intraCellPadding
|
||||||
let effectiveLabelWidth = max(min(labelWidth, maxAllowedLabelWidth), viewWidth)
|
let maxAllowedLabelWidth = getMaxAllowedLabelWidth()
|
||||||
- (view.isFirstInRow && view.isLastInRow ? 4 : (view.isFirstInRow || view.isLastInRow ? 2 : 0)) * Appearance.intraCellPadding
|
let sidesToOffset: CGFloat = (isFirstInRow ? 1 : 0) + (isLastInRow ? 1 : 0)
|
||||||
var leftOffset = -Appearance.intraCellPadding * 2
|
let paddingForOffset = sidesToOffset * padding
|
||||||
if view.isFirstInRow && view.isLastInRow {
|
var effectiveLabelWidth = max(min(labelWidth, maxAllowedLabelWidth), viewWidth) - paddingForOffset
|
||||||
leftOffset = -Appearance.intraCellPadding * 2
|
// if the label is small, and with an offset only on one side, we reduce its width to center its text
|
||||||
|
if sidesToOffset == 1 && labelWidth <= (effectiveLabelWidth - paddingForOffset) {
|
||||||
} else if view.isLastInRow {
|
effectiveLabelWidth -= paddingForOffset
|
||||||
leftOffset = max(0, effectiveLabelWidth - viewWidth + Appearance.intraCellPadding * 2)
|
}
|
||||||
} else if !view.isFirstInRow && !view.isLastInRow {
|
var leftOffset = CGFloat(0)
|
||||||
|
if isFirstInRow {
|
||||||
|
leftOffset = -padding
|
||||||
|
} else if isLastInRow {
|
||||||
|
leftOffset = effectiveLabelWidth - viewWidth + padding
|
||||||
|
} else {
|
||||||
let halfNeededOffset = max(0, (effectiveLabelWidth - viewWidth) / 2)
|
let halfNeededOffset = max(0, (effectiveLabelWidth - viewWidth) / 2)
|
||||||
let availableLeftWidth = view.isFirstInRow ? 0 : CGFloat(view.indexInRow) * viewWidth
|
let availableLeftWidth = isFirstInRow ? 0 : CGFloat(indexInRow) * viewWidth
|
||||||
let availableRightWidth = view.isLastInRow ? 0 : CGFloat(view.numberOfViewsInRow - 1 - view.indexInRow) * viewWidth
|
let availableRightWidth = isLastInRow ? 0 : CGFloat(numberOfViewsInRow - 1 - indexInRow) * viewWidth
|
||||||
if availableLeftWidth >= halfNeededOffset && availableRightWidth >= halfNeededOffset {
|
if availableLeftWidth >= halfNeededOffset && availableRightWidth >= halfNeededOffset {
|
||||||
leftOffset = halfNeededOffset
|
leftOffset = halfNeededOffset
|
||||||
} else if availableLeftWidth <= halfNeededOffset && availableRightWidth <= halfNeededOffset {
|
} else if availableLeftWidth <= halfNeededOffset && availableRightWidth <= halfNeededOffset {
|
||||||
@@ -307,11 +312,11 @@ class ThumbnailView: FlippedView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let xPosition = -leftOffset
|
let xPosition = -leftOffset
|
||||||
let height = view.label.fittingSize.height
|
let height = label.fittingSize.height
|
||||||
let yPosition = view.hStackView.frame.origin.y + view.hStackView.frame.height + Appearance.intraCellPadding * 2
|
let yPosition = hStackView.frame.origin.y + hStackView.frame.height + Appearance.intraCellPadding * 2
|
||||||
view.label.frame = NSRect(x: xPosition, y: yPosition, width: effectiveLabelWidth, height: height)
|
label.frame = NSRect(x: xPosition, y: yPosition, width: effectiveLabelWidth, height: height)
|
||||||
view.label.setWidth(effectiveLabelWidth)
|
label.setWidth(effectiveLabelWidth)
|
||||||
view.label.toolTip = view.label.cell!.cellSize.width >= view.label.frame.size.width ? view.label.stringValue : nil
|
label.toolTip = label.cell!.cellSize.width >= label.frame.size.width ? label.stringValue : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateAppIcon(_ element: Window, _ title: String) {
|
private func updateAppIcon(_ element: Window, _ title: String) {
|
||||||
|
|||||||
Reference in new issue
Block a user