Skip to content

Commit

Permalink
add yoga layout engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed May 8, 2024
1 parent 3a8319e commit 897b276
Show file tree
Hide file tree
Showing 147 changed files with 15,061 additions and 2,053 deletions.
24 changes: 24 additions & 0 deletions Assets/LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -1353,3 +1353,27 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------

Yoga: MIT License

Copyright (c) Facebook, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions Assets/Script/Dev/Entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ doCompile = function(minify) -- 256
} -- 265
for _index_0 = 1, #gamesInDev do -- 272
local _des_0 = gamesInDev[_index_0] -- 272
local name, entryFile = _des_0[1], _des_0[2] -- 272
local gamePath = Path:getPath(entryFile) -- 273
local entryFile = _des_0[2] -- 272
local gamePath = Path:getPath(Path:getRelative(entryFile, writablePath)) -- 273
buildPaths[#buildPaths + 1] = { -- 275
Path(writablePath, gamePath), -- 275
Path(writablePath, ".build", gamePath), -- 276
Expand Down
4 changes: 2 additions & 2 deletions Assets/Script/Dev/Entry.yue
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ doCompile = (minify) ->
""
],
]
for [name, entryFile] in *gamesInDev
gamePath = Path\getPath entryFile
for [_, entryFile] in *gamesInDev
gamePath = Path\getPath Path\getRelative entryFile, writablePath
buildPaths[] =
* Path writablePath, gamePath
* Path writablePath, ".build", gamePath
Expand Down
243 changes: 125 additions & 118 deletions Assets/Script/Example/Sprite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,127 +12,134 @@ do -- 3
local _with_0 = Sprite("Image/logo.png") -- 3
_with_0.scaleX = 0.5 -- 4
_with_0.scaleY = 0.5 -- 4
_with_0.showDebug = true -- 5
sprite = _with_0 -- 3
end -- 3
do -- 6
local _with_0 = Node() -- 6
_with_0.touchEnabled = true -- 7
_with_0:slot("TapMoved", function(touch) -- 8
if not touch.first then -- 9
return -- 9
end -- 9
sprite.position = sprite.position + touch.delta -- 10
end) -- 8
_with_0:addChild(sprite) -- 11
end -- 6
local windowFlags = { -- 16
"NoResize", -- 16
"NoSavedSettings" -- 17
} -- 15
return threadLoop(function() -- 18
local width -- 19
width = App.visualSize.width -- 19
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0)) -- 20
ImGui.SetNextWindowSize(Vec2(240, 520), "FirstUseEver") -- 21
return ImGui.Begin("Sprite", windowFlags, function() -- 22
ImGui.Text("Sprite (Yuescript)") -- 23
ImGui.BeginChild("SpriteSetting", Vec2(-1, -40), function() -- 24
local z = sprite.z -- 25
do -- 26
local changed -- 26
changed, z = ImGui.DragFloat("Z", z, 1, -1000, 1000, "%.2f") -- 26
if changed then -- 26
sprite.z = z -- 27
end -- 26
end -- 26
local x, y -- 28
do -- 28
local _obj_0 = sprite.anchor -- 28
x, y = _obj_0.x, _obj_0.y -- 28
end -- 28
do -- 7
local _with_0 = Node() -- 7
_with_0.touchEnabled = true -- 8
_with_0:slot("TapMoved", function(touch) -- 9
if not touch.first then -- 10
return -- 10
end -- 10
sprite.position = sprite.position + touch.delta -- 11
end) -- 9
_with_0:addChild(sprite) -- 12
end -- 7
local windowFlags = { -- 17
"NoResize", -- 17
"NoSavedSettings" -- 18
} -- 16
return threadLoop(function() -- 19
local width -- 20
width = App.visualSize.width -- 20
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0)) -- 21
ImGui.SetNextWindowSize(Vec2(240, 520), "FirstUseEver") -- 22
return ImGui.Begin("Sprite", windowFlags, function() -- 23
ImGui.Text("Sprite (Yuescript)") -- 24
ImGui.BeginChild("SpriteSetting", Vec2(-1, -40), function() -- 25
local z = sprite.z -- 26
do -- 27
local changed -- 27
changed, z = ImGui.DragFloat("Z", z, 1, -1000, 1000, "%.2f") -- 27
if changed then -- 27
sprite.z = z -- 28
end -- 27
end -- 27
local x, y -- 29
do -- 29
local changed -- 29
changed, x, y = ImGui.DragFloat2("Anchor", x, y, 0.01, 0, 1, "%.2f") -- 29
if changed then -- 29
sprite.anchor = Vec2(x, y) -- 30
end -- 29
local _obj_0 = sprite.anchor -- 29
x, y = _obj_0.x, _obj_0.y -- 29
end -- 29
local spriteW, height -- 31
do -- 31
local _obj_0 = sprite.size -- 31
spriteW, height = _obj_0.width, _obj_0.height -- 31
end -- 31
do -- 30
local changed -- 30
changed, x, y = ImGui.DragFloat2("Anchor", x, y, 0.01, 0, 1, "%.2f") -- 30
if changed then -- 30
sprite.anchor = Vec2(x, y) -- 31
end -- 30
end -- 30
local spriteW, height -- 32
do -- 32
local changed -- 32
changed, spriteW, height = ImGui.DragFloat2("Size", spriteW, height, 0.1, 0, 1000, "%.f") -- 32
if changed then -- 32
sprite.size = Size(spriteW, height) -- 33
end -- 32
local _obj_0 = sprite.size -- 32
spriteW, height = _obj_0.width, _obj_0.height -- 32
end -- 32
local scaleX, scaleY = sprite.scaleX, sprite.scaleY -- 34
do -- 35
local changed -- 35
changed, scaleX, scaleY = ImGui.DragFloat2("Scale", scaleX, scaleY, 0.01, -2, 2, "%.2f") -- 35
if changed then -- 35
sprite.scaleX, sprite.scaleY = scaleX, scaleY -- 36
end -- 35
end -- 35
ImGui.PushItemWidth(-60, function() -- 37
local angle = sprite.angle -- 38
local changed -- 39
changed, angle = ImGui.DragInt("Angle", math.floor(angle), 1, -360, 360) -- 39
if changed then -- 39
sprite.angle = angle -- 40
end -- 39
end) -- 37
ImGui.PushItemWidth(-60, function() -- 41
local angleX = sprite.angleX -- 42
local changed -- 43
changed, angleX = ImGui.DragInt("AngleX", math.floor(angleX), 1, -360, 360) -- 43
if changed then -- 43
sprite.angleX = angleX -- 44
end -- 43
end) -- 41
ImGui.PushItemWidth(-60, function() -- 45
local angleY = sprite.angleY -- 46
local changed -- 47
changed, angleY = ImGui.DragInt("AngleY", math.floor(angleY), 1, -360, 360) -- 47
if changed then -- 47
sprite.angleY = angleY -- 48
end -- 47
end) -- 45
local skewX, skewY = sprite.skewX, sprite.skewY -- 49
do -- 50
local changed -- 50
changed, skewX, skewY = ImGui.DragInt2("Skew", math.floor(skewX), math.floor(skewY), 1, -360, 360) -- 50
if changed then -- 50
sprite.skewX, sprite.skewY = skewX, skewY -- 51
end -- 50
end -- 50
ImGui.PushItemWidth(-70, function() -- 52
local opacity = sprite.opacity -- 53
local changed -- 54
changed, opacity = ImGui.DragFloat("Opacity", opacity, 0.01, 0, 1, "%.2f") -- 54
if changed then -- 54
sprite.opacity = opacity -- 55
end -- 54
end) -- 52
return ImGui.PushItemWidth(-1, function() -- 56
local color3 = sprite.color3 -- 57
ImGui.SetColorEditOptions({ -- 58
"DisplayRGB" -- 58
}) -- 58
if ImGui.ColorEdit3("", color3) then -- 59
sprite.color3 = color3 -- 60
end -- 59
end) -- 60
end) -- 24
if ImGui.Button("Reset", Vec2(140, 30)) then -- 61
local _with_0 = sprite.parent -- 62
_with_0:removeChild(sprite) -- 63
sprite = Sprite("Image/logo.png") -- 64
_with_0:addChild(sprite) -- 65
return _with_0 -- 62
end -- 61
end) -- 65
end) -- 65
do -- 33
local changed -- 33
changed, spriteW, height = ImGui.DragFloat2("Size", spriteW, height, 0.1, 0, 1500, "%.f") -- 33
if changed then -- 33
sprite.size = Size(spriteW, height) -- 34
end -- 33
end -- 33
local scaleX, scaleY = sprite.scaleX, sprite.scaleY -- 35
do -- 36
local changed -- 36
changed, scaleX, scaleY = ImGui.DragFloat2("Scale", scaleX, scaleY, 0.01, -2, 2, "%.2f") -- 36
if changed then -- 36
sprite.scaleX, sprite.scaleY = scaleX, scaleY -- 37
end -- 36
end -- 36
ImGui.PushItemWidth(-60, function() -- 38
local angle = sprite.angle -- 39
local changed -- 40
changed, angle = ImGui.DragInt("Angle", math.floor(angle), 1, -360, 360) -- 40
if changed then -- 40
sprite.angle = angle -- 41
end -- 40
end) -- 38
ImGui.PushItemWidth(-60, function() -- 42
local angleX = sprite.angleX -- 43
local changed -- 44
changed, angleX = ImGui.DragInt("AngleX", math.floor(angleX), 1, -360, 360) -- 44
if changed then -- 44
sprite.angleX = angleX -- 45
end -- 44
end) -- 42
ImGui.PushItemWidth(-60, function() -- 46
local angleY = sprite.angleY -- 47
local changed -- 48
changed, angleY = ImGui.DragInt("AngleY", math.floor(angleY), 1, -360, 360) -- 48
if changed then -- 48
sprite.angleY = angleY -- 49
end -- 48
end) -- 46
local skewX, skewY = sprite.skewX, sprite.skewY -- 50
do -- 51
local changed -- 51
changed, skewX, skewY = ImGui.DragInt2("Skew", math.floor(skewX), math.floor(skewY), 1, -360, 360) -- 51
if changed then -- 51
sprite.skewX, sprite.skewY = skewX, skewY -- 52
end -- 51
end -- 51
ImGui.PushItemWidth(-70, function() -- 53
local opacity = sprite.opacity -- 54
local changed -- 55
changed, opacity = ImGui.DragFloat("Opacity", opacity, 0.01, 0, 1, "%.2f") -- 55
if changed then -- 55
sprite.opacity = opacity -- 56
end -- 55
end) -- 53
return ImGui.PushItemWidth(-1, function() -- 57
local color3 = sprite.color3 -- 58
ImGui.SetColorEditOptions({ -- 59
"DisplayRGB" -- 59
}) -- 59
if ImGui.ColorEdit3("", color3) then -- 60
sprite.color3 = color3 -- 61
end -- 60
end) -- 61
end) -- 25
if ImGui.Button("Reset", Vec2(140, 30)) then -- 62
local _with_0 = sprite.parent -- 63
_with_0:removeChild(sprite) -- 64
do -- 65
local _with_1 = Sprite("Image/logo.png") -- 65
_with_1.scaleX = 0.5 -- 66
_with_1.scaleY = 0.5 -- 66
_with_1.showDebug = true -- 67
sprite = _with_1 -- 65
end -- 65
_with_0:addChild(sprite) -- 68
return _with_0 -- 63
end -- 62
end) -- 68
end) -- 68
7 changes: 5 additions & 2 deletions Assets/Script/Example/Sprite.yue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ _ENV = Dora!

