Skip to content

Commit

Permalink
Keep the left padding of the column's title in sync with the columns'…
Browse files Browse the repository at this point in the history
… contents, fixed #398 (#416)
  • Loading branch information
mikekazakov authored Oct 7, 2024
1 parent 6d46463 commit cfaa155
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,23 @@ - (void)calculateItemLayout

if( m_TableView )
m_TableView.rowHeight = m_Geometry.LineHeight();

// By default the offset of the title in the header cell is the same as the default offset in the geometry
for( auto column : {m_ExtensionColumn,
m_SizeColumn,
m_DateCreatedColumn,
m_DateAddedColumn,
m_DateModifiedColumn,
m_DateAccessedColumn,
m_TagsColumn} ) {
if( auto cell = objc_cast<PanelListViewTableHeaderCell>(column.headerCell) ) {
cell.leftOffset = static_cast<double>(m_Geometry.LeftInset());
}
}
// But for the filename column the offset is special
if( auto cell = objc_cast<PanelListViewTableHeaderCell>(m_NameColumn.headerCell) ) {
cell.leftOffset = static_cast<double>(m_Geometry.FilenameOffsetInColumn());
}
}

- (void)setupIconsPxSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class PanelListViewGeometry
short RightInset() const { return 5; }
short BottomInset() const { return 1; }

// Returns the the left offset of the filename text in its column
short FilenameOffsetInColumn() const noexcept;

private:
short m_LineHeight;
short m_TextBaseLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@
std::tie(m_LineHeight, m_TextBaseLine, m_IconSize) = GrabGeometryFromSystemFont(_font, _icon_scale);
}

short PanelListViewGeometry::FilenameOffsetInColumn() const noexcept
{
return static_cast<short>(IconSize() ? 2 * LeftInset() + IconSize() : LeftInset());
}

} // namespace nc::panel
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (void)setFilename:(NSString *)_filename andTags:(std::span<const nc::utility::

- (NSRect)calculateTextSegmentFromBounds:(NSRect)bounds andGeometry:(const PanelListViewGeometry &)g
{
const int origin = g.IconSize() ? 2 * g.LeftInset() + g.IconSize() : g.LeftInset();
const int origin = g.FilenameOffsetInColumn();
const auto tags_geom = TrailingTagsInplaceDisplay::Place(m_Tags);
const auto width = bounds.size.width - origin - g.RightInset() - tags_geom.margin - tags_geom.width;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class PanelListViewTableHeaderCell: NSTableHeaderCell {
var separatorColor: NSColor = NSColor.black
var sortIndicator: NSImage?
var tintedSortIndicator: NSImage?
@objc public var leftOffset: Double = 4.0

// RTFM "NSCopyObject() + NSCell + crash" to learn why this abomination is required
public override func copy(with zone: NSZone? = nil) -> Any {
Expand Down Expand Up @@ -90,7 +91,6 @@ public class PanelListViewTableHeaderCell: NSTableHeaderCell {
}

// Now draw the column title
let left_padding = Double(4)
var trc = drawingRect(forBounds: cellFrame)
trc.size.height -= 1 // eaten by the horizontal separator at the bottom
trc.size.width -= 1 // eatern by the vertical separator at the right
Expand All @@ -109,7 +109,7 @@ public class PanelListViewTableHeaderCell: NSTableHeaderCell {
if self.alignment == NSTextAlignment.right {
trc = NSMakeRect(trc.origin.x, top, trc.size.width, height)
} else if self.alignment == NSTextAlignment.left {
trc = NSMakeRect(trc.origin.x + left_padding, top, trc.size.width - left_padding, height)
trc = NSMakeRect(trc.origin.x + leftOffset, top, trc.size.width - leftOffset, height)
} else { // center
trc = NSMakeRect(trc.origin.x, top, trc.size.width, height)
}
Expand Down

0 comments on commit cfaa155

Please sign in to comment.