Skip to content

Commit

Permalink
fixed filter field vertical issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yagiz-tlb committed May 18, 2019
1 parent c76fa31 commit 876fb1e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
4 changes: 4 additions & 0 deletions mac/Bagel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
8A814D04228ECCED0049A64E /* DetailSectionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailSectionProtocol.swift; sourceTree = "<group>"; };
8A814D06229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticallyCenteredTextFieldCell.swift; sourceTree = "<group>"; };
BC1F5B36216746D30045C871 /* FontManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManager.swift; sourceTree = "<group>"; };
BC32643521738AF0006452FE /* KeyValueRepresentation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyValueRepresentation.swift; sourceTree = "<group>"; };
BC5E76C8216A64DB000F658D /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -596,6 +598,7 @@
BCB6FD6821627D5400D6F03C /* TransparentSplitView.swift */,
BCDF0EC321662CA10030710C /* FlatTableRowView.swift */,
BC911A462168EB0A00B755D4 /* ContentBar.swift */,
8A814D06229025FF0049A64E /* VerticallyCenteredTextFieldCell.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
40 changes: 40 additions & 0 deletions mac/Bagel/Base/Views/VerticallyCenteredTextFieldCell.swift
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)
}
}
12 changes: 6 additions & 6 deletions mac/Bagel/Components/Packets/Packets.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Nh8-PV-Qe4">
<rect key="frame" x="3" y="0.0" width="194" height="20"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" placeholderString="URL..." id="OhO-md-Jfb">
<font key="font" metaFont="system" size="11"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" alignment="left" placeholderString="URL" id="OhO-md-Jfb" customClass="VerticallyCenteredTextFieldCell" customModule="Bagel" customModuleProvider="target">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="labelColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -268,8 +268,8 @@
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="K4O-j7-3QY">
<rect key="frame" x="3" y="0.0" width="66" height="20"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" placeholderString="Status..." id="phe-Xy-3Ds">
<font key="font" metaFont="system"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" placeholderString="Status" id="phe-Xy-3Ds" customClass="VerticallyCenteredTextFieldCell" customModule="Bagel" customModuleProvider="target">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="labelColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -295,8 +295,8 @@
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="H4n-d7-YFE">
<rect key="frame" x="3" y="0.0" width="66" height="20"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" placeholderString="Method..." id="OPB-NY-4Xr">
<font key="font" metaFont="system"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" placeholderString="Method" id="OPB-NY-4Xr" customClass="VerticallyCenteredTextFieldCell" customModule="Bagel" customModuleProvider="target">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="labelColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand Down

0 comments on commit 876fb1e

Please sign in to comment.