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

Components app #72

Merged
merged 22 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f207f49
Bump deps
rauanmayemir Feb 28, 2019
6a744a1
Various bindings improvements
rauanmayemir Feb 28, 2019
42ee24d
Implement view Shadow styling
rauanmayemir Feb 28, 2019
0ca80eb
Allow viewStyle attributes on EffectView
rauanmayemir Feb 28, 2019
11e64c0
Add View styles, factor out entry point to the Main module
rauanmayemir Feb 28, 2019
c12060c
Fix NSScrollView flipping, refactor component to use composed views
rauanmayemir Mar 2, 2019
35b75df
Add View background clipping
rauanmayemir Mar 2, 2019
ca44a8e
Improve components app styling
rauanmayemir Mar 2, 2019
ae760db
Implement removing the layout child node
rauanmayemir Mar 2, 2019
7566f67
Bake Y axis flipping in to layout context logic
rauanmayemir Mar 3, 2019
5f16f4b
Implement basic Clickable component
rauanmayemir Mar 3, 2019
89233a1
Add components example tabs switcher reducer
rauanmayemir Mar 3, 2019
0110dca
Add logo in the Welcome tab
rauanmayemir Mar 3, 2019
1f99afa
Stubbed component example tabs
rauanmayemir Mar 3, 2019
bd978f1
Misc fixes from review feedback
rauanmayemir Mar 3, 2019
d0b5069
Fix callback gc pointer issue
rauanmayemir Mar 7, 2019
5613924
Fix button callback handler
rauanmayemir Mar 7, 2019
1f1e2ee
Specify why we're overriding acceptsFirstMouse on BriskClickable
rauanmayemir Mar 7, 2019
a3ac6ef
Misc component app improvements from review feedback
rauanmayemir Mar 7, 2019
b7ad22e
Add a note on the use of `isYAxisFlipped` in macos renderer
rauanmayemir Mar 7, 2019
912671c
Improve type-safe style attributes composition
rauanmayemir Mar 7, 2019
8a44710
Use state hook for examples tabs
rauanmayemir Mar 7, 2019
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
50 changes: 41 additions & 9 deletions core/lib/Layout.re
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
~bottom=cssUndefined,
position,
) => {
let pos: t = {
`Position({
position,
inset: {
left,
top,
right,
bottom,
},
};
`Position(pos);
});
};
};

Expand All @@ -61,8 +60,7 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
};

let make = (~family="", ~size=cssUndefined, ~weight=`Regular, ()) => {
let font: t = {family, size, weight};
`Font(font);
`Font({family, size, weight});
};
};

Expand Down Expand Up @@ -99,16 +97,38 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
~color=Color0.undefined,
(),
) => {
let border: t = {width, radius, color};
`Border(border);
`Border({width, radius, color});
};

let width = (width: Encoding.scalar) => make(~width, ());
let color = (color: Color0.t) => make(~color, ());
rauanmayemir marked this conversation as resolved.
Show resolved Hide resolved
};

module Shadow = {
type t = {
x: scalar,
y: scalar,
opacity: scalar,
blur: scalar,
color: Color0.t,
};

let make =
(
~x=cssUndefined,
~y=cssUndefined,
~opacity=cssUndefined,
~blur=cssUndefined,
~color=Color0.undefined,
(),
) => {
`Shadow({x, y, opacity, blur, color});
};
};

