drift
Package drift provides the main entry point for Drift applications.
func Dispatch
func Dispatch(callback func())
Dispatch schedules a callback to run on the UI thread during the next frame and is safe to call from any goroutine.
Example:
This example shows how to dispatch work to the UI thread from a background goroutine. Use Dispatch when you need to update UI state from async operations like network calls.
package main
import (
"github.com/go-drift/drift/pkg/drift"
)
func main() {
// Simulating an async operation that needs to update UI
go func() {
// ... do some work in the background ...
// Schedule UI update on the main thread
drift.Dispatch(func() {
// This code runs on the UI thread and can safely update state
// state.SetState(func() {
// state.data = result
// })
})
}()
}
func Run
func Run(app App)
Run initializes the Drift engine with the given App configuration.
type App
App defines the configuration for a Drift application.
type App struct {
// Root is the root widget of the application.
Root core.Widget
// Theme is the application theme. Defaults to DefaultLightTheme if nil.
Theme *theme.ThemeData
// DeviceScale is the device pixel ratio. Defaults to 1.0 if zero.
DeviceScale float64
}
Example (With Theme):
This example shows how to create an app with a custom theme.
package main
import (
"github.com/go-drift/drift/pkg/drift"
"github.com/go-drift/drift/pkg/theme"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
root := widgets.Center{
ChildWidget: widgets.Text{Content: "Dark Mode App"},
}
app := drift.App{
Root: root,
Theme: theme.DefaultDarkTheme(),
DeviceScale: 2.0, // For high-DPI displays
}
_ = app
}
func NewApp
func NewApp(root core.Widget) App
NewApp creates a default App with the given root widget.
Example:
This example shows how to create and configure a Drift application.
package main
import (
"github.com/go-drift/drift/pkg/drift"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
// Create the root widget for the application
root := widgets.Center{
ChildWidget: widgets.Text{Content: "Hello, Drift!"},
}
// Create an app with default settings
app := drift.NewApp(root)
_ = app
}
func (App) Run
func (app App) Run()
Run starts the app using the package-level runtime.
Generated by gomarkdoc