sprite = with Sprite "Image/logo.png"
.scaleX = .scaleY = 0.5
.showDebug = true

with Node!
.touchEnabled = true
Expand Down Expand Up @@ -29,7 +30,7 @@ threadLoop ->
if changed, x, y := ImGui.DragFloat2 "Anchor", x, y, 0.01, 0, 1, "%.2f"
sprite.anchor = Vec2 x, y
width: spriteW, :height = sprite.size
if changed, spriteW, height := ImGui.DragFloat2 "Size", spriteW, height, 0.1, 0, 1000, "%.f"
if changed, spriteW, height := ImGui.DragFloat2 "Size", spriteW, height, 0.1, 0, 1500, "%.f"
sprite.size = Size spriteW, height
:scaleX, :scaleY = sprite
if changed, scaleX, scaleY := ImGui.DragFloat2 "Scale", scaleX, scaleY, 0.01, -2, 2, "%.2f"
Expand Down Expand Up @@ -61,5 +62,7 @@ threadLoop ->
if ImGui.Button "Reset", Vec2 140, 30
with sprite.parent
\removeChild sprite
sprite = Sprite "Image/logo.png"
sprite = with Sprite "Image/logo.png"
.scaleX = .scaleY = 0.5
.showDebug = true
\addChild sprite
58 changes: 58 additions & 0 deletions Assets/Script/Lib/Dora/en/AlignNode.d.tl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
local Node = require("Node").Type

