@@ -1,6 +1,9 @@
package lazylist
-import "charm.land/lipgloss/v2"
+import (
+ "charm.land/lipgloss/v2"
+ "github.com/charmbracelet/x/ansi"
+)
// Item represents a single item in the lazy-loaded list.
type Item interface {
@@ -22,3 +25,10 @@ type HighlightStylable interface {
// HighlightStyle returns the style to apply for highlighted regions.
HighlightStyle() lipgloss.Style
}
+
+// MouseClickable represents an item that can handle mouse click events.
+type MouseClickable interface {
+ // HandleMouseClick processes a mouse click event at the given coordinates.
+ // It returns true if the event was handled, false otherwise.
+ HandleMouseClick(btn ansi.MouseButton, x, y int) bool
+}
@@ -5,6 +5,7 @@ import (
"strings"
"charm.land/lipgloss/v2"
+ "github.com/charmbracelet/x/ansi"
)
// List represents a list of items that can be lazily rendered. A list is
@@ -550,6 +551,12 @@ func (l *List) HandleMouseDown(x, y int) bool {
// Select the clicked item
l.SetSelected(itemIdx)
+ if clickable, ok := l.items[itemIdx].(MouseClickable); ok {
+ clickable.HandleMouseClick(ansi.MouseButton1, x, itemY)
+ l.items[itemIdx] = clickable.(Item)
+ l.invalidateItem(itemIdx)
+ }
+
return true
}