core

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	VisualDensityStandard    = VisualDensity{Horizontal: 0, Vertical: 0}
	VisualDensityComfortable = VisualDensity{Horizontal: -1, Vertical: -1}
	VisualDensityCompact     = VisualDensity{Horizontal: -2, Vertical: -2}
	VisualDensityAdaptive    = VisualDensity{Horizontal: 0, Vertical: 0}
)

Standard visual densities

View Source
var (
	DefaultLightTheme = NewThemeData()
	DefaultDarkTheme  = func() *ThemeData {
		theme := NewThemeData()
		theme.ColorScheme = NewDarkColorScheme()
		theme.Brightness = BrightnessDark
		return theme
	}()
)

Predefined themes

View Source
var (
	// Primary colors
	ColorPrimary      = NewColor(103, 80, 164, 255) // Material Purple
	ColorPrimaryLight = NewColor(187, 134, 252, 255)
	ColorPrimaryDark  = NewColor(77, 56, 138, 255)

	// Secondary colors
	ColorSecondary      = NewColor(3, 218, 198, 255) // Material Teal
	ColorSecondaryLight = NewColor(129, 199, 132, 255)
	ColorSecondaryDark  = NewColor(0, 150, 136, 255)

	// Surface colors
	ColorSurface        = NewColor(255, 255, 255, 255)
	ColorSurfaceDark    = NewColor(18, 18, 18, 255)
	ColorBackground     = NewColor(255, 255, 255, 255)
	ColorBackgroundDark = NewColor(0, 0, 0, 255)

	// Text colors
	ColorOnSurface        = NewColor(0, 0, 0, 255)
	ColorOnSurfaceDark    = NewColor(255, 255, 255, 255)
	ColorOnBackground     = NewColor(0, 0, 0, 255)
	ColorOnBackgroundDark = NewColor(255, 255, 255, 255)
	ColorOnPrimary        = NewColor(255, 255, 255, 255)
	ColorOnPrimaryDark    = NewColor(0, 0, 0, 255)
	ColorOnSecondary      = NewColor(0, 0, 0, 255)
	ColorOnSecondaryDark  = NewColor(0, 0, 0, 255)

	// Status colors
	ColorError   = NewColor(211, 47, 47, 255)
	ColorWarning = NewColor(255, 152, 0, 255)
	ColorSuccess = NewColor(76, 175, 80, 255)
	ColorInfo    = NewColor(33, 150, 243, 255)

	// Neutral colors
	ColorTransparent = NewColor(0, 0, 0, 0)
	ColorWhite       = NewColor(255, 255, 255, 255)
	ColorBlack       = NewColor(0, 0, 0, 255)
	ColorGrey        = NewColor(158, 158, 158, 255)
	ColorGreyLight   = NewColor(245, 245, 245, 255)
	ColorGreyDark    = NewColor(66, 66, 66, 255)
)

Predefined colors following Material Design

View Source
var BreakpointValues = map[Breakpoint]float64{
	BreakpointXS: 0,
	BreakpointSM: 576,
	BreakpointMD: 768,
	BreakpointLG: 992,
	BreakpointXL: 1200,
}

BreakpointValues maps breakpoints to their pixel values

Functions

func ClampFloat64 added in v1.2.0

func ClampFloat64(value, min, max float64) float64

ClampFloat64 clamps a float64 value between min and max

func ClampInt added in v1.2.0

func ClampInt(value, min, max int) int

ClampInt clamps an int value between min and max

func GenerateCSRFToken added in v1.2.0

func GenerateCSRFToken() string

GenerateCSRFToken generates a new CSRF token

func GetEnvPort added in v1.2.0

func GetEnvPort() string

GetEnvPort gets the port from environment variables

func GetState added in v1.2.0

func GetState(key string) interface{}

GetState is the global function to get state values

func GetStateBool added in v1.2.0

func GetStateBool(key string) bool

GetStateBool retrieves a boolean value from global state

func GetStateInt added in v1.2.0

func GetStateInt(key string) int

GetStateInt retrieves an integer value from global state

func GetStateString added in v1.2.0

func GetStateString(key string) string

GetStateString retrieves a string value from global state

func InitGlobalState added in v1.2.0

func InitGlobalState()

InitGlobalState initializes the global state manager

func InitializeStateUpdater added in v1.2.0

func InitializeStateUpdater(ctx *Context)

InitializeStateUpdater initializes the global state updater

func MergeHTMXAttributes added in v1.2.0

func MergeHTMXAttributes(attrMaps ...map[string]string) map[string]string

MergeAttributes merges multiple attribute maps

func SafeExecuteCallback added in v1.2.0

func SafeExecuteCallback(callbackID, widgetType, widgetID, eventType string, callback func(), errorHandler ErrorHandler)

SafeExecuteCallback executes a callback with error handling and recovery

func SafeExecuteStateOperation added in v1.2.0

func SafeExecuteStateOperation(operation, key string, value interface{}, operation_func func() error, errorHandler ErrorHandler) error

SafeExecuteStateOperation executes a state operation with error handling

func ServeFile

func ServeFile(w http.ResponseWriter, r *http.Request, filename string) error

ServeFile serves a single file with proper content type

func SetGlobalContext added in v1.2.0

func SetGlobalContext(ctx *Context)

SetGlobalContext sets the current context for global state operations

func SetGlobalStateUpdater added in v1.2.0

func SetGlobalStateUpdater(updater *StateUpdater)

SetGlobalStateUpdater sets the global state updater instance

func SetState added in v1.2.0

func SetState(key string, value interface{})

setState is the global function that can be called from button callbacks

func SetStateCallback added in v1.2.0

func SetStateCallback(ctx *Context, callback func()) error

Flutter-style setState function that can be called from widget callbacks This provides the familiar setState(() => { ... }) pattern

func SetStateFunc added in v1.2.0

func SetStateFunc(ctx *Context, updateFunc func()) error

SetStateFunc executes a state update function and triggers UI rebuilds This is the main setState function similar to Flutter

func SetStateValue added in v1.2.0

func SetStateValue(ctx *Context, key string, value interface{}) error

SetStateValue is a convenience function for setting a single state value

func SetStateValues added in v1.2.0

func SetStateValues(ctx *Context, values map[string]interface{}) error

SetStateValues is a convenience function for setting multiple state values

func SetStateWithCallback added in v1.2.0

func SetStateWithCallback(ctx *Context, updateFunc func(), callback func()) error

SetStateWithCallback executes a setState with a completion callback

func SetStateWithRebuild added in v1.2.0

func SetStateWithRebuild(ctx *Context, updateFunc func(), widgetIDs ...string) error

SetStateWithRebuild executes a state update and rebuilds specific widgets

func SetStateWithWidgets added in v1.2.0

func SetStateWithWidgets(ctx *Context, updateFunc func(), widgetIDs []string) error

SetStateWithWidgets executes a state update and rebuilds specific widgets

func SetupStateAPI added in v1.2.0

func SetupStateAPI(app *App, stateManager *state.StateManager)

Helper function to create a complete state API setup

func StateMiddleware added in v1.2.0

func StateMiddleware(stateManager *state.StateManager) func(http.Handler) http.Handler

StateMiddleware provides state management middleware

func ValidateCSRFToken added in v1.2.0

func ValidateCSRFToken(provided, expected string) bool

ValidateCSRFToken validates a CSRF token (simplified implementation)

func WithStateContext added in v1.2.0

func WithStateContext(ctx context.Context, stateCtx *Context) context.Context

WithStateContext creates a new context with state context

Types

type AccessibilityFeatures added in v1.2.0

type AccessibilityFeatures struct {
	AccessibleNavigation bool
	InvertColors         bool
	HighContrast         bool
	DisableAnimations    bool
	BoldText             bool
}

