MCPcopy
hub / github.com/g3n/engine / updateScrollbarsVisibility

Method updateScrollbarsVisibility

gui/scroller.go:346–407  ·  view source on GitHub ↗

updateScrollbarsVisibility updates the visibility of the scrollbars and corner panel, creating them if necessary. This method should be called when either the target panel changes size or when either the scroll mode or style of the Scroller changes.

()

Source from the content-addressed store, hash-verified

344// This method should be called when either the target panel changes size or when either the scroll mode or
345// style of the Scroller changes.
346func (s *Scroller) updateScrollbarsVisibility() {
347
348 // Obtain the size of the target panel
349 targetWidth := s.target.Width()
350 targetHeight := s.target.Height()
351
352 // If vertical scrolling is enabled and the vertical scrollbar should be visible
353 if (s.mode&ScrollVertical > 0) && (targetHeight > s.content.Height) {
354 s.setVerticalScrollbarVisible()
355 } else if s.vscroll != nil {
356 s.vscroll.SetVisible(false)
357 s.vscroll.SetValue(0)
358 }
359
360 // If horizontal scrolling is enabled and the horizontal scrollbar should be visible
361 if (s.mode&ScrollHorizontal > 0) && (targetWidth > s.content.Width) {
362 s.setHorizontalScrollbarVisible()
363 } else if s.hscroll != nil {
364 s.hscroll.SetVisible(false)
365 s.hscroll.SetValue(0)
366 }
367
368 // If both scrollbars can be visible we need to check whether we should show the corner panel and also whether
369 // any scrollbar's presence caused the other to be required. The latter is a literal and figurative edge case
370 // that happens when the target panel is larger than the content in one dimension but smaller than the content
371 // in the other, and in the dimension that it is smaller than the content, the difference is less than the width
372 // of the scrollbar. In that case we need to show both scrollbars to allow viewing of the complete target panel.
373 if s.mode == ScrollBoth {
374
375 vScrollVisible := (s.vscroll != nil) && s.vscroll.Visible()
376 hScrollVisible := (s.hscroll != nil) && s.hscroll.Visible()
377
378 // Check if adding any of the scrollbars ended up covering an edge of the target. If that's the case,
379 // then show the other scrollbar as well (if the covering scrollbar's style is set to non-overlapping).
380
381 // If the vertical scrollbar is visible and covering the target (and its style is not set to overlap)
382 if vScrollVisible && (targetWidth > (s.content.Width - s.vscroll.width)) && !s.style.VerticalScrollbar.OverlapContent {
383 s.setHorizontalScrollbarVisible() // Show the other scrollbar too
384 }
385 // If the horizontal scrollbar is visible and covering the target (and its style is not set to overlap)
386 if hScrollVisible && (targetHeight > (s.content.Height - s.hscroll.height)) && !s.style.HorizontalScrollbar.OverlapContent {
387 s.setVerticalScrollbarVisible() // Show the other scrollbar too
388 }
389
390 // Update visibility variables since they may have changed
391 vScrollVisible = (s.vscroll != nil) && s.vscroll.Visible()
392 hScrollVisible = (s.hscroll != nil) && s.hscroll.Visible()
393
394 // If both vertical and horizontal scrolling is enabled, and the style specifies no interlocking
395 // and a corner panel, and both scrollbars are visible - then the corner panel should be visible
396 if (s.style.ScrollbarInterlocking == ScrollbarInterlockingNone) && s.style.CornerCovered && vScrollVisible && hScrollVisible {
397 if s.corner == nil {
398 s.corner = NewPanel(s.vscroll.width, s.hscroll.height)
399 s.corner.ApplyStyle(&s.style.CornerPanel)
400 s.Add(s.corner)
401 }
402 s.corner.SetVisible(true)
403 } else if s.corner != nil {

Callers 1

UpdateMethod · 0.95

Calls 10

NewPanelFunction · 0.85
WidthMethod · 0.65
HeightMethod · 0.65
SetVisibleMethod · 0.65
VisibleMethod · 0.65
SetValueMethod · 0.45
ApplyStyleMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected