Skip to content

Commit

Permalink
Show the text style browser when viewing textStyles.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dabbott committed Oct 17, 2018
1 parent 9f14924 commit af11b54
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 289 deletions.
4 changes: 4 additions & 0 deletions studio/LonaStudio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
6BA5BBD72173A7F600F086A7 /* Shadows.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA5BBD62173A7F600F086A7 /* Shadows.swift */; };
6BA5BBD92174F2A500F086A7 /* FileNavigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA5BBD82174F2A500F086A7 /* FileNavigator.swift */; };
6BA5BBDB2174FA2100F086A7 /* FileNavigatorHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA5BBDA2174FA2100F086A7 /* FileNavigatorHeader.swift */; };
6BA5BBDF2176D93D00F086A7 /* TextStyleEditorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA5BBDE2176D93D00F086A7 /* TextStyleEditorViewController.swift */; };
6BA6E895212F92B0009CD33C /* Witness.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6BA6E894212F92B0009CD33C /* Witness.framework */; };
6BA6E896212F92B0009CD33C /* Witness.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6BA6E894212F92B0009CD33C /* Witness.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6BA6E89921307D65009CD33C /* WorkspaceWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA6E89821307D65009CD33C /* WorkspaceWindowController.swift */; };
Expand Down Expand Up @@ -429,6 +430,7 @@
6BA5BBD62173A7F600F086A7 /* Shadows.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shadows.swift; sourceTree = "<group>"; };
6BA5BBD82174F2A500F086A7 /* FileNavigator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileNavigator.swift; sourceTree = "<group>"; };
6BA5BBDA2174FA2100F086A7 /* FileNavigatorHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileNavigatorHeader.swift; sourceTree = "<group>"; };
6BA5BBDE2176D93D00F086A7 /* TextStyleEditorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyleEditorViewController.swift; sourceTree = "<group>"; };
6BA6E894212F92B0009CD33C /* Witness.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Witness.framework; path = Carthage/Build/Mac/Witness.framework; sourceTree = "<group>"; };
6BA6E89821307D65009CD33C /* WorkspaceWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceWindowController.swift; sourceTree = "<group>"; };
6BA6E89A213080CE009CD33C /* ComponentEditorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentEditorViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -546,6 +548,7 @@
307B7B4E1F9A71C5001A62D9 /* MetadataEditorView.swift */,
303C3FEF20A3A05D008E1541 /* RecentProjectsList.swift */,
300A0AFB1EDA0CBC00704DB7 /* SectionSplitter.swift */,
6BA5BBDE2176D93D00F086A7 /* TextStyleEditorViewController.swift */,
30C203DE20BF5955007C3FE0 /* TextStylePreviewCollection.swift */,
6B39E6F2212DB3AD0012DA4C /* UtilitiesView.swift */,
6BABAFE62139C341002B8C8F /* WorkspaceToolbar.swift */,
Expand Down Expand Up @@ -1261,6 +1264,7 @@
BA153BCA202B2D1F002A83A5 /* UndoManager.swift in Sources */,
6B5D4DA1213F05AF004F8AC3 /* CodeEditor.swift in Sources */,
3005A5381FA00FE000ABC5C2 /* CustomPopupField.swift in Sources */,
6BA5BBDF2176D93D00F086A7 /* TextStyleEditorViewController.swift in Sources */,
30EFC9581EF369DC0087711D /* ImageField.swift in Sources */,
30CE47811ED73FC800BBF716 /* TextField.swift in Sources */,
6BA6E89D2131CD09009CD33C /* JSONDocument.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion studio/LonaStudio/ForeignTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import ControlledComponents
import class ColorPicker.ColorWellPicker

public typealias ColorList = [CSColor]?

public typealias ColorHandler = ((CSColor?) -> Void)?

public typealias TextStyleList = [CSTextStyle]?
public typealias TextStyleHandler = ((CSTextStyle?) -> Void)?

public typealias StringHandler = ((String) -> Void)?
public typealias ColorPickerColor = Color?
public typealias ColorPickerHandler = ((Color) -> Void)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ public class ColorPreviewCollection: NSBox {
view1View.addSubview(colorPreviewCardView)
view2View.addSubview(colorPreviewCard2View)

fillColor = Colors.pink50
view1View.fillColor = #colorLiteral(red: 0.847058823529, green: 0.847058823529, blue: 0.847058823529, alpha: 1)
colorPreviewCardView.color = Colors.red500
colorPreviewCardView.colorCode = "#ff0000"
colorPreviewCardView.colorName = "Red"
colorPreviewCardView.selected = false
view2View.fillColor = #colorLiteral(red: 0.847058823529, green: 0.847058823529, blue: 0.847058823529, alpha: 1)
colorPreviewCardView.selected = true
colorPreviewCard2View.color = Colors.black
colorPreviewCard2View.colorCode = "Text"
colorPreviewCard2View.colorName = "Text"
Expand All @@ -99,8 +96,8 @@ public class ColorPreviewCollection: NSBox {
let spacer1ViewTopAnchorConstraint = spacer1View.topAnchor.constraint(equalTo: topAnchor, constant: 36)
let view2ViewLeadingAnchorConstraint = view2View.leadingAnchor.constraint(equalTo: spacer1View.trailingAnchor)
let view2ViewTopAnchorConstraint = view2View.topAnchor.constraint(equalTo: topAnchor, constant: 36)
let view1ViewHeightAnchorConstraint = view1View.heightAnchor.constraint(equalToConstant: 140)
let view1ViewWidthAnchorConstraint = view1View.widthAnchor.constraint(equalToConstant: 120)
let view1ViewHeightAnchorConstraint = view1View.heightAnchor.constraint(equalToConstant: 130)
let view1ViewWidthAnchorConstraint = view1View.widthAnchor.constraint(equalToConstant: 90)
let colorPreviewCardViewTopAnchorConstraint = colorPreviewCardView
.topAnchor
.constraint(equalTo: view1View.topAnchor)
Expand All @@ -115,8 +112,8 @@ public class ColorPreviewCollection: NSBox {
.constraint(equalTo: view1View.trailingAnchor)
let spacer1ViewHeightAnchorConstraint = spacer1View.heightAnchor.constraint(equalToConstant: 0)
let spacer1ViewWidthAnchorConstraint = spacer1View.widthAnchor.constraint(equalToConstant: 20)
let view2ViewHeightAnchorConstraint = view2View.heightAnchor.constraint(equalToConstant: 140)
let view2ViewWidthAnchorConstraint = view2View.widthAnchor.constraint(equalToConstant: 120)
let view2ViewHeightAnchorConstraint = view2View.heightAnchor.constraint(equalToConstant: 130)
let view2ViewWidthAnchorConstraint = view2View.widthAnchor.constraint(equalToConstant: 90)
let colorPreviewCard2ViewTopAnchorConstraint = colorPreviewCard2View
.topAnchor
.constraint(equalTo: view2View.topAnchor)
Expand Down
98 changes: 26 additions & 72 deletions studio/LonaStudio/Generated/components/TextStylePreviewCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public class TextStylePreviewCard: NSBox {
// MARK: Private

private var previewView = NSBox()
private var topLineView = NSBox()
private var exampleTextView = NSTextField(labelWithString: "")
private var bottomLineView = NSBox()
private var dividerView = NSBox()
private var detailsView = NSBox()
private var textStyleSummaryView = NSTextField(labelWithString: "")
Expand All @@ -64,91 +62,70 @@ public class TextStylePreviewCard: NSBox {
detailsView.boxType = .custom
detailsView.borderType = .noBorder
detailsView.contentViewMargins = .zero
topLineView.boxType = .custom
topLineView.borderType = .noBorder
topLineView.contentViewMargins = .zero
exampleTextView.lineBreakMode = .byWordWrapping
bottomLineView.boxType = .custom
bottomLineView.borderType = .noBorder
bottomLineView.contentViewMargins = .zero
textStyleSummaryView.lineBreakMode = .byWordWrapping

addSubview(previewView)
addSubview(dividerView)
addSubview(detailsView)
previewView.addSubview(topLineView)
previewView.addSubview(exampleTextView)
previewView.addSubview(bottomLineView)
detailsView.addSubview(textStyleSummaryView)

fillColor = Colors.white
cornerRadius = 4
borderWidth = 1
borderColor = Colors.grey300
exampleTextView.maximumNumberOfLines = 1
dividerView.fillColor = Colors.grey300
}

private func setUpConstraints() {
translatesAutoresizingMaskIntoConstraints = false
previewView.translatesAutoresizingMaskIntoConstraints = false
dividerView.translatesAutoresizingMaskIntoConstraints = false
detailsView.translatesAutoresizingMaskIntoConstraints = false
topLineView.translatesAutoresizingMaskIntoConstraints = false
exampleTextView.translatesAutoresizingMaskIntoConstraints = false
bottomLineView.translatesAutoresizingMaskIntoConstraints = false
textStyleSummaryView.translatesAutoresizingMaskIntoConstraints = false

let previewViewTopAnchorConstraint = previewView.topAnchor.constraint(equalTo: topAnchor, constant: 1)
let previewViewLeadingAnchorConstraint = previewView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 1)
let previewViewTopAnchorConstraint = previewView.topAnchor.constraint(equalTo: topAnchor, constant: 5)
let previewViewLeadingAnchorConstraint = previewView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 5)
let previewViewTrailingAnchorConstraint = previewView
.trailingAnchor
.constraint(equalTo: trailingAnchor, constant: -1)
.constraint(equalTo: trailingAnchor, constant: -5)
let dividerViewTopAnchorConstraint = dividerView.topAnchor.constraint(equalTo: previewView.bottomAnchor)
let dividerViewLeadingAnchorConstraint = dividerView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 1)
let dividerViewLeadingAnchorConstraint = dividerView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 5)
let dividerViewTrailingAnchorConstraint = dividerView
.trailingAnchor
.constraint(equalTo: trailingAnchor, constant: -1)
let detailsViewTopAnchorConstraint = detailsView.topAnchor.constraint(equalTo: dividerView.bottomAnchor)
let detailsViewLeadingAnchorConstraint = detailsView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 1)
.constraint(equalTo: trailingAnchor, constant: -5)
let detailsViewTopAnchorConstraint = detailsView
.topAnchor
.constraint(equalTo: dividerView.bottomAnchor, constant: 5)
let detailsViewLeadingAnchorConstraint = detailsView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 5)
let detailsViewTrailingAnchorConstraint = detailsView
.trailingAnchor
.constraint(equalTo: trailingAnchor, constant: -1)
let topLineViewTopAnchorConstraint = topLineView.topAnchor.constraint(equalTo: previewView.topAnchor, constant: 16)
let topLineViewLeadingAnchorConstraint = topLineView.leadingAnchor.constraint(equalTo: previewView.leadingAnchor)
let topLineViewTrailingAnchorConstraint = topLineView.trailingAnchor.constraint(equalTo: previewView.trailingAnchor)
let exampleTextViewTopAnchorConstraint = exampleTextView.topAnchor.constraint(equalTo: topLineView.bottomAnchor)
.constraint(equalTo: trailingAnchor, constant: -5)
let exampleTextViewTopAnchorConstraint = exampleTextView.topAnchor.constraint(equalTo: previewView.topAnchor)
let exampleTextViewBottomAnchorConstraint = exampleTextView
.bottomAnchor
.constraint(equalTo: previewView.bottomAnchor)
let exampleTextViewLeadingAnchorConstraint = exampleTextView
.leadingAnchor
.constraint(equalTo: previewView.leadingAnchor, constant: 20)
.constraint(equalTo: previewView.leadingAnchor, constant: 2)
let exampleTextViewTrailingAnchorConstraint = exampleTextView
.trailingAnchor
.constraint(lessThanOrEqualTo: previewView.trailingAnchor, constant: -20)
let bottomLineViewBottomAnchorConstraint = bottomLineView
.bottomAnchor
.constraint(equalTo: previewView.bottomAnchor, constant: -16)
let bottomLineViewTopAnchorConstraint = bottomLineView.topAnchor.constraint(equalTo: exampleTextView.bottomAnchor)
let bottomLineViewLeadingAnchorConstraint = bottomLineView
.leadingAnchor
.constraint(equalTo: previewView.leadingAnchor)
let bottomLineViewTrailingAnchorConstraint = bottomLineView
.trailingAnchor
.constraint(equalTo: previewView.trailingAnchor)
.constraint(lessThanOrEqualTo: previewView.trailingAnchor, constant: -2)
let dividerViewHeightAnchorConstraint = dividerView.heightAnchor.constraint(equalToConstant: 1)
let textStyleSummaryViewTopAnchorConstraint = textStyleSummaryView
.topAnchor
.constraint(equalTo: detailsView.topAnchor, constant: 16)
.constraint(equalTo: detailsView.topAnchor)
let textStyleSummaryViewBottomAnchorConstraint = textStyleSummaryView
.bottomAnchor
.constraint(equalTo: detailsView.bottomAnchor, constant: -16)
.constraint(equalTo: detailsView.bottomAnchor)
let textStyleSummaryViewLeadingAnchorConstraint = textStyleSummaryView
.leadingAnchor
.constraint(equalTo: detailsView.leadingAnchor, constant: 20)
.constraint(equalTo: detailsView.leadingAnchor)
let textStyleSummaryViewTrailingAnchorConstraint = textStyleSummaryView
.trailingAnchor
.constraint(lessThanOrEqualTo: detailsView.trailingAnchor, constant: -20)
let topLineViewHeightAnchorConstraint = topLineView.heightAnchor.constraint(equalToConstant: 1)
let bottomLineViewHeightAnchorConstraint = bottomLineView.heightAnchor.constraint(equalToConstant: 1)
.constraint(lessThanOrEqualTo: detailsView.trailingAnchor)
let textStyleSummaryViewHeightAnchorConstraint = textStyleSummaryView.heightAnchor.constraint(equalToConstant: 18)

NSLayoutConstraint.activate([
previewViewTopAnchorConstraint,
Expand All @@ -160,54 +137,31 @@ public class TextStylePreviewCard: NSBox {
detailsViewTopAnchorConstraint,
detailsViewLeadingAnchorConstraint,
detailsViewTrailingAnchorConstraint,
topLineViewTopAnchorConstraint,
topLineViewLeadingAnchorConstraint,
topLineViewTrailingAnchorConstraint,
exampleTextViewTopAnchorConstraint,
exampleTextViewBottomAnchorConstraint,
exampleTextViewLeadingAnchorConstraint,
exampleTextViewTrailingAnchorConstraint,
bottomLineViewBottomAnchorConstraint,
bottomLineViewTopAnchorConstraint,
bottomLineViewLeadingAnchorConstraint,
bottomLineViewTrailingAnchorConstraint,
dividerViewHeightAnchorConstraint,
textStyleSummaryViewTopAnchorConstraint,
textStyleSummaryViewBottomAnchorConstraint,
textStyleSummaryViewLeadingAnchorConstraint,
textStyleSummaryViewTrailingAnchorConstraint,
topLineViewHeightAnchorConstraint,
bottomLineViewHeightAnchorConstraint
textStyleSummaryViewHeightAnchorConstraint
])
}

private func update() {
bottomLineView.fillColor = Colors.white
detailsView.fillColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0)
previewView.fillColor = Colors.white
textStyleSummaryViewTextStyle = TextStyles.regular
textStyleSummaryView.attributedStringValue =
textStyleSummaryViewTextStyle.apply(to: textStyleSummaryView.attributedStringValue)
topLineView.fillColor = Colors.white
borderColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0)
previewView.fillColor = Colors.grey100
exampleTextView.attributedStringValue = exampleTextViewTextStyle.apply(to: example)
textStyleSummaryView.attributedStringValue = textStyleSummaryViewTextStyle.apply(to: textStyleSummary)
exampleTextViewTextStyle = textStyle
exampleTextView.attributedStringValue = exampleTextViewTextStyle.apply(to: exampleTextView.attributedStringValue)
if inverse {
previewView.fillColor = Colors.grey900
topLineView.fillColor = Colors.grey900
bottomLineView.fillColor = Colors.grey900
}
if selected {
detailsView.fillColor = Colors.lightblue600
topLineView.fillColor = Colors.grey200
bottomLineView.fillColor = Colors.grey200
textStyleSummaryViewTextStyle = TextStyles.regularInverse
textStyleSummaryView.attributedStringValue =
textStyleSummaryViewTextStyle.apply(to: textStyleSummaryView.attributedStringValue)
if inverse {
topLineView.fillColor = Colors.grey700
bottomLineView.fillColor = Colors.grey700
}
borderColor = Colors.lightblue600
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ public class TextStylePreviewCollection: NSBox {

// MARK: Lifecycle

public init() {
public init(
onSelectTextStyle: TextStyleHandler,
onChangeTextStyle: TextStyleHandler,
onDeleteTextStyle: TextStyleHandler,
onMoveTextStyle: ItemMoveHandler,
textStyles: TextStyleList)
{
self.onSelectTextStyle = onSelectTextStyle
self.onChangeTextStyle = onChangeTextStyle
self.onDeleteTextStyle = onDeleteTextStyle
self.onMoveTextStyle = onMoveTextStyle
self.textStyles = textStyles

super.init(frame: .zero)

setUpViews()
Expand All @@ -16,10 +28,28 @@ public class TextStylePreviewCollection: NSBox {
update()
}

public convenience init() {
self
.init(
onSelectTextStyle: nil,
onChangeTextStyle: nil,
onDeleteTextStyle: nil,
onMoveTextStyle: nil,
textStyles: nil)
}

public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: Public

public var onSelectTextStyle: TextStyleHandler { didSet { update() } }
public var onChangeTextStyle: TextStyleHandler { didSet { update() } }
public var onDeleteTextStyle: TextStyleHandler { didSet { update() } }
public var onMoveTextStyle: ItemMoveHandler { didSet { update() } }
public var textStyles: TextStyleList { didSet { update() } }

// MARK: Private

private func setUpViews() {
Expand Down
Loading

0 comments on commit af11b54

Please sign in to comment.