From 876fb1e02fc43f742453fe38a8be2ffe522e1bad Mon Sep 17 00:00:00 2001 From: Yagiz Gurgul Date: Sat, 18 May 2019 15:40:41 +0400 Subject: [PATCH] fixed filter field vertical issue --- mac/Bagel.xcodeproj/project.pbxproj | 4 ++ .../VerticallyCenteredTextFieldCell.swift | 40 +++++++++++++++++++ .../Components/Packets/Packets.storyboard | 12 +++--- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 mac/Bagel/Base/Views/VerticallyCenteredTextFieldCell.swift diff --git a/mac/Bagel.xcodeproj/project.pbxproj b/mac/Bagel.xcodeproj/project.pbxproj index 1d2bebf..641358c 100644 --- a/mac/Bagel.xcodeproj/project.pbxproj +++ b/mac/Bagel.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1191142A21F8B9CB00BFCA48 /* CURLRepresentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1191142921F8B9CB00BFCA48 /* CURLRepresentation.swift */; }; 8A814D05228ECCED0049A64E /* DetailSectionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A814D04228ECCED0049A64E /* DetailSectionProtocol.swift */; }; + 8A814D07229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A814D06229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift */; }; 9AAA3A9C54B46F8D2C8DD674 /* Pods_Bagel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00E3BE2EECB0984D92EFCA30 /* Pods_Bagel.framework */; }; BC1F5B37216746D30045C871 /* FontManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC1F5B36216746D30045C871 /* FontManager.swift */; }; BC32643621738AF0006452FE /* KeyValueRepresentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC32643521738AF0006452FE /* KeyValueRepresentation.swift */; }; @@ -118,6 +119,7 @@ 00E3BE2EECB0984D92EFCA30 /* Pods_Bagel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Bagel.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1191142921F8B9CB00BFCA48 /* CURLRepresentation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CURLRepresentation.swift; sourceTree = ""; }; 8A814D04228ECCED0049A64E /* DetailSectionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailSectionProtocol.swift; sourceTree = ""; }; + 8A814D06229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticallyCenteredTextFieldCell.swift; sourceTree = ""; }; BC1F5B36216746D30045C871 /* FontManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManager.swift; sourceTree = ""; }; BC32643521738AF0006452FE /* KeyValueRepresentation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyValueRepresentation.swift; sourceTree = ""; }; BC5E76C8216A64DB000F658D /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; @@ -596,6 +598,7 @@ BCB6FD6821627D5400D6F03C /* TransparentSplitView.swift */, BCDF0EC321662CA10030710C /* FlatTableRowView.swift */, BC911A462168EB0A00B755D4 /* ContentBar.swift */, + 8A814D06229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift */, ); path = Views; sourceTree = ""; @@ -906,6 +909,7 @@ BCFC855021384981001EC6D7 /* BagelPacket.swift in Sources */, BCE21E3E2162C15900A65B29 /* KeyValueListViewController.swift in Sources */, BCA60B4E2162439E00B9DCAD /* URLPacketTableCellView.swift in Sources */, + 8A814D07229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift in Sources */, BCFC853B21384239001EC6D7 /* ProjectTableCellView.swift in Sources */, BCFC853E21384443001EC6D7 /* BaseTableView.swift in Sources */, BCBD86E62159172B009CBEA7 /* BagelDeviceController.swift in Sources */, diff --git a/mac/Bagel/Base/Views/VerticallyCenteredTextFieldCell.swift b/mac/Bagel/Base/Views/VerticallyCenteredTextFieldCell.swift new file mode 100644 index 0000000..5d74971 --- /dev/null +++ b/mac/Bagel/Base/Views/VerticallyCenteredTextFieldCell.swift @@ -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) + } +} diff --git a/mac/Bagel/Components/Packets/Packets.storyboard b/mac/Bagel/Components/Packets/Packets.storyboard index 484af4b..c656682 100644 --- a/mac/Bagel/Components/Packets/Packets.storyboard +++ b/mac/Bagel/Components/Packets/Packets.storyboard @@ -241,8 +241,8 @@ - - + + @@ -268,8 +268,8 @@ - - + + @@ -295,8 +295,8 @@ - - + +