AccessibilityFeatures represents accessibility settings

type App

type App struct {
	// contains filtered or unexported fields
}

App represents the main Godin application

func New

func New() *App

New creates a new Godin application

func (*App) CallbackRegistry added in v1.2.0

func (app *App) CallbackRegistry() *CallbackRegistry

CallbackRegistry returns the callback registry

func (*App) DELETE

func (app *App) DELETE(path string, handler Handler)

DELETE registers a DELETE route handler

func (*App) DialogManager added in v1.2.0

func (app *App) DialogManager() interface{}

DialogManager returns the dialog manager

func (*App) ExecuteButtonCallback added in v1.2.0

func (app *App) ExecuteButtonCallback(buttonID string) bool

ExecuteButtonCallback executes a button callback by ID

func (*App) ExecuteCallback added in v1.2.0

func (app *App) ExecuteCallback(callbackID string, params map[string]interface{}) error

ExecuteCallback executes a callback by ID with optional parameters

func (*App) GET

func (app *App) GET(path string, handler Handler)

GET registers a GET route handler

func (*App) GenerateCSRFTokenForApp added in v1.2.0

func (app *App) GenerateCSRFTokenForApp() string

GenerateCSRFTokenForApp generates and sets a CSRF token for the app

func (*App) GenerateThemeCSS added in v1.2.0

func (app *App) GenerateThemeCSS() string

GenerateThemeCSS generates CSS from the current theme

func (*App) GetHandlerCount added in v1.2.0

func (app *App) GetHandlerCount() int

GetHandlerCount returns the number of registered handlers (for generating unique IDs)

func (*App) GetTheme added in v1.2.0

func (app *App) GetTheme() *ThemeData

GetTheme returns the current theme

func (*App) HTMXIntegrator added in v1.2.0

func (app *App) HTMXIntegrator() *HTMXIntegrator

HTMXIntegrator returns the HTMX integrator

func (*App) MediaQueryProvider added in v1.2.0

func (app *App) MediaQueryProvider() *MediaQueryProvider

MediaQueryProvider returns the media query provider

func (*App) Navigator added in v1.2.0

func (app *App) Navigator() interface{}

Navigator returns the navigator

func (*App) POST

func (app *App) POST(path string, handler Handler)

POST registers a POST route handler

func (*App) PUT

func (app *App) PUT(path string, handler Handler)

PUT registers a PUT route handler

func (*App) Packages

func (app *App) Packages() *packages.PackageManager

Packages returns the package manager

func (*App) RegisterButtonCallback added in v1.2.0

func (app *App) RegisterButtonCallback(buttonID string, callback func())

RegisterButtonCallback registers a button callback for WebSocket communication

func (*App) RegisterCallback added in v1.2.0

func (app *App) RegisterCallback(widgetID, widgetType, callbackType string, fn interface{}, ctx *Context) string

RegisterCallback registers a callback function and returns a unique callback ID

func (*App) RegisterHandler added in v1.2.0

func (app *App) RegisterHandler(handler Handler) string

RegisterHandler registers a handler globally and returns a unique ID

func (*App) Router

func (app *App) Router() *mux.Router

Router returns the underlying mux router for advanced routing

func (*App) Serve

func (app *App) Serve(addr string) error

Serve starts the application server

func (*App) SetDarkTheme added in v1.2.0

func (app *App) SetDarkTheme(theme *ThemeData)

SetDarkTheme sets the dark theme

func (*App) SetDialogManager added in v1.2.0

func (app *App) SetDialogManager(manager interface{})

SetDialogManager sets the dialog manager

func (*App) SetHTMXConfig added in v1.2.0

func (app *App) SetHTMXConfig(config *HTMXConfig)

SetHTMXConfig updates the HTMX integrator configuration

func (*App) SetLightTheme added in v1.2.0

func (app *App) SetLightTheme(theme *ThemeData)

SetLightTheme sets the light theme

func (*App) SetMediaQueryProvider added in v1.2.0

func (app *App) SetMediaQueryProvider(provider *MediaQueryProvider)

SetMediaQueryProvider sets the media query provider

func (*App) SetNavigator added in v1.2.0

func (app *App) SetNavigator(nav interface{})

SetNavigator sets the navigator

func (*App) SetTheme added in v1.2.0

func (app *App) SetTheme(theme *ThemeData)

SetTheme sets the current theme

func (*App) SetThemeMode added in v1.2.0

func (app *App) SetThemeMode(mode ThemeMode)

SetThemeMode sets the theme mode (light, dark, or system)

func (*App) State

func (app *App) State() *state.StateManager

State returns the state manager

func (*App) ThemeProvider added in v1.2.0

func (app *App) ThemeProvider() *ThemeProvider

ThemeProvider returns the theme provider

func (*App) WebSocket

func (app *App) WebSocket() *WebSocketManager

WebSocket returns the WebSocket manager

func (*App) WithDarkTheme added in v1.2.0

func (app *App) WithDarkTheme(theme *ThemeData) *App

WithDarkTheme creates a new app instance with a custom dark theme (builder pattern)

func (*App) WithLightTheme added in v1.2.0

func (app *App) WithLightTheme(theme *ThemeData) *App

WithLightTheme creates a new app instance with a custom light theme (builder pattern)

func (*App) WithTheme added in v1.2.0

func (app *App) WithTheme(theme *ThemeData) *App

WithTheme creates a new app instance with a custom theme (builder pattern)

func (*App) WithThemeMode added in v1.2.0

func (app *App) WithThemeMode(mode ThemeMode) *App

WithThemeMode creates a new app instance with a specific theme mode (builder pattern)

type BoxConstraints added in v1.2.0

type BoxConstraints struct {
	MinWidth  float64
	MaxWidth  float64
	MinHeight float64
	MaxHeight float64
}

BoxConstraints represents layout constraints

type Breakpoint added in v1.2.0

type Breakpoint string

Breakpoint represents responsive design breakpoints

const (
	BreakpointXS Breakpoint = "xs" // < 576px
	BreakpointSM Breakpoint = "sm" // >= 576px
	BreakpointMD Breakpoint = "md" // >= 768px
	BreakpointLG Breakpoint = "lg" // >= 992px
	BreakpointXL Breakpoint = "xl" // >= 1200px
)

func GetBreakpoint added in v1.2.0

func GetBreakpoint(width float64) Breakpoint

GetBreakpoint returns the appropriate breakpoint for a given width

type Brightness added in v1.2.0

type Brightness string

Brightness represents light or dark theme mode

const (
	BrightnessLight Brightness = "light"
	BrightnessDark  Brightness = "dark"
)

type CSSGenerator added in v1.2.0

type CSSGenerator struct {
	// contains filtered or unexported fields
}

CSSGenerator generates CSS from theme data

func NewCSSGenerator added in v1.2.0

func NewCSSGenerator(prefix string) *CSSGenerator

NewCSSGenerator creates a new CSS generator

func (*CSSGenerator) GenerateCSS added in v1.2.0

func (cg *CSSGenerator) GenerateCSS(theme *ThemeData) string

GenerateCSS generates CSS custom properties from theme data

type CallbackError added in v1.2.0

type CallbackError struct {
	CallbackID  string      // ID of the callback that failed
	WidgetType  string      // Type of widget that triggered the callback
	WidgetID    string      // ID of the widget that triggered the callback
	EventType   string      // Type of event (OnPressed, OnChanged, etc.)
	OriginalErr error       // The original error that occurred
	Timestamp   time.Time   // When the error occurred
	StackTrace  string      // Stack trace at the time of error
	Context     interface{} // Additional context information
	Recoverable bool        // Whether the error is recoverable
}

CallbackError represents an error that occurred during callback execution

func CreateCallbackError added in v1.2.0

func CreateCallbackError(callbackID, widgetType, widgetID, eventType string, originalErr error, recoverable bool) *CallbackError