-- AlignNode is a layout node that aligns its children.
local record AlignNode

-- Inherits from `Node`.
embed Node

-- Sets the layout style of the node.
-- @param style (string) The layout style.
-- The following properties can be set through a CSS style string:
--
-- ## Layout direction and alignment
-- * direction: Sets the direction (ltr, rtl, inherit).
-- * align-items, align-self, align-content: Sets the alignment of different items (flex-start, center, stretch, flex-end, auto).
-- * flex-direction: Sets the layout direction (column, row, column-reverse, row-reverse).
-- * justify-content: Sets the arrangement of child items (flex-start, center, flex-end, space-between, space-around, space-evenly).
--
-- ## Flex properties
-- * flex: Sets the overall size of the flex container.
-- * flex-grow: Sets the flex growth value.
-- * flex-shrink: Sets the flex shrink value.
-- * flex-wrap: Sets whether to wrap (nowrap, wrap, wrap-reverse).
-- * flex-basis: Sets the flex basis value or percentage.
--
-- ## Margins and dimensions
-- * margin: Can be set by a single value or multiple values separated by commas, percentages or auto for each side.
-- * margin-top, margin-right, margin-bottom, margin-left, margin-start, margin-end: Sets the margin values, percentages or auto.
-- * padding: Can be set by a single value or multiple values separated by commas or percentages for each side.
-- * padding-top, padding-right, padding-bottom, padding-left: Sets the padding values or percentages.
-- * border: Can be set by a single value or multiple values separated by commas for each side.
-- * width, height, min-width, min-height, max-width, max-height: Sets the dimension values or percentage properties.
--
-- ## Positioning
-- * top, right, bottom, left, start, end, horizontal, vertical: Sets the positioning property values or percentages.
--
-- ## Other properties
-- * position: Sets the positioning type (absolute, relative, static).
-- * overflow: Sets the overflow property (visible, hidden, scroll).
-- * display: Controls whether to display (flex, none).
--
-- @usage
-- alignNode:css("flex-direction: column; justify-content: center; align-items: center;")
css: function(self: AlignNode, style: string)
end

-- A class for creating AlignNode objects.
local record AlignNodeClass
type Type = AlignNode

-- Creates a new AlignNode.
-- @param isWindowRoot (boolean) [optional] Whether the node is a window root node. A window root node will automatically listen for window size change events and update the layout accordingly.
-- @return (AlignNode) The created AlignNode object.
metamethod __call: function(self: AlignNodeClass, isWindowRoot?: boolean): AlignNode
end

local alignNodeClass: AlignNodeClass
return alignNodeClass
3 changes: 0 additions & 3 deletions Assets/Script/Lib/Dora/en/DragonBone.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ local record DragonBone
-- Inherit from the `Playable`.
embed Playable

-- Whether to show debug graphics.
showDebug: boolean

-- Whether hit testing is enabled.
hitTestEnabled: boolean

Expand Down
Loading

0 comments on commit 897b276

Please sign in to comment.