Skip to content

Commit 9177c9f

Browse files
committed
[examples] Add an example app
1 parent 1a7e0f2 commit 9177c9f

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

examples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
There is only a single example here as of now. Not much is needed to
2+
demonstrate Frenyard, as it is quite small.

examples/app.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"github.com/uwu/frenyard"
5+
"github.com/uwu/frenyard/framework"
6+
)
7+
8+
// UpApplication is the struct that powers anything referenced under `app`.
9+
type UpApplication struct {
10+
MainContainer *framework.UISlideTransitionContainer
11+
Window frenyard.Window
12+
UpQueued chan func()
13+
TeleportSettings framework.SlideTransition
14+
}
15+
16+
const upTeleportLen float64 = 0.25
17+
18+
// GSLeftwards sets the teleportation affinity to LEFT.
19+
func (app *UpApplication) GSLeftwards() {
20+
app.TeleportSettings.Reverse = true
21+
app.TeleportSettings.Vertical = false
22+
app.TeleportSettings.Length = upTeleportLen
23+
}
24+
25+
// GSRightwards sets the teleportation affinity to RIGHT.
26+
func (app *UpApplication) GSRightwards() {
27+
app.TeleportSettings.Reverse = false
28+
app.TeleportSettings.Vertical = false
29+
app.TeleportSettings.Length = upTeleportLen
30+
}
31+
32+
// GSLeftwards sets the teleportation affinity to UP.
33+
func (app *UpApplication) GSUpwards() {
34+
app.TeleportSettings.Reverse = true
35+
app.TeleportSettings.Vertical = true
36+
app.TeleportSettings.Length = upTeleportLen
37+
}
38+
39+
// GSRightwards sets the teleportation affinity to DOWN.
40+
func (app *UpApplication) GSDownwards() {
41+
app.TeleportSettings.Reverse = false
42+
app.TeleportSettings.Vertical = true
43+
app.TeleportSettings.Length = upTeleportLen
44+
}
45+
46+
// GSInstant sets the teleportation affinity to INSTANT.
47+
func (app *UpApplication) GSInstant() {
48+
// direction doesn't matter
49+
app.TeleportSettings.Length = 0
50+
}
51+
52+
// Teleport starts a transition with the cached affinity settings.
53+
func (app *UpApplication) Teleport(target framework.UILayoutElement) {
54+
forkTD := app.TeleportSettings
55+
forkTD.Element = target
56+
app.MainContainer.TransitionTo(forkTD)
57+
}

examples/main.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"github.com/uwu/frenyard"
5+
"github.com/uwu/frenyard/design"
6+
"github.com/uwu/frenyard/framework"
7+
"github.com/uwu/frenyard/integration"
8+
)
9+
10+
func main() {
11+
// This controls the framerate
12+
frenyard.TargetFrameTime = 0.016
13+
14+
// Initialize our main container capable of slide animations
15+
slideContainer := framework.NewUISlideTransitionContainerPtr(nil)
16+
slideContainer.FyEResize(design.SizeWindowInit)
17+
18+
// Initialize our window and bind it to our container element
19+
wnd, err := framework.CreateBoundWindow("Frenyard Example", true, design.ThemeBackground, slideContainer)
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
// Setup sets the sizes, fonts and borders according to a reasonable inferred
25+
// scale.
26+
design.Setup(frenyard.InferScale(wnd))
27+
wnd.SetSize(design.SizeWindow)
28+
29+
// Initialize our app struct, referencable from anywhere.
30+
app := (&UpApplication{
31+
MainContainer: slideContainer,
32+
Window: wnd,
33+
UpQueued: make(chan func(), 16),
34+
TeleportSettings: framework.SlideTransition{},
35+
})
36+
37+
// Start an instant transition to our main screen.
38+
app.Teleport(
39+
// A 'document', with a title header and body.
40+
design.LayoutDocument(
41+
design.Header{
42+
Title: "Example App",
43+
},
44+
// Main flexbox container, contains all elements.
45+
framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
46+
DirVertical: true,
47+
Slots: []framework.FlexboxSlot{
48+
{
49+
Element: framework.NewUILabelPtr(integration.NewTextTypeChunk("Hello World!", design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{}),
50+
},
51+
},
52+
}),
53+
// Sets the flexbox container to be scrollable.
54+
true,
55+
),
56+
)
57+
58+
// Start the backend. Stops when ExitFlag is set to true.
59+
frenyard.GlobalBackend.Run(func(frameTime float64) {
60+
select {
61+
case fn := <-app.UpQueued:
62+
63+
fn()
64+
default:
65+
}
66+
})
67+
}

0 commit comments

Comments
 (0)