CreateCallbackError creates a new callback error with stack trace

func (*CallbackError) Error added in v1.2.0

func (ce *CallbackError) Error() string

Error implements the error interface

func (*CallbackError) String added in v1.2.0

func (ce *CallbackError) String() string

String returns a detailed string representation of the error

type CallbackInfo added in v1.2.0

type CallbackInfo struct {
	ID           string                 // Unique callback identifier
	WidgetID     string                 // Widget instance identifier
	WidgetType   string                 // Type of widget (Button, TextField, etc.)
	CallbackType string                 // Type of callback (OnPressed, OnChanged, etc.)
	Function     interface{}            // The actual Go function to execute
	Context      *Context               // Context when callback was registered
	Parameters   map[string]interface{} // Additional parameters for the callback
	CreatedAt    time.Time              // When the callback was registered
	LastUsed     time.Time              // When the callback was last executed
}

CallbackInfo stores information about a registered callback

type CallbackParameter added in v1.2.0

type CallbackParameter struct {
	Name  string
	Value interface{}
	Type  string
}

CallbackParameter represents a parameter passed to a callback

type CallbackRecoveryStrategy added in v1.2.0

type CallbackRecoveryStrategy struct{}

CallbackRecoveryStrategy implements recovery for callback errors

func (*CallbackRecoveryStrategy) CanRecover added in v1.2.0

func (crs *CallbackRecoveryStrategy) CanRecover(err error) bool

CanRecover checks if this strategy can recover from the error

func (*CallbackRecoveryStrategy) Recover added in v1.2.0

func (crs *CallbackRecoveryStrategy) Recover(err error, context interface{}) error

Recover attempts to recover from a callback error

type CallbackRegistry added in v1.2.0

type CallbackRegistry struct {
	// contains filtered or unexported fields
}

CallbackRegistry manages widget callback registration and execution

func NewCallbackRegistry added in v1.2.0

func NewCallbackRegistry(app *App) *CallbackRegistry

NewCallbackRegistry creates a new callback registry

func (*CallbackRegistry) CleanupCallback added in v1.2.0

func (cr *CallbackRegistry) CleanupCallback(callbackID string)

CleanupCallback removes a callback from the registry

func (*CallbackRegistry) ExecuteCallback added in v1.2.0

func (cr *CallbackRegistry) ExecuteCallback(callbackID string, params map[string]interface{}) error

ExecuteCallback executes a callback by ID with optional parameters

func (*CallbackRegistry) GetCallbackInfo added in v1.2.0

func (cr *CallbackRegistry) GetCallbackInfo(callbackID string) (*CallbackInfo, bool)

GetCallbackInfo returns information about a callback

func (*CallbackRegistry) GetCallbacksByType added in v1.2.0

func (cr *CallbackRegistry) GetCallbacksByType(callbackType string) []*CallbackInfo

GetCallbacksByType returns all callbacks of a specific type

func (*CallbackRegistry) GetCallbacksByWidget added in v1.2.0

func (cr *CallbackRegistry) GetCallbacksByWidget(widgetID string) []*CallbackInfo

GetCallbacksByWidget returns all callbacks for a specific widget

func (*CallbackRegistry) GetStats added in v1.2.0

func (cr *CallbackRegistry) GetStats() map[string]interface{}

GetStats returns statistics about the callback registry

func (*CallbackRegistry) ListCallbacks added in v1.2.0

func (cr *CallbackRegistry) ListCallbacks() map[string]*CallbackInfo

ListCallbacks returns all registered callbacks

func (*CallbackRegistry) RegisterCallback added in v1.2.0

func (cr *CallbackRegistry) RegisterCallback(widgetID, widgetType, callbackType string, fn interface{}, ctx *Context) string

RegisterCallback registers a callback function and returns a unique callback ID

func (*CallbackRegistry) Stop added in v1.2.0

func (cr *CallbackRegistry) Stop()

Stop stops the cleanup timer

type Color added in v1.2.0

type Color struct {
	R, G, B, A uint8
}

Color represents an RGBA color

func LerpColor added in v1.2.0

func LerpColor(a, b Color, t float64) Color

LerpColor interpolates between two colors

func NewColor added in v1.2.0

func NewColor(r, g, b, a uint8) Color

NewColor creates a new Color from RGBA values

func NewColorFromHex added in v1.2.0

func NewColorFromHex(hex string) (Color, error)

NewColorFromHex creates a Color from a hex string (e.g., "#FF0000" or "FF0000")

func (Color) Darken added in v1.2.0

func (c Color) Darken(amount float64) Color

Darken returns a darker version of the color

func (Color) Lighten added in v1.2.0

func (c Color) Lighten(amount float64) Color

Lighten returns a lighter version of the color

func (Color) ToCSS added in v1.2.0

func (c Color) ToCSS() string

ToCSS converts the color to the most appropriate CSS format

func (Color) ToHex added in v1.2.0

func (c Color) ToHex() string

ToHex converts the color to a hex string

func (Color) ToRGBA added in v1.2.0

func (c Color) ToRGBA() string

ToRGBA converts the color to CSS rgba() format

func (Color) WithOpacity added in v1.2.0

func (c Color) WithOpacity(opacity float64) Color

WithOpacity returns a new color with the specified opacity (0.0 to 1.0)

type ColorScheme added in v1.2.0

type ColorScheme struct {
	// Primary colors
	Primary            Color
	OnPrimary          Color
	PrimaryContainer   Color
	OnPrimaryContainer Color

	// Secondary colors
	Secondary            Color
	OnSecondary          Color
	SecondaryContainer   Color
	OnSecondaryContainer Color

	// Tertiary colors
	Tertiary            Color
	OnTertiary          Color
	TertiaryContainer   Color
	OnTertiaryContainer Color

	// Error colors
	Error            Color
	OnError          Color
	ErrorContainer   Color
	OnErrorContainer Color

	// Surface colors
	Surface          Color
	OnSurface        Color
	SurfaceVariant   Color
	OnSurfaceVariant Color
	SurfaceTint      Color

	// Background colors
	Background   Color
	OnBackground Color

	// Outline colors
	Outline        Color
	OutlineVariant Color

	// Other colors
	Shadow           Color
	Scrim            Color
	InverseSurface   Color
	InverseOnSurface Color
	InversePrimary   Color

	// Brightness
	Brightness Brightness
}

ColorScheme defines the color palette for the theme

func NewDarkColorScheme added in v1.2.0

func NewDarkColorScheme() *ColorScheme

NewDarkColorScheme creates a dark color scheme

func NewLightColorScheme added in v1.2.0

func NewLightColorScheme() *ColorScheme

NewLightColorScheme creates a light color scheme

type Config

type Config struct {
	Server struct {
		Port string `yaml:"port"`
		Host string `yaml:"host"`
	} `yaml:"server"`
	WebSocket struct {
		Enabled bool   `yaml:"enabled"`
		Path    string `yaml:"path"`
	} `yaml:"websocket"`
	Static struct {
		Dir   string `yaml:"dir"`
		Cache bool   `yaml:"cache"`
	} `yaml:"static"`
}

Config holds application configuration

type ConsoleErrorLogger added in v1.2.0

type ConsoleErrorLogger struct{}

ConsoleErrorLogger logs errors to the console only

func NewConsoleErrorLogger added in v1.2.0

func NewConsoleErrorLogger() *ConsoleErrorLogger

NewConsoleErrorLogger creates a new console error logger

func (*ConsoleErrorLogger) LogError added in v1.2.0

func (cel *ConsoleErrorLogger) LogError(level string, message string, err error, context interface{})

LogError logs an error to the console

type Context

type Context struct {
	Request  *http.Request
	Response http.ResponseWriter
	App      *App
	// contains filtered or unexported fields
}

