Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scrollbar offset logic in HourlyDetails widget #115

Merged
merged 1 commit into from
May 8, 2024

Conversation

georgescutelnicu
Copy link
Contributor

This pull request adds functionality to the HourlyDetails widget in order to properly handle scrollbar positioning based on the nearest current time index.

get_preferred_size() returns a tuple containing the minimum and the natural size of the widget (width and height), so i accessed directly the natural size and retrieved the width:
container_size = graphic_container.get_preferred_size()[1]
container_width = container_size.width

Then i calculate the offset based on the container width and the nearest current time index. It substracts 2 to leave the last 2 cards before the current time visible:
scrollbar_offset = (container_width / 24) * (nearest_current_time_idx - 2)

In the end i created Gtk adjustment for the horizontal scrollbar, setting its value to the calculated scrollbar offset and ensuring it remains within the bounds of 0 and the width of the container:
h_adjustment = Gtk.Adjustment(value=scrollbar_offset, lower=0, upper=container_width)
scrolled_window.set_hadjustment(h_adjustment)

Note: In case nearest_current_time_idx will be 0 or 1, the scrollbar_offset will have a negative value which means the scrollbar will be positioned at the extreme left, so we don't have to handle this case separately. Also the code is positioned at the end of the file because it relies on the initialization of UI elements which occur just before.

@amit9838
Copy link
Owner

amit9838 commented May 8, 2024

very descriptive pr 🙂 , thanks for your contribution @georgescutelnicu

Copy link
Owner

@amit9838 amit9838 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@amit9838 amit9838 merged commit cabf166 into amit9838:master May 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants