Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve text measurement logic and implement proper text padding #88

Merged
merged 2 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/esy.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@esy-ocaml/reason": ">=3.4.0",
"@opam/color": "^0.2.0",
"@opam/dune": "^1.7.2",
"flex": "^1.2.2",
"flex": "briskml/flex#7042e49",
"ocaml": "~4.7.1000"
}
}
46 changes: 26 additions & 20 deletions core/lib/Layout.re
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
| `CharWrap
| `Clip
| `TruncateHead
| `TruncateTale
| `TruncateTail
| `TruncateMiddle
];

Expand Down Expand Up @@ -257,47 +257,47 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
{
...style,
positionType,
left: !isUndefined(left) ? int_of_scalar(left) : style.left,
top: !isUndefined(top) ? int_of_scalar(top) : style.top,
right: !isUndefined(right) ? int_of_scalar(right) : style.right,
bottom: !isUndefined(bottom) ? int_of_scalar(bottom) : style.bottom,
left: !isUndefined(left) ? left : style.left,
top: !isUndefined(top) ? top : style.top,
right: !isUndefined(right) ? right : style.right,
bottom: !isUndefined(bottom) ? bottom : style.bottom,
wokalski marked this conversation as resolved.
Show resolved Hide resolved
};
| `Flex(f) => {...style, flex: int_of_scalar(f)}
| `Flex(flex) => {...style, flex}
| `FlexDirection(flexDirection) => {...style, flexDirection}
| `FlexGrow(f) => {...style, flexGrow: int_of_scalar(f)}
| `FlexShrink(f) => {...style, flexShrink: int_of_scalar(f)}
| `FlexBasis(f) => {...style, flexBasis: int_of_scalar(f)}
| `FlexGrow(flexGrow) => {...style, flexGrow}
| `FlexShrink(flexShrink) => {...style, flexShrink}
| `FlexBasis(flexBasis) => {...style, flexBasis}
| `JustifyContent(justifyContent) => {...style, justifyContent}
| `AlignContent(alignContent) => {...style, alignContent}
| `AlignItems(alignItems) => {...style, alignItems}
| `AlignSelf(alignSelf) => {...style, alignSelf}
| `Width(w) => {...style, width: int_of_scalar(w)}
| `Height(h) => {...style, height: int_of_scalar(h)}
| `Width(w) => {...style, width: w}
| `Height(h) => {...style, height: h}
| `Overflow(overflow) => {...style, overflow}
| `Border({Border.width, _}) => {
...style,
border: !isUndefined(width) ? int_of_scalar(width) : style.border,
border: !isUndefined(width) ? width : style.border,
}
| `Padding({left, top, right, bottom}) => {
...style,
paddingLeft:
!isUndefined(left) ? int_of_scalar(left) : style.paddingLeft,
!isUndefined(left) ? left : style.paddingLeft,
paddingTop:
!isUndefined(top) ? int_of_scalar(top) : style.paddingTop,
!isUndefined(top) ? top : style.paddingTop,
paddingRight:
!isUndefined(right) ? int_of_scalar(right) : style.paddingRight,
!isUndefined(right) ? right : style.paddingRight,
paddingBottom:
!isUndefined(bottom) ? int_of_scalar(bottom) : style.paddingBottom,
!isUndefined(bottom) ? bottom : style.paddingBottom,
}
| `Margin({left, top, right, bottom}) => {
...style,
marginLeft:
!isUndefined(left) ? int_of_scalar(left) : style.marginLeft,
marginTop: !isUndefined(top) ? int_of_scalar(top) : style.marginTop,
!isUndefined(left) ? left : style.marginLeft,
marginTop: !isUndefined(top) ? top : style.marginTop,
marginRight:
!isUndefined(right) ? int_of_scalar(right) : style.marginRight,
!isUndefined(right) ? right : style.marginRight,
marginBottom:
!isUndefined(bottom) ? int_of_scalar(bottom) : style.marginBottom,
!isUndefined(bottom) ? bottom : style.marginBottom,
}
| _ => style
};
Expand Down Expand Up @@ -367,4 +367,10 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
markDirtyInternal(node);
};
};

let get0IfUndefined = x => {
isUndefined(x) ? Encoding.zero : x;
}

let cssUndefined = Encoding.cssUndefined;
};
11 changes: 8 additions & 3 deletions examples/hacker-news/app/TopStories.re
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ let story =
style=[
alignItems(`Center),
flexDirection(`Row),
position(~top=0., ~bottom=0., ~left=0., ~right=0., `Absolute),
]>
<text
style=[
height(20.),
width(30.),
align(`Center),
font(~size=13., ()),
color(Color.hex("#B0B0B0")),
/* Fixme, cannot fix any bc there'll be an exception */
Expand All @@ -110,13 +111,18 @@ let story =
style=[
flex(1.),
font(~size=13., ()),
lineBreak(`TruncateTail),
border(~width=1., ~color=Color.hex("#000000"), ()),
color(Color.hex("#000000")),
]
value={story.title}
/>
</view>
<text
style=Brisk.Layout.[color(Color.hex("#888888"))]
style=Brisk.Layout.[color(Color.hex("#888888")),
border(~width=1., ~color=Color.hex("#000000"), ()),

]
value={formatDetails(
~username=story.by.id,
~score=story.score,
Expand Down Expand Up @@ -228,7 +234,6 @@ let component = {
onReachedEnd=loadNextPage
style=Brisk.Layout.[
flex(1.),
padding4(~left=13., ()),
background(Color.hex("#fff")),
]>
...{
Expand Down
Binary file modified examples/hacker-news/designs/macos.sketch
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/hacker-news/esy.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"clean": "dune clean",
"bundle": "dune build @bundle --only-packages hacker-news --root . --no-buffer --force",
"run": "dune build @run --only-packages hacker-news --root . --no-buffer --force",
"watch": "esy run --watch"
"watch": "esy run --watch",
"open-xcode": "open ./_build/default/macos_app_bundle/project.xcodeproj"
},
"dependencies": {
"@esy-ocaml/reason": ">=3.4.0",
Expand Down
Loading