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

Change (V/H)Stack implementation from grid to flex #515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions Sources/TokamakStaticHTML/Resources/TokamakStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import TokamakCore

public let tokamakStyles = """
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, \(Int(defaultStackSpacing))px);
flex-direction: row;
gap: var(--tokamak-stack-gap, \(Int(defaultStackSpacing))px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, \(Int(defaultStackSpacing))px);
flex-direction: column;
gap: var(--tokamak-stack-gap, \(Int(defaultStackSpacing))px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down
4 changes: 4 additions & 0 deletions Sources/TokamakStaticHTML/Shapes/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ extension Path: _HTMLPrimitive {
"""
width: 100%;
height: 100%;
min-width: 0;
min-height: 0;
""" :
"""
width: \(max(0, size.width));
height: \(max(0, size.height));
min-width: 0;
min-height: 0;
"""
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/TokamakStaticHTML/Views/Layout/HStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ extension VerticalAlignment {
var cssValue: String {
switch self {
case .top:
return "start"
return "flex-start"
case .center:
return "center"
case .bottom:
return "end"
return "flex-end"
default:
return "center"
}
Expand All @@ -38,7 +38,7 @@ extension HStack: _HTMLPrimitive, SpacerContainer {

return AnyView(HTML("div", [
"style": """
align-items: \(alignment.cssValue);
justify-content: \(alignment.cssValue);
\(hasSpacer ? "width: 100%;" : "")
\(fillCrossAxis ? "height: 100%;" : "")
\(spacing != defaultStackSpacing ? "--tokamak-stack-gap: \(spacing)px;" : "")
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakStaticHTML/Views/Layout/VStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension VStack: _HTMLPrimitive, SpacerContainer {

return AnyView(HTML("div", [
"style": """
justify-items: \(alignment.cssValue);
align-items: \(alignment.cssValue);
\(hasSpacer ? "height: 100%;" : "")
\(fillCrossAxis ? "width: 100%;" : "")
\(spacing != defaultStackSpacing ? "--tokamak-stack-gap: \(spacing)px;" : "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ final class VisualRenderingTests: XCTestCase {
Color.clear
.background(Material.ultraThick)
}
},
}.frame(width: 100, height: 100),
as: .image(size: .init(width: 100, height: 100)),
timeout: defaultSnapshotTimeout
)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title>Tokamak 2</title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down Expand Up @@ -246,7 +246,7 @@
height: 100%;
justify-content: center;
align-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="justify-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="align-items: center;


"><span style="font-family: system, -apple-system, '.SFNSText-Regular', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif; font-size: 17.0px; font-style: normal; font-variant: normal; font-weight: 400; line-height: normal;
Expand All @@ -259,7 +259,7 @@
text-decoration: none;
text-decoration-color: inherit;
text-align: left;">Hello, world!</span>
<div class="_tokamak-stack _tokamak-vstack" style="justify-items: center;
<div class="_tokamak-stack _tokamak-vstack" style="align-items: center;


"></div></div></body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title>Tokamak 2</title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title></title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title></title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down Expand Up @@ -246,7 +246,7 @@
height: 100%;
justify-content: center;
align-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="justify-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="align-items: center;


"><span style="font-family: 'Marker Felt', Cambria, 'Hoefler Text', Utopia, 'Liberation Serif', 'Nimbus Roman No9 L Regular', Times, 'Times New Roman', serif; font-size: 17.0px; font-style: normal; font-variant: normal; font-weight: 400; line-height: normal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title></title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title></title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<meta http-equiv="refresh" content="60">
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down Expand Up @@ -250,7 +250,7 @@
height: 100%;
justify-content: center;
align-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="justify-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="align-items: center;


"><span style="font-family: system, -apple-system, '.SFNSText-Regular', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif; font-size: 17.0px; font-style: normal; font-variant: normal; font-weight: 400; line-height: normal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<meta charset="utf-8">
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down Expand Up @@ -247,7 +247,7 @@
height: 100%;
justify-content: center;
align-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="justify-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="align-items: center;


"><span style="font-family: system, -apple-system, '.SFNSText-Regular', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif; font-size: 17.0px; font-style: normal; font-variant: normal; font-weight: 400; line-height: normal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<meta charset="utf-8">
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title></title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down Expand Up @@ -246,11 +246,13 @@
height: 100%;
justify-content: center;
align-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="justify-items: center;
overflow: hidden;"><div class="_tokamak-stack _tokamak-vstack" style="align-items: center;
height: 100%;

"><svg style="width: 100%;
height: 100%;
min-width: 0;
min-height: 0;
overflow: visible; fill: rgba(255.0, 58.650000000000006, 48.45, 1.0);"><rect height="100%" stroke-width="0.0" width="100%" x="0.0" y="0.0"></rect></svg>
<div style="flex-grow: 1; "></div></div></body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<title></title>
<style>
._tokamak-stack {
display: grid;
display: flex;
}
._tokamak-hstack {
grid-auto-flow: column;
column-gap: var(--tokamak-stack-gap, 8px);
flex-direction: row;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-vstack {
grid-auto-flow: row;
row-gap: var(--tokamak-stack-gap, 8px);
flex-direction: column;
gap: var(--tokamak-stack-gap, 8px);
}
._tokamak-scrollview-hideindicators {
scrollbar-color: transparent;
Expand Down Expand Up @@ -248,5 +248,7 @@
align-items: center;
overflow: hidden;"><div style="padding-top: 30.0px; padding-left: 30.0px; padding-bottom: 30.0px; padding-right: 30.0px;"><svg style="width: 100%;
height: 100%;
min-width: 0;
min-height: 0;
overflow: visible; fill: rgba(255.0, 58.650000000000006, 48.45, 1.0);"><rect height="100%" stroke-width="0.0" width="100%" x="0.0" y="0.0"></rect></svg></div></body>
</html>
Loading