/ src / interface / widgets.go
widgets.go
  1  package widgets
  2  
  3  import (
  4  	"github.com/gdamore/tcell/v2"
  5  )
  6  
  7  // CellDisplay represents a widget for displaying a grid of cells.
  8  type CellDisplay struct {
  9  	Cells         [][]bool
 10  	EnergyLevels  [][]float64
 11  	Processing    bool
 12  }
 13  
 14  // NewCellDisplay creates a new CellDisplay widget.
 15  func NewCellDisplay(cells [][]bool, energyLevels [][]float64, processing bool) *CellDisplay {
 16  	return &CellDisplay{
 17  		Cells:         cells,
 18  		EnergyLevels: energyLevels,
 19  		Processing:   processing,
 20  	}
 21  }
 22  
 23  // Render renders the CellDisplay widget to the screen.
 24  func (c *CellDisplay) Render(screen tcell.Screen, x, y, width, height int) {
 25  	for row := 0; row < len(c.Cells); row++ {
 26  		for col := 0; col < len(c.Cells[row]); col++ {
 27  			if row < height && col < width {
 28  				isActive := c.Cells[row][col]
 29  				energy := c.EnergyLevels[row][col]
 30  
 31  				var displayChar rune
 32  				if isActive {
 33  					if c.Processing {
 34  						displayChar = '◆'
 35  					} else {
 36  						displayChar = '■'
 37  					}
 38  				} else {
 39  					displayChar = '·'
 40  				}
 41  
 42  				// Enhanced color scheme
 43  				var color tcell.Color
 44  				if isActive {
 45  					switch {
 46  					case energy > 0.8:
 47  						color = tcell.NewRGBColor(0, 255, 255) // Bright cyan
 48  					case energy > 0.6:
 49  						color = tcell.NewRGBColor(0, 200, 255) // Arc reactor blue
 50  					case energy > 0.4:
 51  						color = tcell.NewRGBColor(0, 150, 255) // Medium blue
 52  					default:
 53  						color = tcell.NewRGBColor(0, 100, 255) // Deep blue
 54  					}
 55  				} else {
 56  					color = tcell.NewRGBColor(30, 30, 30) // Darker background
 57  				}
 58  
 59  				style := tcell.StyleDefault.Foreground(color)
 60  				if c.Processing {
 61  					style = style.Bold(true)
 62  				}
 63  
 64  				screen.SetContent(x+col, y+row, displayChar, nil, style)
 65  			}
 66  		}
 67  	}
 68  }
 69  
 70  // EnergyBar represents a widget for displaying an energy bar.
 71  type EnergyBar struct {
 72  	Progress float64
 73  }
 74  
 75  // NewEnergyBar creates a new EnergyBar widget.
 76  func NewEnergyBar(progress float64) *EnergyBar {
 77  	if progress < 0.0 {
 78  		progress = 0.0
 79  	} else if progress > 1.0 {
 80  		progress = 1.0
 81  	}
 82  	return &EnergyBar{
 83  		Progress: progress,
 84  	}
 85  }
 86  
 87  // Render renders the EnergyBar widget to the screen.
 88  func (e *EnergyBar) Render(screen tcell.Screen, x, y, width int) {
 89  	filled := int(e.Progress * float64(width))
 90  
 91  	for i := 0; i < width; i++ {
 92  		var symbol rune
 93  		if i < filled {
 94  			symbol = '█'
 95  		} else {
 96  			symbol = '░'
 97  		}
 98  
 99  		var color tcell.Color
100  		if i < filled {
101  			progress := float64(i) / float64(width)
102  			switch {
103  			case progress > 0.8:
104  				color = tcell.NewRGBColor(0, 255, 255) // Bright cyan
105  			case progress > 0.6:
106  				color = tcell.NewRGBColor(0, 200, 200) // Medium cyan
107  			case progress > 0.4:
108  				color = tcell.NewRGBColor(0, 150, 150) // Dark cyan
109  			default:
110  				color = tcell.NewRGBColor(0, 100, 100) // Very dark cyan
111  			}
112  		} else {
113  			color = tcell.ColorDarkGray
114  		}
115  
116  		screen.SetContent(x+i, y, symbol, nil, tcell.StyleDefault.Foreground(color))
117  	}
118  }