scrollToBoxDim scrolls to ensure that given target [min..max] range along one dimension is in view. Returns true if scrolling was needed
(d math32.Dims, tmini, tmaxi int)
| 351 | // scrollToBoxDim scrolls to ensure that given target [min..max] range |
| 352 | // along one dimension is in view. Returns true if scrolling was needed |
| 353 | func (fr *Frame) scrollToBoxDim(d math32.Dims, tmini, tmaxi int) bool { |
| 354 | if !fr.HasScroll[d] || fr.scrolls[d] == nil { |
| 355 | return false |
| 356 | } |
| 357 | sb := fr.scrolls[d] |
| 358 | if sb == nil || sb.This == nil { |
| 359 | return false |
| 360 | } |
| 361 | tmin, tmax := float32(tmini), float32(tmaxi) |
| 362 | cmin, cmax := fr.Geom.contentRangeDim(d) |
| 363 | if tmin >= cmin && tmax <= cmax { |
| 364 | return false |
| 365 | } |
| 366 | h := fr.Styles.Font.Size.Dots |
| 367 | if tmin < cmin { // favors scrolling to start |
| 368 | trg := sb.Value + tmin - cmin - h |
| 369 | if trg < 0 { |
| 370 | trg = 0 |
| 371 | } |
| 372 | sb.setValueEvent(trg) |
| 373 | return true |
| 374 | } else { |
| 375 | if (tmax - tmin) < sb.scrollThumbValue() { // only if whole thing fits |
| 376 | trg := sb.Value + float32(tmax-cmax) + h |
| 377 | sb.setValueEvent(trg) |
| 378 | return true |
| 379 | } |
| 380 | } |
| 381 | return false |
| 382 | } |
| 383 | |
| 384 | // ScrollToBox scrolls the layout to ensure that given rect box is in view. |
| 385 | // Returns true if scrolling was needed |
no test coverage detected