<commit_before>//  Copyright 2016 Skyscanner Ltd
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import UIKit

public class SkyFloatingLabelTextFieldWithIcon: SkyFloatingLabelTextField {
    
    public var iconLabel:UILabel!
    public var iconWidth:CGFloat = 20.0
    public var iconMarginLeft:CGFloat = 4.0
    
    /// A UIFont value that determines the font that the icon is using
    @IBInspectable
    public var iconFont:UIFont? {
        didSet {
            self.iconLabel?.font = iconFont
        }
    }
    
    /// A String value that determines the text used when displaying the icon
    @IBInspectable
    public var iconText:String? {
        didSet {
            self.iconLabel?.text = iconText
        }
    }
    
    /// A UIColor value that determines the color of the icon in the normal state
    @IBInspectable
    public var iconColor:UIColor = UIColor.grayColor() {
        didSet {
            self.updateIconLabelColor()
        }
    }
    
    /// A UIColor value that determines the color of the icon when the control is selected
    @IBInspectable
    public var selectedIconColor:UIColor = UIColor.grayColor() {
        didSet {
            self.updateIconLabelColor()
        }
    }
    
    /// A double value that determines the bottom margin of the icon. Use this value to position the icon more precisely vertically.
    @IBInspectable
    public var iconMarginBottom:Double = 4 {
        didSet {
            self.updateFrame()
        }
    }
    
    /// A dobule value that determines the rotation in degrees of the icon. Use this value to rotate the icon in either direction.
    @IBInspectable
    public var iconRotationDegrees:Double = 0 {
        didSet {
            self.iconLabel.transform = CGAffineTransformMakeRotation(CGFloat(iconRotationDegrees * M_PI / 180.0))
        }
    }
    
    // MARK: Initializers
    
    /**
    Initializes the control
    - parameter frame the frame of the control
    */
    override public init(frame: CGRect) {
        super.init(frame: frame)
        self.createIconLabel()
    }
    
    /**
     Intialzies the control by deserializing it
     - parameter coder the object to deserialize the control from
     */
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.createIconLabel()
    }
    
    // MARK: Creating the icon label
    
    /// Creates the icon label
    private func createIconLabel() {
        let iconLabel = UILabel()
        iconLabel.backgroundColor = UIColor.clearColor()
        iconLabel.textAlignment = .Center
        iconLabel.autoresizingMask = [.FlexibleTopMargin, .FlexibleRightMargin]
        self.iconLabel = iconLabel
        self.addSubview(iconLabel)
        
        self.updateIconLabelColor()
    }
    
    // MARK: Handling the icon color
    
    /// Update the colors for the control. Override to customize colors.
    override public func updateColors() {
        super.updateColors()
        self.updateIconLabelColor()
    }
    
    private func updateIconLabelColor() {
        if self.hasErrorMessage {
            self.iconLabel?.textColor = self.errorColor
        } else {
            self.iconLabel?.textColor = self.editing ? self.selectedIconColor : self.iconColor
        }
    }
    
    // MARK: Custom layout overrides
    
    /**
    Calculate the bounds for the textfield component of the control. Override to create a custom size textbox in the control.
    
    - parameter bounds The current bounds of the textfield component
    
    -returns The rectangle that the textfield component should render in
    */
    override public func textFieldRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.textFieldRectForBounds(bounds)
        rect.origin.x += (iconWidth + iconMarginLeft)
        rect.size.width -= (iconWidth + iconMarginLeft)
        return rect
    }
    
    /**
     Calculates the bounds for the placeholder component of the control. Override to create a custom size textbox in the control.
     
     - parameter bounds The current bounds of the placeholder component
     
     -returns The rectangle that the placeholder component should render in
     */
    override public func placeholderLabelRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.placeholderLabelRectForBounds(bounds)
        rect.origin.x += (iconWidth + iconMarginLeft)
        rect.size.width -= (iconWidth + iconMarginLeft)
        return rect
    }
    
    /// Invoked by layoutIfNeeded automatically
    override public func layoutSubviews() {
        super.layoutSubviews()
        self.updateFrame()
    }
    
    private func updateFrame() {
        let textHeight = self.textHeight()
        let marginBottom = CGFloat(self.iconMarginBottom)
        self.iconLabel.frame = CGRectMake(0, self.bounds.size.height - textHeight - marginBottom, iconWidth, textHeight)
    }
}
<commit_msg>Adding documentation to parts that were not covered.<commit_after>//  Copyright 2016 Skyscanner Ltd
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import UIKit

/**
 A beautiful and flexible textfield implementation with support for icon, title label, error message and placeholder.
 */
public class SkyFloatingLabelTextFieldWithIcon: SkyFloatingLabelTextField {
    
    /// A UILabel value that identifies the label used to display the icon
    public var iconLabel:UILabel!
    
