Well you first can calculate the percentage of mouse.x across the screen with:
percent = mouse.x / screen.width
When percent= 0 you want bar.x = 0
and when percent = 1 you want bar.x = screen.width - bar.width
This is assuming there is no scrolling going on and the origin of the bar object is on the left.
You then can use lerp to set it up:
bar.x = lerp(0, screen.width - bar.width, mouse.x / screen.width)
You may also want to clamp the percent value so it stays in the range of 0 to 1 like so:
bar.x = lerp(0, screen.width - bar.width, clamp(mouse.x / screen.width, 0, 1))