github.com/jmigpin/editor@v1.6.0/util/uiutil/widget/scrollhandle.go (about)

     1  package widget
     2  
     3  import (
     4  	"image"
     5  	"image/color"
     6  
     7  	"github.com/jmigpin/editor/util/imageutil"
     8  	"github.com/jmigpin/editor/util/uiutil/event"
     9  )
    10  
    11  // Used by ScrollBar.
    12  type ScrollHandle struct {
    13  	ENode
    14  	ctx    ImageContext
    15  	sb     *ScrollBar
    16  	inside bool
    17  }
    18  
    19  func NewScrollHandle(ctx ImageContext, sb *ScrollBar) *ScrollHandle {
    20  	sh := &ScrollHandle{ctx: ctx, sb: sb}
    21  
    22  	// the scrollbar handles the decision making, the handle only draws
    23  	sh.AddMarks(MarkNotDraggable)
    24  
    25  	return sh
    26  }
    27  
    28  func (sh *ScrollHandle) Paint() {
    29  	var c color.Color
    30  	if sh.sb.clicking || sh.sb.dragging {
    31  		c = sh.TreeThemePaletteColor("scrollhandle_select")
    32  	} else if sh.inside {
    33  		c = sh.TreeThemePaletteColor("scrollhandle_hover")
    34  	} else {
    35  		c = sh.TreeThemePaletteColor("scrollhandle_normal")
    36  	}
    37  	imageutil.FillRectangle(sh.ctx.Image(), sh.Bounds, c)
    38  }
    39  
    40  func (sh *ScrollHandle) OnInputEvent(ev interface{}, p image.Point) event.Handled {
    41  	switch ev.(type) {
    42  	case *event.MouseEnter:
    43  		sh.inside = true
    44  		sh.MarkNeedsPaint()
    45  	case *event.MouseLeave:
    46  		sh.inside = false
    47  		sh.MarkNeedsPaint()
    48  	}
    49  	return false
    50  }