64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package layout_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.eeqj.de/sneak/hdmistat/internal/fbdraw"
|
|
"git.eeqj.de/sneak/hdmistat/internal/layout"
|
|
)
|
|
|
|
// ExampleScreen shows how to create a screen that implements FrameGenerator
|
|
type ExampleScreen struct {
|
|
name string
|
|
fps float64
|
|
}
|
|
|
|
func (s *ExampleScreen) GenerateFrame(grid *fbdraw.CharGrid) error {
|
|
// Create a draw context with the grid dimensions
|
|
draw := layout.NewDraw(grid.Width, grid.Height)
|
|
|
|
// Clear the screen
|
|
draw.Clear()
|
|
|
|
// Draw a title
|
|
draw.Color(layout.Color("cyan")).Size(16).Bold()
|
|
draw.TextCenter(0, 2, "Example Screen: %s", s.name)
|
|
|
|
// Create a grid for structured layout
|
|
contentGrid := draw.Grid(5, 5, 70, 20)
|
|
contentGrid.Border(layout.Color("gray50"))
|
|
|
|
// Add some content
|
|
contentGrid.Color(layout.Color("white")).WriteCenter(1, "Current Time: %s", time.Now().Format("15:04:05"))
|
|
|
|
// Draw a progress bar
|
|
contentGrid.Color(layout.Color("green")).Bar(10, 5, 50, 75.0, layout.Color("green"))
|
|
|
|
// Add system stats
|
|
contentGrid.Color(layout.Color("yellow")).Write(2, 8, "CPU: %.1f%%", 42.5)
|
|
contentGrid.Color(layout.Color("orange")).Write(2, 9, "Memory: %s / %s", layout.Bytes(4*1024*1024*1024), layout.Bytes(16*1024*1024*1024))
|
|
|
|
// Return the rendered grid
|
|
*grid = *draw.Render()
|
|
return nil
|
|
}
|
|
|
|
func (s *ExampleScreen) FramesPerSecond() float64 {
|
|
return s.fps
|
|
}
|
|
|
|
func TestExampleUsage(t *testing.T) {
|
|
// Create carousel with terminal display for testing
|
|
display := fbdraw.NewTerminalDisplay(80, 25)
|
|
carousel := fbdraw.NewCarousel(display, 5*time.Second)
|
|
|
|
// Add screens
|
|
carousel.AddScreen(&ExampleScreen{name: "Dashboard", fps: 1.0})
|
|
carousel.AddScreen(&ExampleScreen{name: "System Monitor", fps: 2.0})
|
|
carousel.AddScreen(&ExampleScreen{name: "Network Stats", fps: 0.5})
|
|
|
|
// In a real application, you would run this in a goroutine
|
|
// ctx := context.Background()
|
|
// go carousel.Run(ctx)
|
|
} |