Skip to content

Commit 803efb3

Browse files
authored
Merge pull request #44 from ferus-web/ferus-leap
Ferus "Leap" branch
2 parents 2c1eb95 + 21f8aa3 commit 803efb3

30 files changed

+587
-443
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
!.github/*
66
!LICENSE
77
result
8+
src/bindings/install

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/third_party/yoga"]
2+
path = src/third_party/yoga
3+
url = https://github.com/facebook/yoga.git

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# The Ferus Web Engine
22
The Ferus web engine is a tiny web engine written in Nim which aims to be a full replacement for something like Chromium's Blink, Safari's WebKit or Firefox's Gecko. \
33
It has rudimentary support for layout and JavaScript.
4-
![A screenshot of Ferus rendering nim-lang.org](screenshots/ferus_nimlang.jpg)
4+
![A screenshot of Ferus rendering SourceHut](screenshots/ferus_sourcehut.jpg)
5+
![A screenshot of Ferus rendering GitHub](screenshots/ferus_github.jpg)
56

67
# Features
78
- When possible, we write our own solution to a component of the overall modern web stack. This has resulted in projects like Stylus (our CSS3 compliant parser derived from Servo) and Bali (our JavaScript engine based on Mirage, our bytecode interpreter) and Sanchar (our HTTP client and URL parser) that are beneficial for the overall Nim community.

assets/user-agent.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Ferus' user agent stylesheet.
3+
* This is the first stylesheet loaded into the layout engine.
4+
*
5+
* Author(s):
6+
* Trayambak Rai (xtrayambak at disroot dot org)
7+
*/
8+
9+
/* Paragraphs */
10+
p {
11+
font-size: 24px;
12+
}
13+
14+
strong { font-size: 24px; } /* FIXME: add support for multiple class matchers in one selector */
15+
16+
/* Headings
17+
* They progressively get smaller with each level.
18+
*/
19+
h1 { font-size: 32px; }
20+
h2 { font-size: 30px; }
21+
h3 { font-size: 28px; }
22+
h4 { font-size: 24px; }
23+
h5 { font-size: 22px; }
24+
h6 { font-size: 20px; }

ferus.nimble

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.2.3"
3+
version = "0.2.4"
44
author = "xTrayambak"
55
description = "The Ferus Web Engine"
66
license = "GPL3"
@@ -13,12 +13,12 @@ bin = @["ferus", "ferus_process"]
1313
requires "nim >= 2.0.2"
1414
requires "ferusgfx >= 1.2.1"
1515
requires "colored_logger >= 0.1.0"
16-
requires "stylus >= 0.1.1"
16+
requires "stylus#master"
1717
requires "https://github.com/ferus-web/sanchar >= 2.0.2"
1818
requires "https://git.sr.ht/~bptato/chame >= 1.0.1"
1919
requires "seccomp >= 0.2.1"
2020
requires "simdutf >= 5.5.0"
21-
requires "https://github.com/ferus-web/bali >= 0.5.0"
21+
requires "https://github.com/ferus-web/bali >= 0.6.3"
2222
requires "results >= 0.5.0"
2323
requires "pretty >= 0.1.0"
2424
requires "jsony >= 1.1.5"

flake.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
wayland-protocols
3131
wayland-scanner
3232
openssl
33+
cmake
34+
gnumake
3335
];
3436

3537
buildInputs = with pkgs; [
@@ -43,6 +45,7 @@
4345
xorg.libX11
4446
icu76
4547
libseccomp.dev
48+
boehmgc
4649
gmp
4750
openssl.dev
4851
xorg.libXext
@@ -54,6 +57,7 @@
5457
libGL
5558
simdutf
5659
openssl
60+
boehmgc
5761
curl.dev
5862
libseccomp.dev
5963
gmp.dev
@@ -67,6 +71,7 @@
6771
simdutf
6872
openssl.dev
6973
curl.dev
74+
boehmgc.dev
7075
libseccomp.dev
7176
gmp.dev
7277
glfw

screenshots/ferus_github.jpg

331 KB
Loading

screenshots/ferus_nimlang.jpg

-166 KB
Binary file not shown.

screenshots/ferus_sourcehut.jpg

258 KB
Loading

src/bindings/yoga.nim

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
## Yoga bindings
2+
##
3+
## Yoga is licensed under the MIT license.
4+
## Copyright (c) Meta Platforms, Inc. and affiliates.
5+
##
6+
## These bindings, however, are licensed under the GNU General Public License, version 3.
7+
## Author: Trayambak Rai (xtrayambak at disroot dot org)
8+
import std/[strutils]
9+
10+
static:
11+
let pwd = gorge("pwd")
12+
discard gorge("mkdir ../third_party/yoga/build")
13+
echo gorge(
14+
"cd ../third_party/yoga/build && cmake .. -DCMAKE_INSTALL_PREFIX=" & pwd & "/install"
15+
)
16+
echo gorge("cd ../third_party/yoga/build && make -j$(nproc)")
17+
echo gorge("cd ../third_party/yoga/build && make install")
18+
echo pwd
19+
20+
{.passC: "-I" & gorge("pwd") & "/install/include".}
21+
{.passL: "-L" & gorge("pwd") & "/install/lib64 -lyogacore".}
22+
23+
{.push header: "<yoga/Yoga.h>".}
24+
type
25+
YGAlign* {.importc, size: sizeof(cint).} = enum
26+
YGAlignAuto
27+
YGAlignFlexStart
28+
YGAlignCenter
29+
YGAlignFlexEnd
30+
YGAlignStretch
31+
YGAlignBaseline
32+
YGAlignSpaceBetween
33+
YGAlignSpaceAround
34+
YGAlignSpaceEvenly
35+
36+
YGDirection* {.importc, size: sizeof(cint).} = enum
37+
YGDirectionInherit
38+
YGDirectionLTR
39+
YGDirectionRTL
40+
41+
YGEdge* {.importc, size: sizeof(cint).} = enum
42+
YGEdgeLeft
43+
YGEdgeTop
44+
YGEdgeRight
45+
YGEdgeBottom
46+
YGEdgeStart
47+
YGEdgeEnd
48+
YGEdgeHorizontal
49+
YGEdgeVertical
50+
YGEdgeAll
51+
52+
YGJustify* {.importc, size: sizeof(cint).} = enum
53+
YGJustifyFlexStart
54+
YGJustifyCenter
55+
YGJustifyFlexEnd
56+
YGJustifySpaceBetween
57+
YGJustifySpaceAround
58+
YGJustifySpaceEvenly
59+
60+
YGFlexDirection* {.importc, size: sizeof(cint).} = enum
61+
YGFlexDirectionColumn
62+
YGFlexDirectionColumnReverse
63+
YGFlexDirectionRow
64+
YGFlexDirectionRowReverse
65+
66+
YGSize* {.bycopy, importc.} = object
67+
width*, height*: float
68+
69+
YGNode* {.importc.} = object
70+
YGNodeRef* {.importc.} = pointer
71+
72+
proc newYGNode*(): YGNodeRef {.importc: "YGNodeNew".}
73+
proc clone*(node: var YGNode) {.importc: "YGNodeClone".}
74+
proc free*(node: YGNodeRef) {.importc: "YGNodeFree".}
75+
proc freeRecursive*(node: YGNodeRef) {.importc: "YGNodeFreeRecursive".}
76+
proc finalize*(node: YGNodeRef) {.importc: "YGNodeFinalize".}
77+
proc reset*(node: YGNodeRef) {.importc: "YGNodeReset".}
78+
proc calculateLayout*(
79+
node: YGNodeRef, availableWidth, availableHeight: float, ownerDirection: YGDirection
80+
) {.importc: "YGNodeCalculateLayout".}
81+
82+
func hasNewLayout*(node: var YGNode): bool {.importc: "YGNodeGetHasNewLayout".}
83+
proc `hasNewLayout=`*(
84+
node: YGNodeRef, hasNewLayout: bool
85+
) {.importc: "YGNodeSetHasNewLayout".}
86+
87+
func isDirty*(node: var YGNode): bool {.importc: "YGNodeIsDirty".}
88+
proc markDirty*(node: YGNodeRef): bool {.importc: "YGNodeMarkDirty".}
89+
proc insertChild*(
90+
node: YGNodeRef, child: YGNodeRef, index: uint64
91+
) {.importc: "YGNodeInsertChild".}
92+
93+
proc swapChild*(
94+
node: YGNodeRef, child: YGNodeRef, index: uint64
95+
) {.importc: "YGNodeInsertChild".}
96+
97+
proc removeChild*(node: YGNodeRef, child: YGNodeRef) {.importc: "YGNodeRemoveChild".}
98+
proc removeAllChildren*(node: YGNodeRef) {.importc: "YGNodeRemoveAllChildren".}
99+
proc setChildrenInternal(
100+
owner: YGNodeRef, children: ptr UncheckedArray[YGNodeRef], count: uint64
101+
) {.importc: "YGNodeSetChildren".}
102+
103+
proc getChild*(node: YGNodeRef, index: uint64): YGNodeRef {.importc: "YGNodeGetChild".}
104+
proc childCount*(node: var YGNode): uint64 {.importc: "YGNodeGetChildCount".}
105+
proc getOwner*(node: YGNodeRef): YGNodeRef {.importc: "YGNodeGetOwner".}
106+
proc getParent*(node: YGNodeRef): YGNodeRef {.importc: "YGNodeGetParent".}
107+
108+
proc getLeft*(node: var YGNode): float {.importc: "YGNodeLayoutGetLeft".}
109+
proc getTop*(node: var YGNode): float {.importc: "YGNodeLayoutGetTop".}
110+
proc getRight*(node: var YGNode): float {.importc: "YGNodeLayoutGetRight".}
111+
proc getBottom*(node: var YGNode): float {.importc: "YGNodeLayoutGetBottom".}
112+
proc getWidth*(node: var YGNode): float {.importc: "YGNodeLayoutGetWidth".}
113+
proc getHeight*(node: var YGNode): float {.importc: "YGNodeLayoutGetHeight".}
114+
proc getDirection*(
115+
node: var YGNode
116+
): YGDirection {.importc: "YGNodeLayoutGetDirection".}
117+
118+
proc getHadOverflow*(node: var YGNode): bool {.importc: "YGNodeLayoutGetHadOverflow".}
119+
proc getMargin*(
120+
node: var YGNode, edge: YGEdge
121+
): float {.importc: "YGNodeLayoutGetMargin".}
122+
123+
proc getBorder*(
124+
node: var YGNode, edge: YGEdge
125+
): float {.importc: "YGNodeLayoutGetBorder".}
126+
127+
proc getPadding*(
128+
node: var YGNode, edge: YGEdge
129+
): float {.importc: "YGNodeLayoutGetPadding".}
130+
131+
proc copyStyle*(dest: YGNodeRef, srcNode: var YGNode) {.importc: "YGNodeCopyStyle".}
132+
proc setDirection*(
133+
node: YGNodeRef, direction: YGDirection
134+
) {.importc: "YGNodeStyleSetDirection".}
135+
136+
proc setFlexDirection*(
137+
node: YGNodeRef, flexDirection: YGFlexDirection
138+
) {.importc: "YGNodeStyleSetFlexDirection".}
139+
140+
proc getFlexDirection*(
141+
node: var YGNode
142+
): YGFlexDirection {.importc: "YGNodeStyleGetFlexDirection".}
143+
144+
proc setJustifyContent*(
145+
node: YGNodeRef, justifyContent: YGJustify
146+
) {.importc: "YGNodeStyleSetJustifyContent".}
147+
148+
proc getJustifyContent*(
149+
node: var YGNode
150+
): YGJustify {.importc: "YGNodeStyleGetJustifyContent".}
151+
152+
proc setWidth*(node: YGNodeRef, width: float) {.importc: "YGNodeStyleSetWidth".}
153+
proc setWidthPercent*(
154+
node: YGNodeRef, width: float
155+
) {.importc: "YGNodeStyleSetWidthPercent".}
156+
157+
proc setWidthAuto*(node: YGNodeRef) {.importc: "YGNodeStyleSetWidthAuto".}
158+
proc setWidthMaxContent*(node: YGNodeRef) {.importc: "YGNodeStyleSetWidthMaxContent".}
159+
proc setWidthFitContent*(node: YGNodeRef) {.importc: "YGNodeStyleSetWidthFitContent".}
160+
proc setWidthStretch*(node: YGNodeRef) {.importc: "YGNodeStyleSetWidthStretch".}
161+
162+
proc setHeight*(node: YGNodeRef, height: float) {.importc: "YGNodeStyleSetHeight".}
163+
proc setHeightPercent*(
164+
node: YGNodeRef, height: float
165+
) {.importc: "YGNodeStyleSetHeightPercent".}
166+
167+
proc setHeightAuto*(node: YGNodeRef) {.importc: "YGNodeStyleSetHeightAuto".}
168+
proc setHeightMaxContent*(node: YGNodeRef) {.importc: "YGNodeStyleSetHeightMaxContent".}
169+
proc setHeightFitContent*(node: YGNodeRef) {.importc: "YGNodeStyleSetHeightFitContent".}
170+
proc setHeightStretch*(node: YGNodeRef) {.importc: "YGNodeStyleSetHeightStretch".}
171+
172+
proc setAlignSelf*(
173+
node: YGNodeRef, align: YGAlign
174+
) {.importc: "YGNodeStyleSetAlignSelf".}
175+
176+
{.pop.}
177+
178+
# Wrapping code, just for convenience.
179+
proc setChildren*(owner: YGNodeRef, children: seq[YGNodeRef]) =
180+
var arr = cast[ptr UncheckedArray[YGNodeRef]](alloc(children.len * sizeof(YGNodeRef)))
181+
for i, _ in children:
182+
arr[i] = children[i]
183+
184+
setChildrenInternal(owner, arr, children.len.uint64)
185+
dealloc(arr)

0 commit comments

Comments
 (0)