let position = Position.make;
let border = Border.make;
let shadow = Shadow.make;
let font = Font.make;
let kern = f => `Kern(f);
let align = Alignment.make;
Expand Down Expand Up @@ -226,7 +246,7 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {

let applyCommonStyle = (style: cssStyle, attribute: [> style]) =>
switch (attribute) {
| `Position(({position, inset}: Position.t)) =>
| `Position({Position.position, inset}) =>
let positionType =
switch (position) {
| `Absolute => Absolute
Expand Down Expand Up @@ -254,7 +274,7 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {
| `Width(w) => {...style, width: int_of_scalar(w)}
| `Height(h) => {...style, height: int_of_scalar(h)}
| `Overflow(overflow) => {...style, overflow}
| `Border(({width, _}: Border.t)) => {
| `Border({Border.width, _}) => {
...style,
border: !isUndefined(width) ? int_of_scalar(width) : style.border,
}
Expand Down Expand Up @@ -334,5 +354,17 @@ module Create = (Node: Flex.Spec.Node, Encoding: Flex.Spec.Encoding) => {

markDirtyInternal(node);
};

let removeChild = (node, child) => {
node.children =
node.children
|> Array.to_seq
|> Seq.filter(p => p === child)
wokalski marked this conversation as resolved.
Show resolved Hide resolved
|> Array.of_seq;

node.childrenCount = node.childrenCount - 1;

markDirtyInternal(node);
};
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images": [
{
"idiom": "universal",
"filename": "brisk.pdf",
"scale": "1x"
},
{
"idiom": "universal",
"scale": "2x"
},
{
"idiom": "universal",
"scale": "3x"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
Binary file not shown.
152 changes: 7 additions & 145 deletions examples/components-macos/bin/app.re
Original file line number Diff line number Diff line change
@@ -1,148 +1,6 @@
open Brisk_macos;
open Components_macos;

type tab =
| Welcome
| Views
| Buttons
| Text
| Image
| System;

type tabItem = {
kind: tab,
label: string,
};

let tabs = [
{kind: Welcome, label: "Welcome"},
{kind: Views, label: "Views"},
{kind: Buttons, label: "Buttons"},
{kind: Text, label: "Text"},
{kind: Image, label: "Image"},
];

type state = {currentTab: tab};

let app = (~children as _, ()) =>
Brisk.component("AppRoot", hooks => {
open Brisk.Layout;

let (state, setState, hooks) =
Brisk.Hooks.state({currentTab: Welcome}, hooks);
(
hooks,
{
let {currentTab} = state;

<view
style=[
position(~top=0., ~left=0., ~right=0., ~bottom=0., `Absolute),
flexDirection(`Row),
]>
<effectView
style=EffectView.[
blendingMode(`BehindWindow),
position(~top=0., ~left=0., ~bottom=0., `Absolute),
width(185.),
]>
<view style=[margin2(~v=37., ())]>
...{
tabs
|> List.map(tab =>
<text
style=[
font(~size=15., ()),
kern(0.09),
align(`Left),
color(Color.hex("#282522")),
background(
tab.kind == currentTab
? Color.hexa("#000000", 0.4)
: Color.transparent,
),
padding2(~h=25., ~v=4., ()),
]
value={tab.label}
/>
)
}
</view>
</effectView>
<scrollView
style=[
position(~top=0., ~left=185., ~right=0., ~bottom=0., `Absolute),
padding4(~top=20., ~left=13., ()),
]>
<text
style=[
font(~size=24., ~weight=`Semibold, ()),
kern(0.58),
align(`Left),
color(Color.hex("#000000")),
background(Color.transparent),
]
value="Welcome to Brisk"
/>
<view style=[justifyContent(`Center), alignContent(`Center)]>
<text
style=[
font(~size=18., ()),
align(`Center),
alignSelf(`Center),
width(200.),
border(~radius=10., ()),
color(Color.hex("#ffffff")),
background(Color.hexa("#263ac5", 0.9)),
margin(20.),
padding2(~h=10., ~v=10., ()),
]
value="Text bubble"
/>
</view>
<button
style=[
width(400.),
height(60.),
margin4(~top=20., ()),
alignSelf(`Center),
font(~size=16., ()),
color(Color.hex("#ffffff")),
background(Color.hex("#263ac5")),
align(`Center),
]
title="You're gonna have to wait 1 second"
callback={() =>
Lwt.Infix.(
ignore(
Lwt_unix.sleep(1.)
>>= (_ => Lwt.return(setState(state))),
)
)
}
/>
<view style=[alignContent(`Center), height(600.)]>
<text
style=[
font(~size=18., ()),
align(`Center),
alignSelf(`Center),
width(200.),
height(300.),
border(~radius=10., ()),
color(Color.hex("#011021")),
margin(20.),
padding2(~h=10., ~v=10., ()),
]
value="Very large height for scrolling"
/>
</view>
</scrollView>
</view>;
},
);
});

let () = {
open Cocoa;

Expand All @@ -151,7 +9,7 @@ let () = {
Application.init();

Application.willFinishLaunching(() => {
let menu = UiMenu.makeMainMenu(appName);
let menu = MainMenu.make(appName);
Menu.add(~kind=Main, menu);
});

Expand Down Expand Up @@ -183,12 +41,16 @@ let () = {
width(Window.contentWidth(window)),
height(Window.contentHeight(window)),
],
view,
{view, isYAxisFlipped: false},
);
{Brisk.OutputTree.view, layoutNode};
};

UI.renderAndMount(~height=Window.contentHeight(window), root, <app />);
UI.renderAndMount(
~height=Window.contentHeight(window),
root,
Main.(<app />),
);

RunLoop.spawn();
});
Expand Down
3 changes: 1 addition & 2 deletions examples/components-macos/esy.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"dependencies": {
"@esy-ocaml/reason": ">=3.4.0",
"@brisk/macos": "*",
"@opam/dune": "^1.7.2",
"@opam/cohttp-lwt-unix": "^1.2.0",
"@opam/dune": "^1.7.3",
"ocaml": "~4.7.1000"
},
"devDependencies": {
Expand Down
Loading