Context provides request context and utilities for handlers

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request, app *App) *Context

NewContext creates a new request context

func StateContextFromContext added in v1.2.0

func StateContextFromContext(ctx context.Context) *Context

StateContextFromContext retrieves the state context from a context

func (*Context) Error

func (c *Context) Error(message string, code int)

Error sends an error response

func (*Context) FormValue

func (c *Context) FormValue(name string) string

FormValue gets a form value by name

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get retrieves a value from the context

func (*Context) GetBool

func (c *Context) GetBool(key string) bool

GetBool retrieves a boolean value from the context

func (*Context) GetInt

func (c *Context) GetInt(key string) int

GetInt retrieves an integer value from the context

func (*Context) GetState added in v1.2.0

func (c *Context) GetState(key string) interface{}

GetState retrieves a value from the local state

func (*Context) GetStateBool added in v1.2.0

func (c *Context) GetStateBool(key string) bool

GetStateBool retrieves a boolean value from the state

func (*Context) GetStateInt added in v1.2.0

func (c *Context) GetStateInt(key string) int

GetStateInt retrieves an integer value from the state

func (*Context) GetStateString added in v1.2.0

func (c *Context) GetStateString(key string) string

GetStateString retrieves a string value from the state

func (*Context) GetString

func (c *Context) GetString(key string) string

GetString retrieves a string value from the context

func (*Context) HTMXCurrentURL

func (c *Context) HTMXCurrentURL() string

HTMXCurrentURL returns the current URL from HTMX

func (*Context) HTMXTarget

func (c *Context) HTMXTarget() string

HTMXTarget returns the HTMX target element ID

func (*Context) HTMXTrigger

func (c *Context) HTMXTrigger() string

HTMXTrigger returns the HTMX trigger element ID

func (*Context) Header

func (c *Context) Header(name string) string

Header gets a request header value

func (*Context) IsHTMX

func (c *Context) IsHTMX() bool

IsHTMX returns true if the request is from HTMX

func (*Context) IsSecure

func (c *Context) IsSecure() bool

IsSecure returns true if the request is HTTPS

func (*Context) JSON

func (c *Context) JSON(v interface{}) error

JSON binds request body to a struct

func (*Context) MediaQuery added in v1.2.0

func (c *Context) MediaQuery() *MediaQueryData

MediaQuery returns the current MediaQuery data

func (*Context) Method

func (c *Context) Method() string

Method returns the HTTP method

func (*Context) Param

func (c *Context) Param(name string) string

Param gets a URL parameter by name

func (*Context) ParamInt

func (c *Context) ParamInt(name string) (int, error)

ParamInt gets a URL parameter as integer

func (*Context) Query

func (c *Context) Query(name string) string

Query gets a query parameter by name

func (*Context) QueryInt

func (c *Context) QueryInt(name string) (int, error)

QueryInt gets a query parameter as integer

func (*Context) Redirect

func (c *Context) Redirect(url string, code int)

Redirect sends a redirect response

func (*Context) RegisterHandler

func (c *Context) RegisterHandler(handler Handler) string

RegisterHandler registers a handler function and returns a unique ID

func (*Context) RemoteAddr

func (c *Context) RemoteAddr() string

RemoteAddr returns the client's remote address

func (*Context) RenderTemplate

func (c *Context) RenderTemplate(widget Widget, title string)

RenderTemplate renders a widget using the base HTML template

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set stores a value in the context

func (*Context) SetHeader

func (c *Context) SetHeader(name, value string)

SetHeader sets a response header

func (*Context) SetState added in v1.2.0

func (c *Context) SetState(key string, value interface{})

SetState sets a value in the local state and triggers UI updates

func (*Context) Theme added in v1.2.0

func (c *Context) Theme() *ThemeData

Theme returns the current theme data

func (*Context) URL

func (c *Context) URL() string

URL returns the request URL

func (*Context) UserAgent

func (c *Context) UserAgent() string

UserAgent returns the user agent string

func (*Context) WriteHTML

func (c *Context) WriteHTML(html string)

WriteHTML writes an HTML response

func (*Context) WriteJSON

func (c *Context) WriteJSON(data interface{}) error

WriteJSON writes a JSON response

func (*Context) WriteText

func (c *Context) WriteText(text string)

WriteText writes a plain text response

type ContextKey added in v1.2.0

type ContextKey string

ContextKey is used for context values

const (
	// StateContextKey is the key for storing state context
	StateContextKey ContextKey = "godin_state_context"
)

type DefaultErrorHandler added in v1.2.0

type DefaultErrorHandler struct {
	Logger ErrorLogger
}

DefaultErrorHandler provides default error handling behavior

func NewDefaultErrorHandler added in v1.2.0

func NewDefaultErrorHandler(logger ErrorLogger) *DefaultErrorHandler

NewDefaultErrorHandler creates a new default error handler

func (*DefaultErrorHandler) HandleCallbackError added in v1.2.0

func (deh *DefaultErrorHandler) HandleCallbackError(err *CallbackError)

HandleCallbackError handles callback errors

func (*DefaultErrorHandler) HandleGenericError added in v1.2.0

func (deh *DefaultErrorHandler) HandleGenericError(err error, context interface{})

HandleGenericError handles generic errors

func (*DefaultErrorHandler) HandleStateError added in v1.2.0

func (deh *DefaultErrorHandler) HandleStateError(err *StateError)

HandleStateError handles state management errors

type DevServer

type DevServer struct {
	*Server
	// contains filtered or unexported fields
}

DevServer extends Server with development features

func NewDevServer

func NewDevServer(app *App) *DevServer

NewDevServer creates a development server with hot reload

func (*DevServer) Start

func (ds *DevServer) Start(addr string) error

Start starts the development server with file watching

type DisplayFeature added in v1.2.0

type DisplayFeature struct {
	Bounds Rect
	Type   DisplayFeatureType
	State  DisplayFeatureState
}

DisplayFeature represents a display feature like notches or folds

type DisplayFeatureState added in v1.2.0

type DisplayFeatureState string

DisplayFeatureState represents the state of a display feature

const (
	DisplayFeatureStateUnknown           DisplayFeatureState = "unknown"
	DisplayFeatureStatePostureFlat       DisplayFeatureState = "flat"
	DisplayFeatureStatePostureHalfOpened DisplayFeatureState = "halfOpened"
)

type DisplayFeatureType added in v1.2.0

type DisplayFeatureType string

DisplayFeatureType represents the type of display feature

const (
	DisplayFeatureTypeFold   DisplayFeatureType = "fold"
	DisplayFeatureTypeHinge  DisplayFeatureType = "hinge"
	DisplayFeatureTypeCutout DisplayFeatureType = "cutout"
)

type EdgeInsets added in v1.2.0

type EdgeInsets struct {
	Top    float64
	Right  float64
	Bottom float64
	Left   float64
}

EdgeInsets represents padding or margin values

func NewEdgeInsets added in v1.2.0

func NewEdgeInsets(top, right, bottom, left float64) EdgeInsets

NewEdgeInsets creates EdgeInsets with individual values

func NewEdgeInsetsAll added in v1.2.0

func NewEdgeInsetsAll(value float64) EdgeInsets

NewEdgeInsetsAll creates EdgeInsets with the same value for all sides

func NewEdgeInsetsOnly added in v1.2.0

func NewEdgeInsetsOnly(top, right, bottom, left *float64) EdgeInsets

NewEdgeInsetsOnly creates EdgeInsets with only specified sides

func NewEdgeInsetsSymmetric added in v1.2.0

func NewEdgeInsetsSymmetric(vertical, horizontal float64) EdgeInsets

NewEdgeInsetsSymmetric creates EdgeInsets with vertical and horizontal values

func (EdgeInsets) Horizontal added in v1.2.0

