Skip to content

Commit

Permalink
Add recent project lists. Working text style assignments in logic... …
Browse files Browse the repository at this point in the history
…but redundant
  • Loading branch information
dabbott committed May 13, 2018
1 parent bf3d714 commit 4dc41b1
Show file tree
Hide file tree
Showing 28 changed files with 279 additions and 28 deletions.
3 changes: 3 additions & 0 deletions compiler/core/src/core/layer.re
Expand Up @@ -203,6 +203,9 @@ let parameterAssignmentsFromLogic = (layer, node) => {
);
};

/* Build a map from each layer, to a map from its parameter name to an assignment
[layer: [parameterName: Logic.Assign]]
*/
let logicAssignmentsFromLayerParameters = layer => {
let layerMap = ref(LayerMap.empty);
let extractParameters = (layer: Types.layer) => {
Expand Down
4 changes: 3 additions & 1 deletion compiler/core/src/swift/swiftComponent.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions compiler/core/src/swift/swiftComponent.re
Expand Up @@ -69,6 +69,8 @@ let generate =
| Low => "defaultLow";
let isParameterSetInitially = (layer: Types.layer, parameter) =>
StringMap.mem(parameter, layer.parameters);
let getParameter = (layer: Types.layer, parameter) =>
StringMap.find_opt(parameter, layer.parameters);
let isParameterAssigned = (layer: Types.layer, parameter) => {
let assignedParameters =
Layer.LayerMap.find_opt(layer, layerParameterAssignments);
Expand Down Expand Up @@ -488,10 +490,16 @@ let generate =
| None => LineComment(layer.name)
| Some(parameters) =>
let assignment = StringMap.find_opt(name, parameters);
let parameterName =
switch name {
| "textStyle" => "font"
| _ => name
};
let parameterValue = getParameter(layer, parameterName);
let logic =
switch (assignment, layer.typeName) {
| (Some(assignment), _) => assignment
| (None, Component(componentName)) =>
switch (assignment, layer.typeName, parameterValue) {
| (Some(assignment), _, _) => assignment
| (None, Component(componentName), _) =>
let param =
getComponent(componentName)
|> Decode.Component.parameters
Expand All @@ -501,7 +509,9 @@ let generate =
name,
Logic.defaultValueForType(param.ltype)
);
| (None, _) =>
| (None, _, Some(value)) =>
Logic.assignmentForLayerParameter(layer, name, value)
| (None, _, None) =>
Logic.defaultAssignmentForLayerParameter(
colors,
textStyles,
Expand Down
24 changes: 23 additions & 1 deletion compiler/core/src/swift/swiftLogic.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions compiler/core/src/swift/swiftLogic.re
Expand Up @@ -210,6 +210,45 @@ let toSwiftAST =
),
"operator": "=",
"right": right
}),
Ast.BinaryExpression({
"left":
Ast.SwiftIdentifier(
name
|> Js.String.replace(
".textStyle",
"."
++ SwiftDocument.labelAttributedTextName(
options.framework
)
)
),
"operator": "=",
"right":
Ast.MemberExpression([
Ast.SwiftIdentifier(
name |> Js.String.replace(".textStyle", "TextStyle")
),
Ast.FunctionCallExpression({
"name": Ast.SwiftIdentifier("apply"),
"arguments": [
Ast.FunctionCallArgument({
"name": Some(Ast.SwiftIdentifier("to")),
"value":
Ast.SwiftIdentifier(
name
|> Js.String.replace(
".textStyle",
"."
++ SwiftDocument.labelAttributedTextName(
options.framework
)
)
)
})
]
})
])
})
]);
| (Ast.SwiftIdentifier(name), right)
Expand Down
Expand Up @@ -89,6 +89,7 @@ public class NestedComponent: NSBox {
addSubview(text2View)

textViewTextStyle = TextStyles.subheading2
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
textView.attributedStringValue = textViewTextStyle.apply(to: "Example nested component")
text1View.attributedStringValue = text1ViewTextStyle.apply(to: "Text below")
text2View.attributedStringValue = text2ViewTextStyle.apply(to: "Very bottom")
Expand Down
1 change: 1 addition & 0 deletions examples/generated/test/appkit/interactivity/Button.swift
Expand Up @@ -76,6 +76,7 @@ public class Button: NSBox {
addSubview(textView)

textViewTextStyle = TextStyles.button
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
}

private func setUpConstraints() {
Expand Down
Expand Up @@ -89,6 +89,7 @@ public class PressableRootView: NSBox {
innerView.addSubview(innerTextView)

innerTextViewTextStyle = TextStyles.headline
innerTextView.attributedStringValue = innerTextViewTextStyle.apply(to: innerTextView.attributedStringValue)
}

private func setUpConstraints() {
Expand Down
2 changes: 2 additions & 0 deletions examples/generated/test/appkit/style/TextAlignment.swift
Expand Up @@ -305,8 +305,10 @@ public class TextAlignment: NSBox {
imageView.image = #imageLiteral(resourceName: "icon_128x128")
view2View.fillColor = #colorLiteral(red: 0.847058823529, green: 0.847058823529, blue: 0.847058823529, alpha: 1)
textViewTextStyle = TextStyles.display1.with(alignment: .center)
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
textView.attributedStringValue = textViewTextStyle.apply(to: "Welcome to Lona Studio")
text1ViewTextStyle = TextStyles.subheading2.with(alignment: .center)
text1View.attributedStringValue = text1ViewTextStyle.apply(to: text1View.attributedStringValue)
text1View.attributedStringValue = text1ViewTextStyle.apply(to: "Centered - Width: Fit")
text2View.attributedStringValue = text2ViewTextStyle.apply(to: "Left aligned - Width: Fill")
text3View.attributedStringValue = text3ViewTextStyle.apply(to: "Right aligned - Width: Fill")
Expand Down
Expand Up @@ -59,6 +59,7 @@ public class TextStyleConditional: NSBox {
addSubview(textView)

textViewTextStyle = TextStyles.headline
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
textView.attributedStringValue = textViewTextStyle.apply(to: "Text goes here")
}

Expand Down Expand Up @@ -99,9 +100,11 @@ public class TextStyleConditional: NSBox {
}

private func update() {
textViewTextStyle = TextStyles.body1
textViewTextStyle = TextStyles.headline
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
if large {
textViewTextStyle = TextStyles.display2
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
}
}
}
10 changes: 10 additions & 0 deletions examples/generated/test/appkit/style/TextStylesTest.swift
Expand Up @@ -148,24 +148,34 @@ public class TextStylesTest: NSBox {
addSubview(text9View)

textViewTextStyle = TextStyles.display4
textView.attributedStringValue = textViewTextStyle.apply(to: textView.attributedStringValue)
textView.attributedStringValue = textViewTextStyle.apply(to: "Text goes here")
text1ViewTextStyle = TextStyles.display3
text1View.attributedStringValue = text1ViewTextStyle.apply(to: text1View.attributedStringValue)
text1View.attributedStringValue = text1ViewTextStyle.apply(to: "Text goes here")
text2ViewTextStyle = TextStyles.display2
text2View.attributedStringValue = text2ViewTextStyle.apply(to: text2View.attributedStringValue)
text2View.attributedStringValue = text2ViewTextStyle.apply(to: "Text goes here")
text3ViewTextStyle = TextStyles.display1
text3View.attributedStringValue = text3ViewTextStyle.apply(to: text3View.attributedStringValue)
text3View.attributedStringValue = text3ViewTextStyle.apply(to: "Text goes here")
text4ViewTextStyle = TextStyles.headline
text4View.attributedStringValue = text4ViewTextStyle.apply(to: text4View.attributedStringValue)
text4View.attributedStringValue = text4ViewTextStyle.apply(to: "Text goes here")
text5ViewTextStyle = TextStyles.subheading2
text5View.attributedStringValue = text5ViewTextStyle.apply(to: text5View.attributedStringValue)
text5View.attributedStringValue = text5ViewTextStyle.apply(to: "Text goes here")
text6ViewTextStyle = TextStyles.subheading1
text6View.attributedStringValue = text6ViewTextStyle.apply(to: text6View.attributedStringValue)
text6View.attributedStringValue = text6ViewTextStyle.apply(to: "Text goes here")
text7ViewTextStyle = TextStyles.body2
text7View.attributedStringValue = text7ViewTextStyle.apply(to: text7View.attributedStringValue)
text7View.attributedStringValue = text7ViewTextStyle.apply(to: "Text goes here")
text8ViewTextStyle = TextStyles.body1
text8View.attributedStringValue = text8ViewTextStyle.apply(to: text8View.attributedStringValue)
text8View.attributedStringValue = text8ViewTextStyle.apply(to: "Text goes here")
text9ViewTextStyle = TextStyles.caption
text9View.attributedStringValue = text9ViewTextStyle.apply(to: text9View.attributedStringValue)
text9View.attributedStringValue = text9ViewTextStyle.apply(to: "Text goes here")
}

Expand Down
Expand Up @@ -86,6 +86,7 @@ public class NestedComponent: UIView {
addSubview(text2View)

textViewTextStyle = TextStyles.subheading2
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
textView.attributedText = textViewTextStyle.apply(to: "Example nested component")
text1View.attributedText = text1ViewTextStyle.apply(to: "Text below")
text2View.attributedText = text2ViewTextStyle.apply(to: "Very bottom")
Expand Down
1 change: 1 addition & 0 deletions examples/generated/test/swift/interactivity/Button.swift
Expand Up @@ -62,6 +62,7 @@ public class Button: UIView {
addSubview(textView)

textViewTextStyle = TextStyles.button
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
}

private func setUpConstraints() {
Expand Down
Expand Up @@ -72,6 +72,7 @@ public class PressableRootView: UIView {
innerView.addSubview(innerTextView)

innerTextViewTextStyle = TextStyles.headline
innerTextView.attributedText = innerTextViewTextStyle.apply(to: innerTextView.attributedText)
}

private func setUpConstraints() {
Expand Down
2 changes: 2 additions & 0 deletions examples/generated/test/swift/style/TextAlignment.swift
Expand Up @@ -281,8 +281,10 @@ public class TextAlignment: UIView {
imageView.image = #imageLiteral(resourceName: "icon_128x128")
view2View.backgroundColor = #colorLiteral(red: 0.847058823529, green: 0.847058823529, blue: 0.847058823529, alpha: 1)
textViewTextStyle = TextStyles.display1.with(alignment: .center)
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
textView.attributedText = textViewTextStyle.apply(to: "Welcome to Lona Studio")
text1ViewTextStyle = TextStyles.subheading2.with(alignment: .center)
text1View.attributedText = text1ViewTextStyle.apply(to: text1View.attributedText)
text1View.attributedText = text1ViewTextStyle.apply(to: "Centered - Width: Fit")
text2View.attributedText = text2ViewTextStyle.apply(to: "Left aligned - Width: Fill")
text3View.attributedText = text3ViewTextStyle.apply(to: "Right aligned - Width: Fill")
Expand Down
Expand Up @@ -56,6 +56,7 @@ public class TextStyleConditional: UIView {
addSubview(textView)

textViewTextStyle = TextStyles.headline
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
textView.attributedText = textViewTextStyle.apply(to: "Text goes here")
}

Expand Down Expand Up @@ -96,9 +97,11 @@ public class TextStyleConditional: UIView {
}

private func update() {
textViewTextStyle = TextStyles.body1
textViewTextStyle = TextStyles.headline
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
if large {
textViewTextStyle = TextStyles.display2
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
}
}
}
10 changes: 10 additions & 0 deletions examples/generated/test/swift/style/TextStylesTest.swift
Expand Up @@ -145,24 +145,34 @@ public class TextStylesTest: UIView {
addSubview(text9View)

textViewTextStyle = TextStyles.display4
textView.attributedText = textViewTextStyle.apply(to: textView.attributedText)
textView.attributedText = textViewTextStyle.apply(to: "Text goes here")
text1ViewTextStyle = TextStyles.display3
text1View.attributedText = text1ViewTextStyle.apply(to: text1View.attributedText)
text1View.attributedText = text1ViewTextStyle.apply(to: "Text goes here")
text2ViewTextStyle = TextStyles.display2
text2View.attributedText = text2ViewTextStyle.apply(to: text2View.attributedText)
text2View.attributedText = text2ViewTextStyle.apply(to: "Text goes here")
text3ViewTextStyle = TextStyles.display1
text3View.attributedText = text3ViewTextStyle.apply(to: text3View.attributedText)
text3View.attributedText = text3ViewTextStyle.apply(to: "Text goes here")
text4ViewTextStyle = TextStyles.headline
text4View.attributedText = text4ViewTextStyle.apply(to: text4View.attributedText)
text4View.attributedText = text4ViewTextStyle.apply(to: "Text goes here")
text5ViewTextStyle = TextStyles.subheading2
text5View.attributedText = text5ViewTextStyle.apply(to: text5View.attributedText)
text5View.attributedText = text5ViewTextStyle.apply(to: "Text goes here")
text6ViewTextStyle = TextStyles.subheading1
text6View.attributedText = text6ViewTextStyle.apply(to: text6View.attributedText)
text6View.attributedText = text6ViewTextStyle.apply(to: "Text goes here")
text7ViewTextStyle = TextStyles.body2
text7View.attributedText = text7ViewTextStyle.apply(to: text7View.attributedText)
text7View.attributedText = text7ViewTextStyle.apply(to: "Text goes here")
text8ViewTextStyle = TextStyles.body1
text8View.attributedText = text8ViewTextStyle.apply(to: text8View.attributedText)
text8View.attributedText = text8ViewTextStyle.apply(to: "Text goes here")
text9ViewTextStyle = TextStyles.caption
text9View.attributedText = text9ViewTextStyle.apply(to: text9View.attributedText)
text9View.attributedText = text9ViewTextStyle.apply(to: "Text goes here")
}

Expand Down
5 changes: 5 additions & 0 deletions studio/LonaStudio/Generated/TextStyles.swift
Expand Up @@ -14,5 +14,10 @@ class TextStyles {
color: Colors.black)
public static let large = AttributedFont(size: 15, lineHeight: 17, color: Colors.black)
public static let regular = AttributedFont(size: 13, lineHeight: 15, color: Colors.black)
public static let small = AttributedFont(size: 11, lineHeight: 13, color: Colors.black)
public static let regularMuted = AttributedFont(size: 13, lineHeight: 15, color: #colorLiteral(red: 0.509803921569, green: 0.509803921569, blue: 0.509803921569, alpha: 1))
public static let smallMuted = AttributedFont(size: 11, lineHeight: 13, color: #colorLiteral(red: 0.509803921569, green: 0.509803921569, blue: 0.509803921569, alpha: 1))
public static let largeInverse = AttributedFont(size: 15, lineHeight: 17, color: Colors.white)
public static let regularInverse = AttributedFont(size: 13, lineHeight: 15, color: Colors.white)
public static let smallInverse = AttributedFont(size: 11, lineHeight: 13, color: Colors.white)
}
Expand Up @@ -138,6 +138,7 @@ public class ColorPreviewCard: NSBox {
borderWidth = 1
dividerView.fillColor = Colors.grey300
colorNameViewTextStyle = TextStyles.large
colorNameView.attributedStringValue = colorNameViewTextStyle.apply(to: colorNameView.attributedStringValue)
colorNameView.maximumNumberOfLines = 1
}

Expand Down
Expand Up @@ -137,6 +137,8 @@ public class ComponentPreviewCard: NSBox {
borderWidth = 1
dividerView.fillColor = Colors.grey300
componentNameViewTextStyle = TextStyles.large
componentNameView.attributedStringValue =
componentNameViewTextStyle.apply(to: componentNameView.attributedStringValue)
componentNameView.maximumNumberOfLines = 1
}

Expand Down
2 changes: 2 additions & 0 deletions studio/LonaStudio/Generated/components/IconRow.swift
Expand Up @@ -119,7 +119,9 @@ public class IconRow: NSBox {
rowContentView.addSubview(subtitleView)

titleViewTextStyle = TextStyles.largeSemibold
titleView.attributedStringValue = titleViewTextStyle.apply(to: titleView.attributedStringValue)
subtitleViewTextStyle = TextStyles.regularMuted
subtitleView.attributedStringValue = subtitleViewTextStyle.apply(to: subtitleView.attributedStringValue)
}

private func setUpConstraints() {
Expand Down

0 comments on commit 4dc41b1

Please sign in to comment.