    /// A UIFont value that determines the font that the icon is using
    @IBInspectable
    public var iconFont:UIFont? {
        didSet {
            self.iconLabel?.font = iconFont
        }
    }
    
    /// A String value that determines the text used when displaying the icon
    @IBInspectable
    public var iconText:String? {
        didSet {
            self.iconLabel?.text = iconText
        }
    }
    
    /// A UIColor value that determines the color of the icon in the normal state
    @IBInspectable
    public var iconColor:UIColor = UIColor.grayColor() {
        didSet {
            self.updateIconLabelColor()
        }
    }
    
    /// A UIColor value that determines the color of the icon when the control is selected
    @IBInspectable
    public var selectedIconColor:UIColor = UIColor.grayColor() {
        didSet {
            self.updateIconLabelColor()
        }
    }
    
    /// A double value that determines the width of the icon
    @IBInspectable public var iconWidth:Double = 20 {
        didSet {
            self.updateFrame()
        }
    }
    
    /// A double value that determines the left margin of the icon. Use this value to position the icon more precisely horizontally.
    @IBInspectable public var iconMarginLeft:Double = 4 {
        didSet {
            self.updateFrame()
        }
    }
    
    /// A double value that determines the bottom margin of the icon. Use this value to position the icon more precisely vertically.
    @IBInspectable
    public var iconMarginBottom:Double = 4 {
        didSet {
            self.updateFrame()
        }
    }
    
    /// A dobule value that determines the rotation in degrees of the icon. Use this value to rotate the icon in either direction.
    @IBInspectable
    public var iconRotationDegrees:Double = 0 {
        didSet {
            self.iconLabel.transform = CGAffineTransformMakeRotation(CGFloat(iconRotationDegrees * M_PI / 180.0))
        }
    }
    
    // MARK: Initializers
    
    /**
    Initializes the control
    - parameter frame the frame of the control
    */
    override public init(frame: CGRect) {
        super.init(frame: frame)
        self.createIconLabel()
    }
    
    /**
     Intialzies the control by deserializing it
     - parameter coder the object to deserialize the control from
     */
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.createIconLabel()
    }
    
    // MARK: Creating the icon label
    
    /// Creates the icon label
    private func createIconLabel() {
        let iconLabel = UILabel()
        iconLabel.backgroundColor = UIColor.clearColor()
        iconLabel.textAlignment = .Center
        iconLabel.autoresizingMask = [.FlexibleTopMargin, .FlexibleRightMargin]
        self.iconLabel = iconLabel
        self.addSubview(iconLabel)
        
        self.updateIconLabelColor()
    }
    
    // MARK: Handling the icon color
    
    /// Update the colors for the control. Override to customize colors.
    override public func updateColors() {
        super.updateColors()
        self.updateIconLabelColor()
    }
    
    private func updateIconLabelColor() {
        if self.hasErrorMessage {
            self.iconLabel?.textColor = self.errorColor
        } else {
            self.iconLabel?.textColor = self.editing ? self.selectedIconColor : self.iconColor
        }
    }
    
    // MARK: Custom layout overrides
    
    /**
    Calculate the bounds for the textfield component of the control. Override to create a custom size textbox in the control.
    
    - parameter bounds The current bounds of the textfield component
    
    -returns The rectangle that the textfield component should render in
    */
    override public func textFieldRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.textFieldRectForBounds(bounds)
        rect.origin.x += CGFloat(iconWidth + iconMarginLeft)
        rect.size.width -= CGFloat(iconWidth + iconMarginLeft)
        return rect
    }
    
    /**
     Calculates the bounds for the placeholder component of the control. Override to create a custom size textbox in the control.
     
     - parameter bounds The current bounds of the placeholder component
     
     -returns The rectangle that the placeholder component should render in
     */
    override public func placeholderLabelRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.placeholderLabelRectForBounds(bounds)
        rect.origin.x += CGFloat(iconWidth + iconMarginLeft)
        rect.size.width -= CGFloat(iconWidth + iconMarginLeft)
        return rect
    }
    
    /// Invoked by layoutIfNeeded automatically
    override public func layoutSubviews() {
        super.layoutSubviews()
        self.updateFrame()
    }
    
    private func updateFrame() {
        let textHeight = self.textHeight()
        let marginBottom = CGFloat(self.iconMarginBottom)
        self.iconLabel.frame = CGRectMake(0, self.bounds.size.height - textHeight - marginBottom, CGFloat(iconWidth), textHeight)
    }
}

{'fraction_non_alphanumeric': 0.06855647623201047, 'fraction_numerical': 0.0033144352376798954, 'mean_word_length': 2.3872968980797635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3392834', 'n_tokens_mistral': 3033, 'n_tokens_neox': 3004, 'n_words': 1040}