onCursor process subscribed cursor events over the window
(evname string, ev interface{})
| 157 | |
| 158 | // onCursor process subscribed cursor events over the window |
| 159 | func (w *Window) onCursor(evname string, ev interface{}) { |
| 160 | |
| 161 | // If the window is not resizable we are not interested in cursor movements |
| 162 | if !w.resizable { |
| 163 | return |
| 164 | } |
| 165 | if evname == OnCursor { |
| 166 | cev := ev.(*window.CursorEvent) |
| 167 | // If already dragging - update window size and position depending |
| 168 | // on the cursor position and the borders being dragged |
| 169 | if w.drag { |
| 170 | if w.overTop { |
| 171 | delta := cev.Ypos - w.pospix.Y |
| 172 | newHeight := w.Height() - delta |
| 173 | minHeight := w.title.height |
| 174 | if newHeight >= minHeight { |
| 175 | w.SetPositionY(w.Position().Y + delta) |
| 176 | w.SetHeight(math32.Max(newHeight, minHeight)) |
| 177 | } else { |
| 178 | w.SetPositionY(w.Position().Y + w.Height() - minHeight) |
| 179 | w.SetHeight(w.title.height) |
| 180 | } |
| 181 | } |
| 182 | if w.overRight { |
| 183 | delta := cev.Xpos - (w.pospix.X + w.width) |
| 184 | newWidth := w.Width() + delta |
| 185 | w.SetWidth(math32.Max(newWidth, w.title.label.Width()+w.title.closeButton.Width())) |
| 186 | } |
| 187 | if w.overBottom { |
| 188 | delta := cev.Ypos - (w.pospix.Y + w.height) |
| 189 | newHeight := w.Height() + delta |
| 190 | w.SetHeight(math32.Max(newHeight, w.title.height)) |
| 191 | } |
| 192 | if w.overLeft { |
| 193 | delta := cev.Xpos - w.pospix.X |
| 194 | newWidth := w.Width() - delta |
| 195 | minWidth := w.title.label.Width() + w.title.closeButton.Width() |
| 196 | if newWidth >= minWidth { |
| 197 | w.SetPositionX(w.Position().X + delta) |
| 198 | w.SetWidth(math32.Max(newWidth, minWidth)) |
| 199 | } else { |
| 200 | w.SetPositionX(w.Position().X + w.Width() - minWidth) |
| 201 | w.SetWidth(minWidth) |
| 202 | } |
| 203 | } |
| 204 | } else { |
| 205 | // Obtain cursor position relative to window |
| 206 | cx := cev.Xpos - w.pospix.X |
| 207 | cy := cev.Ypos - w.pospix.Y |
| 208 | // Check if cursor is on the top of the window (border + drag margin) |
| 209 | if cy <= w.borderSizes.Top { |
| 210 | w.overTop = true |
| 211 | } else { |
| 212 | w.overTop = false |
| 213 | } |
| 214 | // Check if cursor is on the bottom of the window (border + drag margin) |
| 215 | if cy >= w.height-w.borderSizes.Bottom-w.dragPadding { |
| 216 | w.overBottom = true |
nothing calls this directly
no test coverage detected