Jump to content
  • Advertisement

find column index when columns are of different widthes

Recommended Posts



let's say i have a table with columns, each are subdivided into 4 subcolumns.

i can get which subcolumn (the 1st, the 2nd, the 3rd...) is hovered by the mouse by doing :

int subcol = ((int)mouse.x / SUBCOL_WIDTH * SUBCOL_WIDTH ) % 4

however, if i have, let's say, the 4th column bigger than the 3 others. How do i modify this line of code to handle that ?

Of course i could do it with conditions, four IFs checking the mouse position. But i'm looking for an elegant solution. Any ideas ?



Edited by isbinil

Share this post

Link to post
Share on other sites

If the subcolumns are of different widths and there is no clean relationship between the widths such as 'subcolumn 4 is twice as wide as any other column' then you'd probably have to either do it with conditions or keep a list of where the columns start and end. Also would you mind explaining why the fourth subcolumn is wider than the others?

Share this post

Link to post
Share on other sites

If you use accumulated width (length of all columns upto the Nth one), you can use bisection to find the column quickly. For mouse interaction, it may not be needed though, as mouse is slow by nature.

Edited by Alberth

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!