MCPcopy Create free account
hub / github.com/davisking/dlib / scroll_to_rect

Method scroll_to_rect

dlib/gui_widgets/base_widgets.cpp:2918–2960  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2916// ----------------------------------------------------------------------------------------
2917
2918 void scrollable_region::
2919 scroll_to_rect (
2920 const rectangle& r_
2921 )
2922 {
2923 const rectangle r(total_rect_.intersect(r_));
2924 const rectangle old(total_rect_);
2925 // adjust the horizontal scroll bar so that r fits as best as possible
2926 if (r.left() < display_rect_.left())
2927 {
2928 long distance = (r.left()-total_rect_.left())/hscroll_bar_inc;
2929 hsb.set_slider_pos(distance);
2930 }
2931 else if (r.right() > display_rect_.right())
2932 {
2933 long distance = (r.right()-total_rect_.left()-display_rect_.width()+hscroll_bar_inc)/hscroll_bar_inc;
2934 hsb.set_slider_pos(distance);
2935 }
2936
2937 // adjust the vertical scroll bar so that r fits as best as possible
2938 if (r.top() < display_rect_.top())
2939 {
2940 long distance = (r.top()-total_rect_.top())/vscroll_bar_inc;
2941 vsb.set_slider_pos(distance);
2942 }
2943 else if (r.bottom() > display_rect_.bottom())
2944 {
2945 long distance = (r.bottom()-total_rect_.top()-display_rect_.height()+vscroll_bar_inc)/vscroll_bar_inc;
2946 vsb.set_slider_pos(distance);
2947 }
2948
2949
2950 // adjust total_rect_ so that it matches where the scroll bars are now
2951 total_rect_ = move_rect(total_rect_,
2952 display_rect_.left()-hscroll_bar_inc*hsb.slider_pos(),
2953 display_rect_.top()-vscroll_bar_inc*vsb.slider_pos());
2954
2955 // only redraw if we actually changed something
2956 if (total_rect_ != old)
2957 {
2958 parent.invalidate_rectangle(display_rect_);
2959 }
2960 }
2961
2962// ----------------------------------------------------------------------------------------
2963

Callers

nothing calls this directly

Calls 8

move_rectFunction · 0.85
intersectMethod · 0.45
leftMethod · 0.45
rightMethod · 0.45
widthMethod · 0.45
topMethod · 0.45
bottomMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected