Change mouse pointer shape over input area
This commit is contained in:
parent
834d0d3848
commit
fdf0a13687
4 changed files with 22 additions and 11 deletions
|
|
@ -41,8 +41,8 @@ func (h *Handler) draw_footer() (num_lines int, err error) {
|
|||
text = sfunc(text)
|
||||
}
|
||||
buf.WriteString(text)
|
||||
if click_name != "" {
|
||||
crs = append(crs, single_line_region{x: pos, width: sz, y: len(lines), id: click_name, callback: func(filter string) error {
|
||||
if click_name != "" && click_name != h.state.current_filter {
|
||||
crs = append(crs, single_line_region{x: pos, width: sz - 1, y: len(lines), id: click_name, callback: func(filter string) error {
|
||||
h.set_filter(filter)
|
||||
h.state.redraw_needed = true
|
||||
return nil
|
||||
|
|
@ -59,7 +59,7 @@ func (h *Handler) draw_footer() (num_lines int, err error) {
|
|||
}
|
||||
offset := h.screen_size.height - len(lines)
|
||||
for _, cr := range crs {
|
||||
h.state.mouse_state.AddCellRegion(cr.id, cr.x, cr.y+offset, cr.x+cr.width, cr.y+offset, cr.callback)
|
||||
h.state.mouse_state.AddCellRegion(cr.id, cr.x, cr.y+offset, cr.x+cr.width, cr.y+offset, cr.callback).HoverStyle = "default fg=red"
|
||||
}
|
||||
}
|
||||
if len(lines) > 0 {
|
||||
|
|
|
|||
|
|
@ -187,7 +187,11 @@ type Handler struct {
|
|||
func (h *Handler) draw_screen() (err error) {
|
||||
h.state.redraw_needed = false
|
||||
h.lp.StartAtomicUpdate()
|
||||
defer h.lp.EndAtomicUpdate()
|
||||
defer func() {
|
||||
h.state.mouse_state.UpdateHoveredIds()
|
||||
h.state.mouse_state.ApplyHoverStyles(h.lp)
|
||||
h.lp.EndAtomicUpdate()
|
||||
}()
|
||||
h.lp.ClearScreen()
|
||||
h.state.mouse_state.ClearCellRegions()
|
||||
switch h.state.screen {
|
||||
|
|
@ -207,8 +211,6 @@ func (h *Handler) draw_screen() (err error) {
|
|||
case SAVE_FILE:
|
||||
err = h.draw_save_file_name_screen()
|
||||
}
|
||||
h.state.mouse_state.UpdateHoveredIds()
|
||||
h.state.mouse_state.ApplyHoverStyles(h.lp)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ func (h *Handler) draw_search_bar(y int) {
|
|||
h.lp.MoveCursorTo(1+left_margin, 1+y)
|
||||
available_width := h.screen_size.width - left_margin - right_margin
|
||||
h.draw_frame(available_width, SEARCH_BAR_HEIGHT)
|
||||
for y1 := y; y1 < y+4; y1++ {
|
||||
cr := h.state.mouse_state.AddCellRegion("search-bar", left_margin, y1, left_margin+available_width, y1)
|
||||
cr.PointerShape = loop.TEXT_POINTER
|
||||
cr.HoverStyle = "none"
|
||||
}
|
||||
h.lp.MoveCursorTo(1+left_margin+1, 2+y)
|
||||
h.draw_search_text(available_width - 2)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package tui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/kovidgoyal/kitty"
|
||||
|
|
@ -214,6 +215,7 @@ type CellRegion struct {
|
|||
Id string
|
||||
OnClick []func(id string) error
|
||||
PointerShape loop.PointerShape
|
||||
HoverStyle string // set to "default" for the global hover style
|
||||
}
|
||||
|
||||
func (c CellRegion) Contains(x, y int) bool { // 0-based
|
||||
|
|
@ -237,7 +239,7 @@ type MouseState struct {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *MouseState) AddRegion(cr CellRegion) *CellRegion {
|
||||
func (m *MouseState) add_region(cr CellRegion) *CellRegion {
|
||||
m.regions = append(m.regions, &cr)
|
||||
if m.region_id_map == nil {
|
||||
m.region_id_map = make(map[string][]*CellRegion)
|
||||
|
|
@ -251,9 +253,8 @@ func (m *MouseState) AddRegion(cr CellRegion) *CellRegion {
|
|||
}
|
||||
|
||||
func (m *MouseState) AddCellRegion(id string, start_x, start_y, end_x, end_y int, on_click ...func(id string) error) *CellRegion {
|
||||
cr := CellRegion{
|
||||
TopLeft: Point{start_x, start_y}, BottomRight: Point{end_x, end_y}, Id: id, OnClick: on_click, PointerShape: loop.POINTER_POINTER}
|
||||
return m.AddRegion(cr)
|
||||
return m.add_region(CellRegion{
|
||||
TopLeft: Point{start_x, start_y}, BottomRight: Point{end_x, end_y}, Id: id, OnClick: on_click, PointerShape: loop.POINTER_POINTER, HoverStyle: "default"})
|
||||
}
|
||||
|
||||
func (m *MouseState) ClearCellRegions() {
|
||||
|
|
@ -307,7 +308,10 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) {
|
|||
ps := loop.DEFAULT_POINTER
|
||||
for id := range m.hovered_ids.Iterable() {
|
||||
for _, r := range m.region_id_map[id] {
|
||||
lp.StyleRegion(hs, r.TopLeft.X, r.TopLeft.Y, r.BottomRight.X, r.BottomRight.Y)
|
||||
if r.HoverStyle != "" {
|
||||
s := strings.Replace(r.HoverStyle, "default", hs, 1)
|
||||
lp.StyleRegion(s, r.TopLeft.X, r.TopLeft.Y, r.BottomRight.X, r.BottomRight.Y)
|
||||
}
|
||||
is_hovered = true
|
||||
ps = r.PointerShape
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue