Skip to content

Commit

Permalink
[examples] Add an example app
Browse files Browse the repository at this point in the history
  • Loading branch information
lexisother committed Oct 3, 2022
1 parent 1a7e0f2 commit 9177c9f
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
There is only a single example here as of now. Not much is needed to
demonstrate Frenyard, as it is quite small.
57 changes: 57 additions & 0 deletions examples/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"github.com/uwu/frenyard"
"github.com/uwu/frenyard/framework"
)

// UpApplication is the struct that powers anything referenced under `app`.
type UpApplication struct {
MainContainer *framework.UISlideTransitionContainer
Window frenyard.Window
UpQueued chan func()
TeleportSettings framework.SlideTransition
}

const upTeleportLen float64 = 0.25

// GSLeftwards sets the teleportation affinity to LEFT.
func (app *UpApplication) GSLeftwards() {
app.TeleportSettings.Reverse = true
app.TeleportSettings.Vertical = false
app.TeleportSettings.Length = upTeleportLen
}

// GSRightwards sets the teleportation affinity to RIGHT.
func (app *UpApplication) GSRightwards() {
app.TeleportSettings.Reverse = false
app.TeleportSettings.Vertical = false
app.TeleportSettings.Length = upTeleportLen
}

// GSLeftwards sets the teleportation affinity to UP.
func (app *UpApplication) GSUpwards() {
app.TeleportSettings.Reverse = true
app.TeleportSettings.Vertical = true
app.TeleportSettings.Length = upTeleportLen
}

// GSRightwards sets the teleportation affinity to DOWN.
func (app *UpApplication) GSDownwards() {
app.TeleportSettings.Reverse = false
app.TeleportSettings.Vertical = true
app.TeleportSettings.Length = upTeleportLen
}

// GSInstant sets the teleportation affinity to INSTANT.
func (app *UpApplication) GSInstant() {
// direction doesn't matter
app.TeleportSettings.Length = 0
}

// Teleport starts a transition with the cached affinity settings.
func (app *UpApplication) Teleport(target framework.UILayoutElement) {
forkTD := app.TeleportSettings
forkTD.Element = target
app.MainContainer.TransitionTo(forkTD)
}
67 changes: 67 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"github.com/uwu/frenyard"
"github.com/uwu/frenyard/design"
"github.com/uwu/frenyard/framework"
"github.com/uwu/frenyard/integration"
)

func main() {
// This controls the framerate
frenyard.TargetFrameTime = 0.016

// Initialize our main container capable of slide animations
slideContainer := framework.NewUISlideTransitionContainerPtr(nil)
slideContainer.FyEResize(design.SizeWindowInit)

// Initialize our window and bind it to our container element
wnd, err := framework.CreateBoundWindow("Frenyard Example", true, design.ThemeBackground, slideContainer)
if err != nil {
panic(err)
}

// Setup sets the sizes, fonts and borders according to a reasonable inferred
// scale.
design.Setup(frenyard.InferScale(wnd))
wnd.SetSize(design.SizeWindow)

// Initialize our app struct, referencable from anywhere.
app := (&UpApplication{
MainContainer: slideContainer,
Window: wnd,
UpQueued: make(chan func(), 16),
TeleportSettings: framework.SlideTransition{},
})

// Start an instant transition to our main screen.
app.Teleport(
// A 'document', with a title header and body.
design.LayoutDocument(
design.Header{
Title: "Example App",
},
// Main flexbox container, contains all elements.
framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: true,
Slots: []framework.FlexboxSlot{
{
Element: framework.NewUILabelPtr(integration.NewTextTypeChunk("Hello World!", design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{}),
},
},
}),
// Sets the flexbox container to be scrollable.
true,
),
)

// Start the backend. Stops when ExitFlag is set to true.
frenyard.GlobalBackend.Run(func(frameTime float64) {
select {
case fn := <-app.UpQueued:

fn()
default:
}
})
}

0 comments on commit 9177c9f

Please sign in to comment.