package elements import ( "context" "fmt" ) type Table struct { mouseHandler Block ColumnCount int RowCount int Cells []Element Style struct { } mouseOverCell int } func (t Table) HandleClick(ctx context.Context, s MouseState) error { address := t.getAddressUnderMouse() if address < 0 || address >= len(t.Cells) { return fmt.Errorf("cell address under mouse is out of bounds") } if clickable, ok := t.Cells[address].(Clickable); ok { return clickable.HandleClick(ctx, s) } } func (t Table) HandleMouseEnter(s MouseState) error { _ = t.mouseHandler.HandleMouseEnter(s) } func (t Table) HandleMouseLeave(s MouseState) error { _ = t.mouseHandler.HandleMouseLeave(s) } func (t Table) HandleMouseMove(s MouseState) error { _ = t.mouseHandler.HandleMouseMove(s) } func (t Table) HandleMouseDown(s MouseState) error { _ = t.mouseHandler.HandleMouseDown(s) } func (t Table) HandleMouseUp(s MouseState) error { _ = t.mouseHandler.HandleMouseUp(s) } func (t *Table) getAddressUnderMouse() int { return int(t.mouseState.Y)*t.RowCount + int(t.mouseState.X) }