-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a7e0f2
commit 9177c9f
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
} | ||
}) | ||
} |