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

GH-76 Add scroll to item signal #81

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/editor/script_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ OrchestratorScriptViewSection::OrchestratorScriptViewSection(const String& p_sec
_section_name = p_section_name;
}

void OrchestratorScriptViewSection::_bind_methods()
{
ADD_SIGNAL(MethodInfo("scroll_to_item", PropertyInfo(Variant::OBJECT, "item")));
}

void OrchestratorScriptViewSection::_notification(int p_what)
{
if (p_what == NOTIFICATION_READY)
Expand Down Expand Up @@ -233,8 +238,8 @@ bool OrchestratorScriptViewSection::_find_child_and_activate(const String& p_nam
{
if (child->get_text(0).match(p_name))
{
emit_signal("scroll_to_item", child);
_tree->call_deferred("set_selected", child, 0);
_handle_item_activated(child);

if (p_edit)
{
Expand Down Expand Up @@ -1277,6 +1282,7 @@ void OrchestratorScriptView::_notification(int p_what)
_graphs->connect("close_graph_requested", callable_mp(this, &OrchestratorScriptView::_on_close_graph));
_graphs->connect("focus_node_requested", callable_mp(this, &OrchestratorScriptView::_on_focus_node));
_graphs->connect("graph_renamed", callable_mp(this, &OrchestratorScriptView::_on_graph_renamed));
_graphs->connect("scroll_to_item", callable_mp(this, &OrchestratorScriptView::_on_scroll_to_item));
vbox->add_child(_graphs);

_functions = memnew(OrchestratorScriptViewFunctionsSection(_script));
Expand All @@ -1285,15 +1291,19 @@ void OrchestratorScriptView::_notification(int p_what)
_functions->connect("focus_node_requested", callable_mp(this, &OrchestratorScriptView::_on_focus_node));
_functions->connect("override_function_requested", callable_mp(this, &OrchestratorScriptView::_on_override_function));
_functions->connect("graph_renamed", callable_mp(this, &OrchestratorScriptView::_on_graph_renamed));
_functions->connect("scroll_to_item", callable_mp(this, &OrchestratorScriptView::_on_scroll_to_item));
vbox->add_child(_functions);

_macros = memnew(OrchestratorScriptViewMacrosSection(_script));
_macros->connect("scroll_to_item", callable_mp(this, &OrchestratorScriptView::_on_scroll_to_item));
vbox->add_child(_macros);

_variables = memnew(OrchestratorScriptViewVariablesSection(_script));
_variables->connect("scroll_to_item", callable_mp(this, &OrchestratorScriptView::_on_scroll_to_item));
vbox->add_child(_variables);

_signals = memnew(OrchestratorScriptViewSignalsSection(_script));
_signals->connect("scroll_to_item", callable_mp(this, &OrchestratorScriptView::_on_scroll_to_item));
vbox->add_child(_signals);

// The base event graph tab
Expand Down Expand Up @@ -1522,6 +1532,22 @@ void OrchestratorScriptView::_on_toggle_component_panel(bool p_visible)
_scroll_container->set_visible(p_visible);
}

void OrchestratorScriptView::_on_scroll_to_item(TreeItem* p_item)
{
if (p_item && _scroll_container)
{
Tree* tree = p_item->get_tree();

const Rect2 item_rect = tree->get_item_area_rect(p_item);
const Rect2 tree_rect = tree->get_global_rect();
const Rect2 view_rect = _scroll_container->get_rect();

const float offset = tree_rect.get_position().y + item_rect.get_position().y;
if (offset > view_rect.get_size().y)
_scroll_container->set_v_scroll(offset);
}
}

void OrchestratorScriptView::_add_callback(Object* p_object, const String& p_function_name, const PackedStringArray& p_args)
{
// Get the script attached to the object
Expand Down
7 changes: 6 additions & 1 deletion src/editor/script_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <godot_cpp/classes/input_event.hpp>
#include <godot_cpp/classes/panel_container.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/scroll_container.hpp>
#include <godot_cpp/classes/tab_container.hpp>
#include <godot_cpp/classes/tree.hpp>
#include <godot_cpp/classes/v_box_container.hpp>
Expand Down Expand Up @@ -56,7 +57,7 @@ class OrchestratorScriptViewSection : public VBoxContainer
bool _expanded{ true }; //! Whether the section is currently expanded
bool _theme_changing{ false }; //! Whether the theme is being changed

static void _bind_methods() {}
static void _bind_methods();

/// Clears the tree of all items but the root.
void _clear_tree();
Expand Down Expand Up @@ -558,6 +559,10 @@ class OrchestratorScriptView : public HSplitContainer
/// @param p_visible whether the panel is visible
void _on_toggle_component_panel(bool p_visible);

/// Dispatched when requested to scroll to the specified item
/// @param p_item the tree item to scroll to
void _on_scroll_to_item(TreeItem* p_item);

/// Dispatched when a user creates a signal connection via the Editor UI
/// @param p_object the object to whom is being connected
/// @param p_function_name the signal function to create
Expand Down
Loading