@ -916,10 +916,10 @@ void ImGui::Scrollbar(ImGuiAxis axis)
if ( ! window - > ScrollbarX )
if ( ! window - > ScrollbarX )
rounding_corners | = ImDrawFlags_RoundCornersBottomRight ;
rounding_corners | = ImDrawFlags_RoundCornersBottomRight ;
}
}
float size_a va il = window - > InnerRect . Max [ axis ] - window - > InnerRect . Min [ axis ] ;
float size_visib le = window - > InnerRect . Max [ axis ] - window - > InnerRect . Min [ axis ] ;
float size_contents = window - > ContentSize [ axis ] + window - > WindowPadding [ axis ] * 2.0f ;
float size_contents = window - > ContentSize [ axis ] + window - > WindowPadding [ axis ] * 2.0f ;
ImS64 scroll = ( ImS64 ) window - > Scroll [ axis ] ;
ImS64 scroll = ( ImS64 ) window - > Scroll [ axis ] ;
ScrollbarEx ( bb , id , axis , & scroll , ( ImS64 ) size_a va il , ( ImS64 ) size_contents , rounding_corners ) ;
ScrollbarEx ( bb , id , axis , & scroll , ( ImS64 ) size_visib le , ( ImS64 ) size_contents , rounding_corners ) ;
window - > Scroll [ axis ] = ( float ) scroll ;
window - > Scroll [ axis ] = ( float ) scroll ;
}
}
@ -929,7 +929,7 @@ void ImGui::Scrollbar(ImGuiAxis axis)
// - We store values as normalized ratio and in a form that allows the window content to change while we are holding on a scrollbar
// - We store values as normalized ratio and in a form that allows the window content to change while we are holding on a scrollbar
// - We handle both horizontal and vertical scrollbars, which makes the terminology not ideal.
// - We handle both horizontal and vertical scrollbars, which makes the terminology not ideal.
// Still, the code should probably be made simpler..
// Still, the code should probably be made simpler..
bool ImGui : : ScrollbarEx ( const ImRect & bb_frame , ImGuiID id , ImGuiAxis axis , ImS64 * p_scroll_v , ImS64 size_a va il_v , ImS64 size_contents_v , ImDrawFlags flags )
bool ImGui : : ScrollbarEx ( const ImRect & bb_frame , ImGuiID id , ImGuiAxis axis , ImS64 * p_scroll_v , ImS64 size_visib le _v , ImS64 size_contents_v , ImDrawFlags flags )
{
{
ImGuiContext & g = * GImGui ;
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
ImGuiWindow * window = g . CurrentWindow ;
@ -959,9 +959,9 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
// Calculate the height of our grabbable box. It generally represent the amount visible (vs the total scrollable amount)
// Calculate the height of our grabbable box. It generally represent the amount visible (vs the total scrollable amount)
// But we maintain a minimum size in pixel to allow for the user to still aim inside.
// But we maintain a minimum size in pixel to allow for the user to still aim inside.
IM_ASSERT ( ImMax ( size_contents_v , size_a va il_v ) > 0.0f ) ; // Adding this assert to check if the ImMax(XXX,1.0f) is still needed. PLEASE CONTACT ME if this triggers.
IM_ASSERT ( ImMax ( size_contents_v , size_visib le _v ) > 0.0f ) ; // Adding this assert to check if the ImMax(XXX,1.0f) is still needed. PLEASE CONTACT ME if this triggers.
const ImS64 win_size_v = ImMax ( ImMax ( size_contents_v , size_a va il_v ) , ( ImS64 ) 1 ) ;
const ImS64 win_size_v = ImMax ( ImMax ( size_contents_v , size_visib le _v ) , ( ImS64 ) 1 ) ;
const float grab_h_pixels = ImClamp ( scrollbar_size_v * ( ( float ) size_a va il_v / ( float ) win_size_v ) , style . GrabMinSize , scrollbar_size_v ) ;
const float grab_h_pixels = ImClamp ( scrollbar_size_v * ( ( float ) size_visib le _v / ( float ) win_size_v ) , style . GrabMinSize , scrollbar_size_v ) ;
const float grab_h_norm = grab_h_pixels / scrollbar_size_v ;
const float grab_h_norm = grab_h_pixels / scrollbar_size_v ;
// Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
// Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
@ -970,7 +970,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
ItemAdd ( bb_frame , id , NULL , ImGuiItemFlags_NoNav ) ;
ItemAdd ( bb_frame , id , NULL , ImGuiItemFlags_NoNav ) ;
ButtonBehavior ( bb , id , & hovered , & held , ImGuiButtonFlags_NoNavFocus ) ;
ButtonBehavior ( bb , id , & hovered , & held , ImGuiButtonFlags_NoNavFocus ) ;
const ImS64 scroll_max = ImMax ( ( ImS64 ) 1 , size_contents_v - size_a va il_v ) ;
const ImS64 scroll_max = ImMax ( ( ImS64 ) 1 , size_contents_v - size_visib le _v ) ;
float scroll_ratio = ImSaturate ( ( float ) * p_scroll_v / ( float ) scroll_max ) ;
float scroll_ratio = ImSaturate ( ( float ) * p_scroll_v / ( float ) scroll_max ) ;
float grab_v_norm = scroll_ratio * ( scrollbar_size_v - grab_h_pixels ) / scrollbar_size_v ; // Grab position in normalized space
float grab_v_norm = scroll_ratio * ( scrollbar_size_v - grab_h_pixels ) / scrollbar_size_v ; // Grab position in normalized space
if ( held & & allow_interaction & & grab_h_norm < 1.0f )
if ( held & & allow_interaction & & grab_h_norm < 1.0f )
@ -981,29 +981,39 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
// Click position in scrollbar normalized space (0.0f->1.0f)
// Click position in scrollbar normalized space (0.0f->1.0f)
const float clicked_v_norm = ImSaturate ( ( mouse_pos_v - scrollbar_pos_v ) / scrollbar_size_v ) ;
const float clicked_v_norm = ImSaturate ( ( mouse_pos_v - scrollbar_pos_v ) / scrollbar_size_v ) ;
bool seek_absolute = false ;
const int held_dir = ( clicked_v_norm < grab_v_norm ) ? - 1 : ( clicked_v_norm > grab_v_norm + grab_h_norm ) ? + 1 : 0 ;
if ( g . ActiveIdIsJustActivated )
if ( g . ActiveIdIsJustActivated )
{
{
// On initial click calculate the distance between mouse and the center of the grab
// On initial click calculate the distance between mouse and the center of the grab
seek_absolute = ( clicked_v_norm < grab_v_norm | | clicked_v_norm > grab_v_norm + grab_h_norm ) ;
g . ScrollbarSeekMode = ( short ) held_dir ;
if ( seek_absolute )
g . ScrollbarClickDeltaToGrabCenter = ( g . ScrollbarSeekMode = = 0.0f ) ? clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f : 0.0f ;
g . ScrollbarClickDeltaToGrabCenter = 0.0f ;
else
g . ScrollbarClickDeltaToGrabCenter = clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f ;
}
}
// Apply scroll (p_scroll_v will generally point on one member of window->Scroll)
// Apply scroll (p_scroll_v will generally point on one member of window->Scroll)
// It is ok to modify Scroll here because we are being called in Begin() after the calculation of ContentSize and before setting up our starting position
// It is ok to modify Scroll here because we are being called in Begin() after the calculation of ContentSize and before setting up our starting position
if ( g . ScrollbarSeekMode = = 0 )
{
// Absolute seeking
const float scroll_v_norm = ImSaturate ( ( clicked_v_norm - g . ScrollbarClickDeltaToGrabCenter - grab_h_norm * 0.5f ) / ( 1.0f - grab_h_norm ) ) ;
const float scroll_v_norm = ImSaturate ( ( clicked_v_norm - g . ScrollbarClickDeltaToGrabCenter - grab_h_norm * 0.5f ) / ( 1.0f - grab_h_norm ) ) ;
* p_scroll_v = ( ImS64 ) ( scroll_v_norm * scroll_max ) ;
* p_scroll_v = ( ImS64 ) ( scroll_v_norm * scroll_max ) ;
}
else
{
// Page by page
if ( IsMouseClicked ( ImGuiMouseButton_Left , ImGuiInputFlags_Repeat ) & & held_dir = = g . ScrollbarSeekMode )
{
float page_dir = ( g . ScrollbarSeekMode > 0.0f ) ? + 1.0f : - 1.0f ;
* p_scroll_v = ImClamp ( * p_scroll_v + ( ImS64 ) ( page_dir * size_visible_v ) , ( ImS64 ) 0 , scroll_max ) ;
}
}
// Update values for rendering
// Update values for rendering
scroll_ratio = ImSaturate ( ( float ) * p_scroll_v / ( float ) scroll_max ) ;
scroll_ratio = ImSaturate ( ( float ) * p_scroll_v / ( float ) scroll_max ) ;
grab_v_norm = scroll_ratio * ( scrollbar_size_v - grab_h_pixels ) / scrollbar_size_v ;
grab_v_norm = scroll_ratio * ( scrollbar_size_v - grab_h_pixels ) / scrollbar_size_v ;
// Update distance to grab now that we have seek'ed and saturated
// Update distance to grab now that we have seek'ed and saturated
if ( seek_absolute )
//if (seek_absolute)
g . ScrollbarClickDeltaToGrabCenter = clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f ;
// g.ScrollbarClickDeltaToGrabCenter = clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f;
}
}
// Render
// Render