()
| 64 | } |
| 65 | |
| 66 | func (pt *Plot) Init() { |
| 67 | pt.WidgetBase.Init() |
| 68 | pt.Scale = 1 |
| 69 | pt.Styler(func(s *styles.Style) { |
| 70 | s.Min.Set(units.Dp(256)) |
| 71 | ro := pt.IsReadOnly() |
| 72 | s.SetAbilities(!ro, abilities.Slideable, abilities.Activatable, abilities.Scrollable) |
| 73 | if !ro { |
| 74 | if s.Is(states.Active) { |
| 75 | s.Cursor = cursors.Grabbing |
| 76 | s.StateLayer = 0 |
| 77 | } else { |
| 78 | s.Cursor = cursors.Grab |
| 79 | } |
| 80 | } |
| 81 | }) |
| 82 | |
| 83 | pt.On(events.SlideMove, func(e events.Event) { |
| 84 | e.SetHandled() |
| 85 | if pt.Plot == nil { |
| 86 | return |
| 87 | } |
| 88 | del := e.PrevDelta() |
| 89 | dx := -float32(del.X) * (pt.Plot.X.Max - pt.Plot.X.Min) * 0.0008 |
| 90 | dy := float32(del.Y) * (pt.Plot.Y.Max - pt.Plot.Y.Min) * 0.0008 |
| 91 | pt.Plot.X.Min += dx |
| 92 | pt.Plot.X.Max += dx |
| 93 | pt.Plot.Y.Min += dy |
| 94 | pt.Plot.Y.Max += dy |
| 95 | pt.updatePlot() |
| 96 | pt.NeedsRender() |
| 97 | }) |
| 98 | |
| 99 | pt.On(events.Scroll, func(e events.Event) { |
| 100 | e.SetHandled() |
| 101 | if pt.Plot == nil { |
| 102 | return |
| 103 | } |
| 104 | se := e.(*events.MouseScroll) |
| 105 | sc := 1 + (float32(se.Delta.Y) * 0.002) |
| 106 | pt.Plot.X.Min *= sc |
| 107 | pt.Plot.X.Max *= sc |
| 108 | pt.Plot.Y.Min *= sc |
| 109 | pt.Plot.Y.Max *= sc |
| 110 | pt.updatePlot() |
| 111 | pt.NeedsRender() |
| 112 | }) |
| 113 | } |
| 114 | |
| 115 | func (pt *Plot) WidgetTooltip(pos image.Point) (string, image.Point) { |
| 116 | if pos == image.Pt(-1, -1) { |
nothing calls this directly
no test coverage detected