<commit_before>// MIT license. Copyright (c) 2015 SwiftyFORM. All rights reserved.
import UIKit
import SwiftyFORM

class ColorPickerViewController: FormViewController {
	override func populate(builder: FormBuilder) {
		builder.navigationTitle = "Color picker"
		builder.toolbarMode = .None

		builder.demo_showInfo("Tap row to expand/collapse.\nPinch to change precision.\nPan to change value.")

		builder += SectionHeaderTitleFormItem().title("Components")
		builder += slider0
		builder += slider1
		builder += slider2
		
		builder += SectionHeaderTitleFormItem().title("Summary")
		builder += summary
		builder += SectionFormItem()
		builder += randomizeButton
		
		updateSummary()
		updateColor()
	}
	
	lazy var slider0: PrecisionSliderFormItem = {
		let instance = PrecisionSliderFormItem().decimalPlaces(3).minimumValue(0).maximumValue(1000).value(500)
		instance.title = "Red"
		instance.sliderDidChangeBlock = { [weak self] _ in
			self?.updateSummary()
			self?.updateColor()
		}
		return instance
	}()
	
	lazy var slider1: PrecisionSliderFormItem = {
		let instance = PrecisionSliderFormItem().decimalPlaces(3).minimumValue(0).maximumValue(1000).value(500)
		instance.title = "Green"
		instance.sliderDidChangeBlock = { [weak self] _ in
			self?.updateSummary()
			self?.updateColor()
		}
		return instance
	}()
	
	lazy var slider2: PrecisionSliderFormItem = {
		let instance = PrecisionSliderFormItem().decimalPlaces(3).minimumValue(0).maximumValue(1000).value(500)
		instance.title = "Blue"
		instance.sliderDidChangeBlock = { [weak self] _ in
			self?.updateSummary()
			self?.updateColor()
		}
		return instance
	}()
	
	
	lazy var summary: StaticTextFormItem = {
		return StaticTextFormItem().title("Values").value("-")
	}()
	
	func updateSummary() {
		let s0 = String(format: "%.3f", slider0.actualValue)
		let s1 = String(format: "%.3f", slider1.actualValue)
		let s2 = String(format: "%.3f", slider2.actualValue)
		summary.value = "\(s0) , \(s1) , \(s2)"
	}
	
	func updateColor() {
		let color = UIColor(
			red: CGFloat(slider0.actualValue),
			green: CGFloat(slider1.actualValue),
			blue: CGFloat(slider2.actualValue),
			alpha: 1.0
		)
		view?.backgroundColor = color
	}

	lazy var randomizeButton: ButtonFormItem = {
		let instance = ButtonFormItem()
		instance.title("Randomize")
		instance.action = { [weak self] in
			self?.randomize()
		}
		return instance
	}()
	
	func assignRandomValue(formItem: PrecisionSliderFormItem) {
		formItem.value = randomInt(0, 1000)
	}
	
	func randomize() {
		assignRandomValue(slider0)
		assignRandomValue(slider1)
		assignRandomValue(slider2)
		updateSummary()
		updateColor()
	}
}<commit_msg>color picker now updates the navigationbar color, looks better<commit_after>// MIT license. Copyright (c) 2015 SwiftyFORM. All rights reserved.
import UIKit
import SwiftyFORM

class ColorPickerViewController: FormViewController {
	override func populate(builder: FormBuilder) {
		builder.navigationTitle = "Color picker"
		builder.toolbarMode = .None

		builder.demo_showInfo("Tap row to expand/collapse.\nPinch to change precision.\nPan to change value.")

		builder += SectionHeaderTitleFormItem().title("Components")
		builder += slider0
		builder += slider1
		builder += slider2
		
		builder += SectionHeaderTitleFormItem().title("Summary")
		builder += summary
		builder += SectionFormItem()
		builder += randomizeButton
		
		updateSummary()
		updateColor()
	}
	
	lazy var slider0: PrecisionSliderFormItem = {
		let instance = PrecisionSliderFormItem().decimalPlaces(3).minimumValue(0).maximumValue(1000).value(500)
		instance.title = "Red"
		instance.sliderDidChangeBlock = { [weak self] _ in
			self?.updateSummary()
			self?.updateColor()
		}
		return instance
	}()
	
	lazy var slider1: PrecisionSliderFormItem = {
		let instance = PrecisionSliderFormItem().decimalPlaces(3).minimumValue(0).maximumValue(1000).value(500)
		instance.title = "Green"
		instance.sliderDidChangeBlock = { [weak self] _ in
			self?.updateSummary()
			self?.updateColor()
		}
		return instance
	}()
	
	lazy var slider2: PrecisionSliderFormItem = {
		let instance = PrecisionSliderFormItem().decimalPlaces(3).minimumValue(0).maximumValue(1000).value(500)
		instance.title = "Blue"
		instance.sliderDidChangeBlock = { [weak self] _ in
			self?.updateSummary()
			self?.updateColor()
		}
		return instance
	}()
	
	
	lazy var summary: StaticTextFormItem = {
		return StaticTextFormItem().title("Values").value("-")
	}()
	
	func updateSummary() {
		let s0 = String(format: "%.3f", slider0.actualValue)
		let s1 = String(format: "%.3f", slider1.actualValue)
		let s2 = String(format: "%.3f", slider2.actualValue)
		summary.value = "\(s0) , \(s1) , \(s2)"
	}
	
	func updateColor() {
		let color = UIColor(
			red: CGFloat(slider0.actualValue),
			green: CGFloat(slider1.actualValue),
			blue: CGFloat(slider2.actualValue),
			alpha: 1.0
		)
		view?.backgroundColor = color
		
		navigationController?.navigationBar.barTintColor = color
		navigationController?.navigationBar.translucent = false
	}

	lazy var randomizeButton: ButtonFormItem = {
		let instance = ButtonFormItem()
		instance.title("Randomize")
		instance.action = { [weak self] in
			self?.randomize()
		}
		return instance
	}()
	
	func assignRandomValue(formItem: PrecisionSliderFormItem) {
		formItem.value = randomInt(0, 1000)
	}
	
	func randomize() {
		assignRandomValue(slider0)
		assignRandomValue(slider1)
		assignRandomValue(slider2)
		updateSummary()
		updateColor()
	}

	override func viewWillDisappear(animated: Bool) {
		super.viewWillDisappear(animated)
		
		// restore the navigationbar theme when leaving this page
		navigationController?.navigationBar.barTintColor = nil
		navigationController?.navigationBar.translucent = true
	}
}
{'fraction_non_alphanumeric': 0.12036230621842885, 'fraction_numerical': 0.021599024560181153, 'mean_word_length': 4.569350145489816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4619377', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1784, 'n_words': 379}