fix(browser): fix directory navigation and entry tapping
This commit is contained in:
+15
-14
@@ -234,7 +234,7 @@ type ListView struct {
|
||||
Items []ListItem
|
||||
ScrollOffset Dp // pixel-level scroll offset
|
||||
Selected int
|
||||
RowFilenames []string // filenames for click navigation
|
||||
RowTapHandler func(any) // handler for row taps, receives index as any
|
||||
}
|
||||
|
||||
func (lv ListView) Region() Region { return lv.region }
|
||||
@@ -299,15 +299,15 @@ func (lv ListView) Draw(gtx layout.Context, r *Renderer) {
|
||||
}
|
||||
// Register click area for this row
|
||||
rowID := fmt.Sprintf("list_row_%d", rowGlobalIndex)
|
||||
var filename string
|
||||
if i < len(lv.RowFilenames) {
|
||||
filename = lv.RowFilenames[i]
|
||||
}
|
||||
r.RegisterClick(gtx, rowID, Region{
|
||||
X: lv.region.X, Y: y,
|
||||
W: lv.region.W, H: rowHeight,
|
||||
}, func(data any) {
|
||||
OpenFile(filename)
|
||||
if lv.RowTapHandler != nil {
|
||||
lv.RowTapHandler(rowGlobalIndex)
|
||||
} else {
|
||||
OpenFile(item.Text)
|
||||
}
|
||||
})
|
||||
// Draw main text
|
||||
textRegion := Region{
|
||||
@@ -331,15 +331,16 @@ func (lv ListView) Draw(gtx layout.Context, r *Renderer) {
|
||||
}
|
||||
|
||||
// NewListView creates a visible ListView element.
|
||||
func NewListView(id string, items []ListItem, region Region, scrollOffset Dp, selected int, interactions []Interaction) ListView {
|
||||
func NewListView(id string, items []ListItem, region Region, scrollOffset Dp, selected int, interactions []Interaction, rowTapHandler func(any)) ListView {
|
||||
return ListView{
|
||||
id: id,
|
||||
region: region,
|
||||
visible: true,
|
||||
interactions: interactions,
|
||||
Items: items,
|
||||
ScrollOffset: scrollOffset,
|
||||
Selected: selected,
|
||||
id: id,
|
||||
region: region,
|
||||
visible: true,
|
||||
interactions: interactions,
|
||||
Items: items,
|
||||
ScrollOffset: scrollOffset,
|
||||
Selected: selected,
|
||||
RowTapHandler: rowTapHandler,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user