-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
mac/Bagel/Base/Views/VerticallyCenteredTextFieldCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// asdas.swift | ||
// Bagel | ||
// | ||
// Created by Yagiz Gurgul on 5/18/19. | ||
// Copyright © 2019 Yagiz Lab. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
//credits: https://stackoverflow.com/questions/11775128/set-text-vertical-center-in-nstextfield | ||
class VerticallyCenteredTextFieldCell: NSTextFieldCell { | ||
|
||
func adjustedFrame(toVerticallyCenterText rect: NSRect) -> NSRect { | ||
// super would normally draw text at the top of the cell | ||
var titleRect = super.titleRect(forBounds: rect) | ||
|
||
let minimumHeight = self.cellSize(forBounds: rect).height | ||
titleRect.origin.y += (titleRect.height - minimumHeight) / 2 | ||
titleRect.size.height = minimumHeight | ||
|
||
return titleRect | ||
} | ||
|
||
override func edit(withFrame rect: NSRect, in controlView: NSView, editor textObj: NSText, delegate: Any?, event: NSEvent?) { | ||
super.edit(withFrame: adjustedFrame(toVerticallyCenterText: rect), in: controlView, editor: textObj, delegate: delegate, event: event) | ||
} | ||
|
||
override func select(withFrame rect: NSRect, in controlView: NSView, editor textObj: NSText, delegate: Any?, start selStart: Int, length selLength: Int) { | ||
super.select(withFrame: adjustedFrame(toVerticallyCenterText: rect), in: controlView, editor: textObj, delegate: delegate, start: selStart, length: selLength) | ||
} | ||
|
||
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { | ||
super.drawInterior(withFrame: adjustedFrame(toVerticallyCenterText: cellFrame), in: controlView) | ||
} | ||
|
||
override func draw(withFrame cellFrame: NSRect, in controlView: NSView) { | ||
super.draw(withFrame: cellFrame, in: controlView) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters