Skip to main content
added 134 characters in body
Source Link
RickS.
  • 51
  • 1
  • 6

Could someone please provide a direct answer with the math to calculate the scrollbar Value, Minimum and Maximum properties?

Thanks in advance!

Thanks in advance!

Could someone please provide a direct answer with the math to calculate the scrollbar Value, Minimum and Maximum properties?

Thanks in advance!

edited tags
Link
RickS.
  • 51
  • 1
  • 6
added 22 characters in body
Source Link
RickS.
  • 51
  • 1
  • 6
public int Minimum  { get; set; }
public int Maximum  { get; set; }

public int Value    { get; set; }

public void Update()
{
    // Calculate the Scrollbar Thumb height:
    var viewable_ratio = ViewportHeight / ContentHeight;
    var scrollbar_area = ViewportHeight - ( ArrowHeight * 2 );
    
    this.ThumbHeight = scrollbar_area * viewable_ratio;
    
    // Calculate the Scrollbar Thumb step:
    var track_space = ContentHeight  - ViewportHeight;
    var thumb_space = ViewportHeight - ThumbHeight;
    
    this.ThumbStep = track_space / thumb_space;
    
    // TODO: Calculate the "Minimum" and "Maximum" values.
    this.Minimum = ???
    this.Maximum = ???
    
    Point mouse = Input.MousePosition();
    
    if(Thumb.Rectangle.Contains(mouse) && Input.MouseDown(0))
    {
        int x = Thumb.Position.x;
        int y = ( mouse.y - Thumb.Position.y );
        
        Thumb.Position = new Point(x, y);
        
        if(Thumb.Position.y < Minimum) Thumb.Position.y = Minimum;
        if(Thumb.Position.y > Maximum) Thumb.Position.y = Maximum;
        
        // TODO: Set the "Value" property to the correct value when the Thumb is moved.
        this.Value = ???
        this.Content.Position.y = this.Value;
    }
}
public int Minimum  { get; set; }
public int Maximum  { get; set; }

public int Value    { get; set; }

public void Update()
{
    // Calculate the Scrollbar Thumb height:
    var viewable_ratio = ViewportHeight / ContentHeight;
    var scrollbar_area = ViewportHeight - ( ArrowHeight * 2 );
    
    this.ThumbHeight = scrollbar_area * viewable_ratio;
    
    // Calculate the Scrollbar Thumb step:
    var track_space = ContentHeight  - ViewportHeight;
    var thumb_space = ViewportHeight - ThumbHeight;
    
    this.ThumbStep = track_space / thumb_space;
    
    // TODO: Calculate the "Minimum" and "Maximum" values.
    this.Minimum = ???
    this.Maximum = ???
    
    Point mouse = Input.MousePosition();
    
    if(Thumb.Rectangle.Contains(mouse))
    {
        int x = Thumb.Position.x;
        int y = ( mouse.y - Thumb.Position.y );
        
        Thumb.Position = new Point(x, y);
        
        if(Thumb.Position.y < Minimum) Thumb.Position.y = Minimum;
        if(Thumb.Position.y > Maximum) Thumb.Position.y = Maximum;
        
        // TODO: Set the "Value" property to the correct value when the Thumb is moved.
        this.Value = ???
    }
}
public int Minimum  { get; set; }
public int Maximum  { get; set; }

public int Value    { get; set; }

public void Update()
{
    // Calculate the Scrollbar Thumb height:
    var viewable_ratio = ViewportHeight / ContentHeight;
    var scrollbar_area = ViewportHeight - ( ArrowHeight * 2 );
    
    this.ThumbHeight = scrollbar_area * viewable_ratio;
    
    // Calculate the Scrollbar Thumb step:
    var track_space = ContentHeight  - ViewportHeight;
    var thumb_space = ViewportHeight - ThumbHeight;
    
    this.ThumbStep = track_space / thumb_space;
    
    // TODO: Calculate the "Minimum" and "Maximum" values.
    this.Minimum = ???
    this.Maximum = ???
    
    Point mouse = Input.MousePosition();
    
    if(Thumb.Rectangle.Contains(mouse) && Input.MouseDown(0))
    {
        int x = Thumb.Position.x;
        int y = ( mouse.y - Thumb.Position.y );
        
        Thumb.Position = new Point(x, y);
        
        if(Thumb.Position.y < Minimum) Thumb.Position.y = Minimum;
        if(Thumb.Position.y > Maximum) Thumb.Position.y = Maximum;
        
        // TODO: Set the "Value" property to the correct value when the Thumb is moved.
        this.Value = ???
        this.Content.Position.y = this.Value;
    }
}
added 52 characters in body
Source Link
RickS.
  • 51
  • 1
  • 6
Loading
edited body
Source Link
RickS.
  • 51
  • 1
  • 6
Loading
edited tags; edited title
Link
RickS.
  • 51
  • 1
  • 6
Loading
Source Link
RickS.
  • 51
  • 1
  • 6
Loading