func (e EdgeInsets) Horizontal() float64

Horizontal returns the total horizontal insets (left + right)

func (EdgeInsets) ToCSS added in v1.2.0

func (e EdgeInsets) ToCSS() string

ToCSS converts EdgeInsets to CSS padding/margin format

func (EdgeInsets) Vertical added in v1.2.0

func (e EdgeInsets) Vertical() float64

Vertical returns the total vertical insets (top + bottom)

type ErrorHandler added in v1.2.0

type ErrorHandler interface {
	HandleCallbackError(error *CallbackError)
	HandleStateError(error *StateError)
	HandleGenericError(error error, context interface{})
}

ErrorHandler defines the interface for handling errors

type ErrorLogger added in v1.2.0

type ErrorLogger interface {
	LogError(level string, message string, error error, context interface{})
}

ErrorLogger defines the interface for logging errors

type ErrorRecoveryManager added in v1.2.0

type ErrorRecoveryManager struct {
	// contains filtered or unexported fields
}

ErrorRecoveryManager manages error recovery strategies

func NewErrorRecoveryManager added in v1.2.0

func NewErrorRecoveryManager() *ErrorRecoveryManager

NewErrorRecoveryManager creates a new error recovery manager

func (*ErrorRecoveryManager) Recover added in v1.2.0

func (erm *ErrorRecoveryManager) Recover(err error, context interface{}) error

Recover attempts to recover from an error using registered strategies

func (*ErrorRecoveryManager) RegisterStrategy added in v1.2.0

func (erm *ErrorRecoveryManager) RegisterStrategy(name string, strategy RecoveryStrategy)

RegisterStrategy registers a recovery strategy

type FileWatcher

type FileWatcher struct {
	// contains filtered or unexported fields
}

FileWatcher watches for file changes and triggers reloads

func NewFileWatcher

func NewFileWatcher(app *App) *FileWatcher

NewFileWatcher creates a new file watcher

func (*FileWatcher) Stop added in v1.2.0

func (fw *FileWatcher) Stop()

Stop stops the file watcher

func (*FileWatcher) Watch

func (fw *FileWatcher) Watch(paths []string)

Watch starts watching the specified directories for changes

type FontWeight added in v1.2.0

type FontWeight int

FontWeight represents font weight values

const (
	FontWeightThin       FontWeight = 100
	FontWeightExtraLight FontWeight = 200
	FontWeightLight      FontWeight = 300
	FontWeightNormal     FontWeight = 400
	FontWeightMedium     FontWeight = 500
	FontWeightSemiBold   FontWeight = 600
	FontWeightBold       FontWeight = 700
	FontWeightExtraBold  FontWeight = 800
	FontWeightBlack      FontWeight = 900
)

type GlobalStateManager added in v1.2.0

type GlobalStateManager struct {
	// contains filtered or unexported fields
}

GlobalStateManager manages global state for native Go code execution

func (*GlobalStateManager) GetCurrentContext added in v1.2.0

func (gsm *GlobalStateManager) GetCurrentContext() *Context

GetCurrentContext gets the current context

func (*GlobalStateManager) SetCurrentContext added in v1.2.0

func (gsm *GlobalStateManager) SetCurrentContext(ctx *Context)

SetCurrentContext sets the current context for state operations

type HTMXConfig added in v1.2.0

type HTMXConfig struct {
	EndpointPrefix string            // Prefix for generated endpoints (default: "/api/callbacks")
	CSRFToken      string            // CSRF token for security
	BaseURL        string            // Base URL for endpoints
	Headers        map[string]string // Additional headers to include
	SwapStrategy   string            // Default swap strategy (none, innerHTML, outerHTML, etc.)
	TargetStrategy string            // Default target strategy
}

HTMXConfig represents configuration for HTMX integration

type HTMXErrorHandler added in v1.2.0

type HTMXErrorHandler struct {
	OnClientError  func(statusCode int, message string) string // 4xx errors
	OnServerError  func(statusCode int, message string) string // 5xx errors
	OnNetworkError func(message string) string                 // Network errors
}

HTMXErrorHandler represents an error handler for HTMX requests

type HTMXIntegrator added in v1.2.0

type HTMXIntegrator struct {
	// contains filtered or unexported fields
}

HTMXIntegrator handles automatic HTMX attribute generation

func NewHTMXIntegrator added in v1.2.0

func NewHTMXIntegrator(config *HTMXConfig) *HTMXIntegrator

NewHTMXIntegrator creates a new HTMX integrator with configuration

func (*HTMXIntegrator) AddHeader added in v1.2.0

func (hi *HTMXIntegrator) AddHeader(key, value string)

AddHeader adds a custom header

func (*HTMXIntegrator) GenerateBlurHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateBlurHandler(callbackID string) map[string]string

GenerateBlurHandler generates HTMX attributes for blur events

func (*HTMXIntegrator) GenerateChangeHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateChangeHandler(callbackID string) map[string]string

GenerateChangeHandler generates HTMX attributes for change events

func (*HTMXIntegrator) GenerateClickHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateClickHandler(callbackID string) map[string]string

GenerateClickHandler generates HTMX attributes for click events

func (*HTMXIntegrator) GenerateContextMenuHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateContextMenuHandler(callbackID string) map[string]string

GenerateContextMenuHandler generates HTMX attributes for context menu (right-click) events

func (*HTMXIntegrator) GenerateCustomHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateCustomHandler(event, callbackID string) map[string]string

GenerateCustomHandler generates HTMX attributes for custom events

func (*HTMXIntegrator) GenerateDoubleClickHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateDoubleClickHandler(callbackID string) map[string]string

GenerateDoubleClickHandler generates HTMX attributes for double-click events

func (*HTMXIntegrator) GenerateEnterKeyHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateEnterKeyHandler(callbackID string) map[string]string

GenerateEnterKeyHandler generates HTMX attributes for Enter key events

func (*HTMXIntegrator) GenerateErrorHandlingAttributes added in v1.2.0

func (hi *HTMXIntegrator) GenerateErrorHandlingAttributes(errorHandler *HTMXErrorHandler) map[string]string

GenerateErrorHandlingAttributes generates HTMX attributes for error handling

func (*HTMXIntegrator) GenerateFocusHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateFocusHandler(callbackID string) map[string]string

GenerateFocusHandler generates HTMX attributes for focus events

func (*HTMXIntegrator) GenerateHoverHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateHoverHandler(callbackID string) map[string]string

GenerateHoverHandler generates HTMX attributes for hover events

func (*HTMXIntegrator) GenerateInputHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateInputHandler(callbackID string) map[string]string

GenerateInputHandler generates HTMX attributes for input events (real-time text changes)

func (*HTMXIntegrator) GenerateKeyHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateKeyHandler(callbackID string, keyCode int) map[string]string

GenerateKeyHandler generates HTMX attributes for keyboard events

func (*HTMXIntegrator) GenerateLoadingIndicatorAttributes added in v1.2.0

func (hi *HTMXIntegrator) GenerateLoadingIndicatorAttributes(indicatorSelector string) map[string]string

GenerateLoadingIndicatorAttributes generates HTMX attributes for loading indicators

func (*HTMXIntegrator) GeneratePollingHandler added in v1.2.0

func (hi *HTMXIntegrator) GeneratePollingHandler(callbackID string, intervalMs int) map[string]string

GeneratePollingHandler generates HTMX attributes for polling/periodic updates

func (*HTMXIntegrator) GenerateProgressAttributes added in v1.2.0

func (hi *HTMXIntegrator) GenerateProgressAttributes() map[string]string

GenerateProgressAttributes generates HTMX attributes for progress tracking

func (*HTMXIntegrator) GenerateSubmitHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateSubmitHandler(callbackID string) map[string]string

GenerateSubmitHandler generates HTMX attributes for submit events

func (*HTMXIntegrator) GenerateWebSocketHandler added in v1.2.0

func (hi *HTMXIntegrator) GenerateWebSocketHandler(wsEndpoint string) map[string]string

GenerateWebSocketHandler generates HTMX attributes for WebSocket integration

func (*HTMXIntegrator) GetConfig added in v1.2.0

func (hi *HTMXIntegrator) GetConfig() HTMXConfig

GetConfig returns the current configuration

func (*HTMXIntegrator) RemoveHeader added in v1.2.0

func (hi *HTMXIntegrator) RemoveHeader(key string)

RemoveHeader removes a custom header

func (*HTMXIntegrator) SetCSRFToken added in v1.2.0

func (hi *HTMXIntegrator) SetCSRFToken(token string)

SetCSRFToken sets the CSRF token for security

func (*HTMXIntegrator) SetSwapStrategy added in v1.2.0

func (hi *HTMXIntegrator) SetSwapStrategy(strategy string)

SetSwapStrategy sets the default swap strategy

func (*HTMXIntegrator) SetTargetStrategy added in v1.2.0

func (hi *HTMXIntegrator) SetTargetStrategy(target string)

SetTargetStrategy sets the default target strategy

type Handler

type Handler func(ctx *Context) Widget

Handler represents a route handler function

type LayoutBuilder added in v1.2.0

type LayoutBuilder struct {
	Builder func(ctx *Context, constraints BoxConstraints) Widget
}

LayoutBuilder provides constraints-based layout building

func (LayoutBuilder) Render added in v1.2.0

func (lb LayoutBuilder) Render(ctx *Context) string

Render renders the LayoutBuilder

type MediaQueryData added in v1.2.0

type MediaQueryData struct {
	Size                  Size
	DevicePixelRatio      float64
	TextScaleFactor       float64
	Padding               EdgeInsets
	ViewInsets            EdgeInsets
	ViewPadding           EdgeInsets
	AlwaysUse24HourFormat bool
	AccessibleNavigation  bool
	InvertColors          bool
	HighContrast          bool
	DisableAnimations     bool
	BoldText              bool
	Orientation           Orientation
	PlatformBrightness    Brightness
	Breakpoint            Breakpoint
	SystemGestureInsets   EdgeInsets
	DisplayFeatures       []DisplayFeature
}

MediaQueryData contains screen and device information

func MediaQueryOf added in v1.2.0

func MediaQueryOf(ctx *Context) *MediaQueryData

MediaQueryOf returns the MediaQueryData from the context

func NewDefaultMediaQueryData added in v1.2.0

func NewDefaultMediaQueryData() *MediaQueryData

NewDefaultMediaQueryData creates default MediaQueryData

func (*MediaQueryData) GetBreakpointName added in v1.2.0

func (mqd *MediaQueryData) GetBreakpointName() string

GetBreakpointName returns the name of the current breakpoint

func (*MediaQueryData) GetDisplayFeaturesByType added in v1.2.0

func (mqd *MediaQueryData) GetDisplayFeaturesByType(featureType DisplayFeatureType) []DisplayFeature

GetDisplayFeaturesByType returns display features of a specific type

func (*MediaQueryData) GetSafeAreaInsets added in v1.2.0

func (mqd *MediaQueryData) GetSafeAreaInsets() EdgeInsets

GetSafeAreaInsets returns the safe area insets

func (*MediaQueryData) GetViewportSize added in v1.2.0

func (mqd *MediaQueryData) GetViewportSize() Size

GetViewportSize returns the viewport size minus insets

func (*MediaQueryData) HasDisplayFeatures added in v1.2.0

func (mqd *MediaQueryData) HasDisplayFeatures() bool

HasDisplayFeatures returns true if there are display features

func (*MediaQueryData) IsLandscape added in v1.2.0

func (mqd *MediaQueryData) IsLandscape() bool

IsLandscape returns true if the orientation is landscape

func (*MediaQueryData) IsLargeScreen added in v1.2.0

func (mqd *MediaQueryData) IsLargeScreen() bool

IsLargeScreen returns true if the screen is considered large

func (*MediaQueryData) IsMediumScreen added in v1.2.0

func (mqd *MediaQueryData) IsMediumScreen() bool

IsMediumScreen returns true if the screen is considered medium

func (*MediaQueryData) IsPortrait added in v1.2.0

func (mqd *MediaQueryData) IsPortrait() bool

IsPortrait returns true if the orientation is portrait

func (*MediaQueryData) IsSmallScreen added in v1.2.0

func (mqd *MediaQueryData) IsSmallScreen() bool

IsSmallScreen returns true if the screen is considered small

type MediaQueryInheritedWidget added in v1.2.0

type MediaQueryInheritedWidget struct {
	Data  *MediaQueryData
	Child Widget
}

MediaQueryInheritedWidget provides MediaQuery data to child widgets

func (MediaQueryInheritedWidget) Render added in v1.2.0

func (mq MediaQueryInheritedWidget) Render(ctx *Context) string

Render renders the MediaQueryInheritedWidget

type MediaQueryProvider added in v1.2.0

type MediaQueryProvider struct {
	// contains filtered or unexported fields
}

MediaQueryProvider manages screen information and updates

func NewMediaQueryProvider added in v1.2.0

func NewMediaQueryProvider() *MediaQueryProvider

NewMediaQueryProvider creates a new MediaQueryProvider

func (*MediaQueryProvider) AddListener added in v1.2.0

func (mqp *MediaQueryProvider) AddListener(listener func(*MediaQueryData))

AddListener adds a MediaQuery change listener

func (*MediaQueryProvider) GetData added in v1.2.0

func (mqp *MediaQueryProvider) GetData() *MediaQueryData

GetData returns the current MediaQueryData

func (*MediaQueryProvider) QueueUpdate added in v1.2.0

func (mqp *MediaQueryProvider) QueueUpdate(data *MediaQueryData)

QueueUpdate queues a MediaQuery update

func (*MediaQueryProvider) RemoveListener added in v1.2.0

func (mqp *MediaQueryProvider) RemoveListener(listener func(*MediaQueryData))

RemoveListener removes a MediaQuery change listener

func (*MediaQueryProvider) StartListening added in v1.2.0

func (mqp *MediaQueryProvider) StartListening()

StartListening starts listening for MediaQuery updates

func (*MediaQueryProvider) StopListening added in v1.2.0

func (mqp *MediaQueryProvider) StopListening()

StopListening stops listening for MediaQuery updates

func (*MediaQueryProvider) UpdateAccessibilityFeatures added in v1.2.0

func (mqp *MediaQueryProvider) UpdateAccessibilityFeatures(features AccessibilityFeatures)

UpdateAccessibilityFeatures updates accessibility features

func (*MediaQueryProvider) UpdateData added in v1.2.0

func (mqp *MediaQueryProvider) UpdateData(data *MediaQueryData)

UpdateData updates the MediaQueryData and notifies listeners

func (*MediaQueryProvider) UpdateDevicePixelRatio added in v1.2.0

func (mqp *MediaQueryProvider) UpdateDevicePixelRatio(ratio float64)

UpdateDevicePixelRatio updates the device pixel ratio

func (*MediaQueryProvider) UpdatePlatformBrightness added in v1.2.0

func (mqp *MediaQueryProvider) UpdatePlatformBrightness(brightness Brightness)

UpdatePlatformBrightness updates the platform brightness

func (*MediaQueryProvider) UpdateSize added in v1.2.0

func (mqp *MediaQueryProvider) UpdateSize(width, height float64)

UpdateSize updates just the screen size

func (*MediaQueryProvider) UpdateTextScaleFactor added in v1.2.0

func (mqp *MediaQueryProvider) UpdateTextScaleFactor(factor float64)

UpdateTextScaleFactor updates the text scale factor

type Orientation added in v1.2.0

type Orientation string

Orientation represents screen orientation

const (
	OrientationPortrait  Orientation = "portrait"
	OrientationLandscape Orientation = "landscape"
)

type OrientationBuilder added in v1.2.0

type OrientationBuilder struct {
	Portrait  Widget
	Landscape Widget
	Child     Widget // Fallback widget
}

OrientationBuilder builds different widgets based on orientation

func (OrientationBuilder) Render added in v1.2.0

func (ob OrientationBuilder) Render(ctx *Context) string

Render renders the appropriate widget based on orientation

type RecoveryStrategy added in v1.2.0

type RecoveryStrategy interface {
	CanRecover(err error) bool
	Recover(err error, context interface{}) error
}

RecoveryStrategy defines a strategy for recovering from errors

type Rect added in v1.2.0

type Rect struct {
	Left   float64
	Top    float64
	Right  float64
	Bottom float64
}

Rect represents a rectangle

type ResponsiveBuilder added in v1.2.0

type ResponsiveBuilder struct {
	XS    Widget // Extra small screens
	SM    Widget // Small screens
	MD    Widget // Medium screens
	LG    Widget // Large screens
	XL    Widget // Extra large screens
	Child Widget // Fallback widget
}

ResponsiveBuilder builds different widgets based on screen size

func (ResponsiveBuilder) Render added in v1.2.0

func (rb ResponsiveBuilder) Render(ctx *Context) string

Render renders the appropriate widget based on screen size

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server handles HTTP requests and WebSocket connections

func NewServer

func NewServer(app *App) *Server

NewServer creates a new server instance

func (*Server) Start

func (s *Server) Start(addr string) error

Start starts the HTTP server

type SimpleErrorLogger added in v1.2.0

type SimpleErrorLogger struct {
	// contains filtered or unexported fields
}

SimpleErrorLogger provides a simple implementation of ErrorLogger

func NewSimpleErrorLogger added in v1.2.0

func NewSimpleErrorLogger(logFile string) (*SimpleErrorLogger, error)

NewSimpleErrorLogger creates a new simple error logger

func (*SimpleErrorLogger) Close added in v1.2.0

func (sel *SimpleErrorLogger) Close() error

Close closes the log file if it was opened

func (*SimpleErrorLogger) LogError added in v1.2.0

func (sel *SimpleErrorLogger) LogError(level string, message string, err error, context interface{})

LogError logs an error with the specified level and context

type Size added in v1.2.0

type Size struct {
	Width  float64
	Height float64
}

Size represents width and height dimensions

func LerpSize added in v1.2.0

func LerpSize(a, b Size, t float64) Size

LerpSize interpolates between two sizes

func NewSize added in v1.2.0

func NewSize(width, height float64) Size

NewSize creates a new Size

func (Size) AspectRatio added in v1.2.0

func (s Size) AspectRatio() float64

AspectRatio returns the width/height ratio

func (Size) IsEmpty added in v1.2.0

func (s Size) IsEmpty() bool

IsEmpty returns true if the size has zero or negative dimensions

type StateAPIHandler added in v1.2.0

type StateAPIHandler struct {
	// contains filtered or unexported fields
}

StateAPIHandler handles state-related API endpoints

func NewStateAPIHandler added in v1.2.0

func NewStateAPIHandler(stateManager *state.StateManager) *StateAPIHandler

NewStateAPIHandler creates a new state API handler

func (*StateAPIHandler) RegisterRoutes added in v1.2.0

func (h *StateAPIHandler) RegisterRoutes(app *App)

RegisterRoutes registers state API routes with the app

type StateConsumer added in v1.2.0

type StateConsumer struct {
	StateKey string
	Value    interface{}
}

StateConsumer is a simple widget for rendering state values in API responses

func (*StateConsumer) Render added in v1.2.0

func (sc *StateConsumer) Render(ctx *Context) string

Render renders the state consumer as HTML

type StateError added in v1.2.0

type StateError struct {
	Operation   string      // The operation that failed (Set, Get, Watch, etc.)
	Key         string      // The state key involved
	Value       interface{} // The value involved (if applicable)
	OriginalErr error       // The original error that occurred
	Timestamp   time.Time   // When the error occurred
	StackTrace  string      // Stack trace at the time of error
	Context     interface{} // Additional context information
	Recoverable bool        // Whether the error is recoverable
}

StateError represents an error that occurred during state management

func CreateStateError added in v1.2.0

func CreateStateError(operation, key string, value interface{}, originalErr error, recoverable bool) *StateError

CreateStateError creates a new state error with stack trace

func (*StateError) Error added in v1.2.0

func (se *StateError) Error() string

Error implements the error interface

func (*StateError) String added in v1.2.0

func (se *StateError) String() string

String returns a detailed string representation of the error

type StateRecoveryStrategy added in v1.2.0

type StateRecoveryStrategy struct{}

StateRecoveryStrategy implements recovery for state errors

func (*StateRecoveryStrategy) CanRecover added in v1.2.0

func (srs *StateRecoveryStrategy) CanRecover(err error) bool

CanRecover checks if this strategy can recover from the error

func (*StateRecoveryStrategy) Recover added in v1.2.0

func (srs *StateRecoveryStrategy) Recover(err error, context interface{}) error

Recover attempts to recover from a state error

type StateUpdate added in v1.2.0

type StateUpdate struct {
	UpdateFunc func()                 // Function to execute for the state update
	WidgetIDs  []string               // Widget IDs that should be rebuilt
	Timestamp  time.Time              // When the update was queued
	Context    *Context               // Context for the update
	Metadata   map[string]interface{} // Additional metadata
}

StateUpdate represents a state update operation

type StateUpdater added in v1.2.0

type StateUpdater struct {
	// contains filtered or unexported fields
}

StateUpdater provides Flutter-like setState functionality

func GetGlobalStateUpdater added in v1.2.0

func GetGlobalStateUpdater() *StateUpdater

GetGlobalStateUpdater returns the global state updater instance

func NewStateUpdater added in v1.2.0

func NewStateUpdater(ctx *Context) *StateUpdater

NewStateUpdater creates a new StateUpdater instance

func (*StateUpdater) GetStats added in v1.2.0

func (su *StateUpdater) GetStats() map[string]interface{}

GetStats returns statistics about the state updater

func (*StateUpdater) IsProcessing added in v1.2.0

func (su *StateUpdater) IsProcessing() bool

IsProcessing returns true if the state updater is currently processing updates

func (*StateUpdater) QueueUpdate added in v1.2.0

func (su *StateUpdater) QueueUpdate(update StateUpdate) error

QueueUpdate queues a state update for batch processing

func (*StateUpdater) SetBatchDelay added in v1.2.0

func (su *StateUpdater) SetBatchDelay(delay time.Duration)

SetBatchDelay sets the delay for batching state updates

func (*StateUpdater) Stop added in v1.2.0

func (su *StateUpdater) Stop()

Stop stops the state updater (for cleanup)

func (*StateUpdater) TriggerRebuild added in v1.2.0

func (su *StateUpdater) TriggerRebuild(widgetIDs []string)

TriggerRebuild triggers rebuilds for specific widget IDs

type StateWebSocketHandler added in v1.2.0

type StateWebSocketHandler struct {
	// contains filtered or unexported fields
}

StateWebSocketHandler handles WebSocket connections for real-time state updates

func NewStateWebSocketHandler added in v1.2.0

func NewStateWebSocketHandler(stateManager *state.StateManager) *StateWebSocketHandler

NewStateWebSocketHandler creates a new state WebSocket handler

func (*StateWebSocketHandler) HandleWebSocket added in v1.2.0

func (h *StateWebSocketHandler) HandleWebSocket(w http.ResponseWriter, r *http.Request)

HandleWebSocket handles WebSocket connections for state updates

type TemplateData

type TemplateData struct {
	Title   string
	Content template.HTML // Use template.HTML to prevent escaping
	CSS     template.CSS  // Use template.CSS for CSS content
	JS      template.JS   // Use template.JS for JavaScript content
}

TemplateData represents data for template rendering

type TextAlign added in v1.2.0

type TextAlign string

TextAlign represents text alignment options

const (
	TextAlignLeft    TextAlign = "left"
	TextAlignRight   TextAlign = "right"
	TextAlignCenter  TextAlign = "center"
	TextAlignJustify TextAlign = "justify"
	TextAlignStart   TextAlign = "start"
	TextAlignEnd     TextAlign = "end"
)

type TextStyle added in v1.2.0

type TextStyle struct {
	Color          *Color
	FontSize       *float64
	FontWeight     *FontWeight
	FontFamily     *string
	LetterSpacing  *float64
	LineHeight     *float64
	TextAlign      *TextAlign
	TextDecoration *string
}

TextStyle represents text styling options

func NewTextStyle added in v1.2.0

func NewTextStyle() *TextStyle

NewTextStyle creates a new TextStyle

func (*TextStyle) ToCSS added in v1.2.0

func (ts *TextStyle) ToCSS() map[string]string

ToCSS converts TextStyle to CSS properties

func (*TextStyle) WithColor added in v1.2.0

func (ts *TextStyle) WithColor(color Color) *TextStyle

WithColor sets the text color

func (*TextStyle) WithFontFamily added in v1.2.0

func (ts *TextStyle) WithFontFamily(family string) *TextStyle

WithFontFamily sets the font family

func (*TextStyle) WithFontSize added in v1.2.0

func (ts *TextStyle) WithFontSize(size float64) *TextStyle

WithFontSize sets the font size

func (*TextStyle) WithFontWeight added in v1.2.0

func (ts *TextStyle) WithFontWeight(weight FontWeight) *TextStyle

WithFontWeight sets the font weight

type ThemeData added in v1.2.0

type ThemeData struct {
	ColorScheme     *ColorScheme
	Typography      *Typography
	ComponentThemes map[string]interface{}
	Extensions      map[string]interface{}
	Brightness      Brightness
	CSS             map[string]string // CSS custom properties
	UseMaterial3    bool
	VisualDensity   VisualDensity
}

ThemeData contains all theme configuration

func NewThemeData added in v1.2.0

func NewThemeData() *ThemeData

NewThemeData creates a new ThemeData with default values

type ThemeMode added in v1.2.0

type ThemeMode string

ThemeMode represents how theme should be determined

const (
	ThemeModeSystem ThemeMode = "system" // Follow system preference
	ThemeModeLight  ThemeMode = "light"  // Always use light theme
	ThemeModeDark   ThemeMode = "dark"   // Always use dark theme
)

type ThemeProvider added in v1.2.0

type ThemeProvider struct {
	// contains filtered or unexported fields
}

ThemeProvider manages theme state and updates

func NewThemeProvider added in v1.2.0

func NewThemeProvider() *ThemeProvider

NewThemeProvider creates a new ThemeProvider

func (*ThemeProvider) AddListener added in v1.2.0

func (tp *ThemeProvider) AddListener(listener func(*ThemeData))

AddListener adds a theme change listener

func (*ThemeProvider) GenerateCSS added in v1.2.0

func (tp *ThemeProvider) GenerateCSS() string

GenerateCSS generates CSS custom properties from the current theme

func (*ThemeProvider) GetDarkTheme added in v1.2.0

func (tp *ThemeProvider) GetDarkTheme() *ThemeData

GetDarkTheme returns the dark theme

func (*ThemeProvider) GetLightTheme added in v1.2.0

func (tp *ThemeProvider) GetLightTheme() *ThemeData

GetLightTheme returns the light theme

func (*ThemeProvider) GetTheme added in v1.2.0

func (tp *ThemeProvider) GetTheme() *ThemeData

GetTheme returns the current theme

func (*ThemeProvider) RemoveListener added in v1.2.0

func (tp *ThemeProvider) RemoveListener(listener func(*ThemeData))

RemoveListener removes a theme change listener

func (*ThemeProvider) SetDarkTheme added in v1.2.0

func (tp *ThemeProvider) SetDarkTheme(theme *ThemeData)

SetDarkTheme sets the dark theme

func (*ThemeProvider) SetLightTheme added in v1.2.0

func (tp *ThemeProvider) SetLightTheme(theme *ThemeData)

SetLightTheme sets the light theme

func (*ThemeProvider) SetTheme added in v1.2.0

func (tp *ThemeProvider) SetTheme(theme *ThemeData)

SetTheme sets the current theme

func (*ThemeProvider) SetThemeMode added in v1.2.0

func (tp *ThemeProvider) SetThemeMode(mode ThemeMode)

SetThemeMode sets the theme mode

type Typography added in v1.2.0

type Typography struct {
	// Display styles
	DisplayLarge  *TextStyle
	DisplayMedium *TextStyle
	DisplaySmall  *TextStyle

	// Headline styles
	HeadlineLarge  *TextStyle
	HeadlineMedium *TextStyle
	HeadlineSmall  *TextStyle

	// Title styles
	TitleLarge  *TextStyle
	TitleMedium *TextStyle
	TitleSmall  *TextStyle

	// Body styles
	BodyLarge  *TextStyle
	BodyMedium *TextStyle
	BodySmall  *TextStyle

	// Label styles
	LabelLarge  *TextStyle
	LabelMedium *TextStyle
	LabelSmall  *TextStyle
}

Typography defines text styles for the theme

func NewDefaultTypography added in v1.2.0

func NewDefaultTypography() *Typography

NewDefaultTypography creates default typography

type VisualDensity added in v1.2.0

type VisualDensity struct {
	Horizontal float64
	Vertical   float64
}

VisualDensity represents the visual density of UI elements

type WebSocketManager

type WebSocketManager struct {
	// contains filtered or unexported fields
}

WebSocketManager manages WebSocket connections and channels

func NewWebSocketManager

func NewWebSocketManager() *WebSocketManager

NewWebSocketManager creates a new WebSocket manager

func (*WebSocketManager) Broadcast

func (wsm *WebSocketManager) Broadcast(channel string, data interface{})

Broadcast sends data to all connections on a channel

func (*WebSocketManager) Enable

func (wsm *WebSocketManager) Enable(path string)

Enable enables WebSocket support with the specified path

func (*WebSocketManager) GetConnectionCount

func (wsm *WebSocketManager) GetConnectionCount() int

GetConnectionCount returns the number of active connections

func (*WebSocketManager) GetPath

func (wsm *WebSocketManager) GetPath() string

GetPath returns the WebSocket path

func (*WebSocketManager) HandleConnection

func (wsm *WebSocketManager) HandleConnection(w http.ResponseWriter, r *http.Request)

HandleConnection handles new WebSocket connections

func (*WebSocketManager) IsEnabled

func (wsm *WebSocketManager) IsEnabled() bool

IsEnabled returns whether WebSocket is enabled

func (*WebSocketManager) Publish

func (wsm *WebSocketManager) Publish(channel string, data interface{})

Publish sends data to all subscribers of a channel

func (*WebSocketManager) Subscribe

func (wsm *WebSocketManager) Subscribe(channel string) chan interface{}

Subscribe creates a channel for receiving data

type WebSocketMessage

type WebSocketMessage struct {
	Type    string      `json:"type"`
	Channel string      `json:"channel"`
	Data    interface{} `json:"data"`
}

WebSocketMessage represents a WebSocket message

type Widget

type Widget interface {
	Render(ctx *Context) string
}

Widget interface for rendering components

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL