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

Handle scroll events in RichtTextLabel #97730

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Oct 2, 2024

Allows scrolling RichTextLabel inside ScrollContainer.

Before:

godot_23r9S1xFxA.mp4

After:

godot.windows.editor.dev.x86_64_RdaT5zqTkq.mp4

The code is adapted from ScrollContainer.

if (mb->get_button_index() == MouseButton::WHEEL_UP) {
// By default, the vertical orientation takes precedence. This is an exception.
if ((h_scroll_enabled && mb->is_shift_pressed()) || v_scroll_hidden) {
h_scroll->scroll(-h_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
} else if (v_scroll_enabled) {
v_scroll->scroll(-v_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
}
}
if (mb->get_button_index() == MouseButton::WHEEL_DOWN) {
if ((h_scroll_enabled && mb->is_shift_pressed()) || v_scroll_hidden) {
h_scroll->scroll(h_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
} else if (v_scroll_enabled) {
v_scroll->scroll(v_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
}
}
bool h_scroll_hidden = !h_scroll->is_visible() && horizontal_scroll_mode != SCROLL_MODE_SHOW_NEVER;
if (mb->get_button_index() == MouseButton::WHEEL_LEFT) {
// By default, the horizontal orientation takes precedence. This is an exception.
if ((v_scroll_enabled && mb->is_shift_pressed()) || h_scroll_hidden) {
v_scroll->scroll(-v_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
} else if (h_scroll_enabled) {
h_scroll->scroll(-h_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
}
}
if (mb->get_button_index() == MouseButton::WHEEL_RIGHT) {
if ((v_scroll_enabled && mb->is_shift_pressed()) || h_scroll_hidden) {
v_scroll->scroll(v_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
} else if (h_scroll_enabled) {
h_scroll->scroll(h_scroll->get_page() / 8 * mb->get_factor());
scroll_value_modified = true;
}
}
if (scroll_value_modified && (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)) {
accept_event(); // Accept event if scroll changed.
return;
}

@KoBeWi KoBeWi added this to the 4.4 milestone Oct 2, 2024
@KoBeWi KoBeWi requested a review from a team as a code owner October 2, 2024 13:49
@akien-mga akien-mga merged commit ae7fd80 into godotengine:master Oct 3, 2024
19 checks passed
@akien-mga
Copy link
Member

Thanks!

@KoBeWi KoBeWi deleted the rich_text_label_inside_a_scroll_container_inside_a_bag_of_milk branch October 3, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants