Skip to content

Commit f60f69a

Browse files
committed
Merge pull request #102024 from arkology/profiler-flow-container
Use `FlowContainer` for `Profiler` and `Visual Profiler` bars
2 parents dfedfe7 + 03bfb46 commit f60f69a

File tree

2 files changed

+57
-26
lines changed

2 files changed

+57
-26
lines changed

editor/debugger/editor_profiler.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "editor/gui/editor_run_bar.h"
3737
#include "editor/themes/editor_scale.h"
3838
#include "scene/gui/check_box.h"
39+
#include "scene/gui/flow_container.h"
3940
#include "scene/resources/image_texture.h"
4041

4142
void EditorProfiler::_make_metric_ptrs(Metric &m) {
@@ -658,27 +659,39 @@ Vector<Vector<String>> EditorProfiler::get_data_as_csv() const {
658659

659660
EditorProfiler::EditorProfiler() {
660661
HBoxContainer *hb = memnew(HBoxContainer);
662+
hb->add_theme_constant_override(SNAME("separation"), 8 * EDSCALE);
661663
add_child(hb);
664+
665+
FlowContainer *container = memnew(FlowContainer);
666+
container->set_h_size_flags(SIZE_EXPAND_FILL);
667+
container->add_theme_constant_override(SNAME("h_separation"), 8 * EDSCALE);
668+
container->add_theme_constant_override(SNAME("v_separation"), 2 * EDSCALE);
669+
hb->add_child(container);
670+
662671
activate = memnew(Button);
663672
activate->set_toggle_mode(true);
664673
activate->set_disabled(true);
665674
activate->set_text(TTR("Start"));
666675
activate->connect(SceneStringName(pressed), callable_mp(this, &EditorProfiler::_activate_pressed));
667-
hb->add_child(activate);
676+
container->add_child(activate);
668677

669678
clear_button = memnew(Button);
670679
clear_button->set_text(TTR("Clear"));
671680
clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorProfiler::_clear_pressed));
672681
clear_button->set_disabled(true);
673-
hb->add_child(clear_button);
682+
container->add_child(clear_button);
674683

675684
CheckBox *autostart_checkbox = memnew(CheckBox);
676685
autostart_checkbox->set_text(TTR("Autostart"));
677686
autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false));
678687
autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorProfiler::_autostart_toggled));
679-
hb->add_child(autostart_checkbox);
688+
container->add_child(autostart_checkbox);
689+
690+
HBoxContainer *hb_measure = memnew(HBoxContainer);
691+
hb_measure->add_theme_constant_override(SNAME("separation"), 2 * EDSCALE);
692+
container->add_child(hb_measure);
680693

681-
hb->add_child(memnew(Label(TTR("Measure:"))));
694+
hb_measure->add_child(memnew(Label(TTR("Measure:"))));
682695

683696
display_mode = memnew(OptionButton);
684697
display_mode->add_item(TTR("Frame Time (ms)"));
@@ -687,9 +700,13 @@ EditorProfiler::EditorProfiler() {
687700
display_mode->add_item(TTR("Physics Frame %"));
688701
display_mode->connect(SceneStringName(item_selected), callable_mp(this, &EditorProfiler::_combo_changed));
689702

690-
hb->add_child(display_mode);
703+
hb_measure->add_child(display_mode);
691704

692-
hb->add_child(memnew(Label(TTR("Time:"))));
705+
HBoxContainer *hb_time = memnew(HBoxContainer);
706+
hb_time->add_theme_constant_override(SNAME("separation"), 2 * EDSCALE);
707+
container->add_child(hb_time);
708+
709+
hb_time->add_child(memnew(Label(TTR("Time:"))));
693710

694711
display_time = memnew(OptionButton);
695712
// TRANSLATORS: This is an option in the profiler to display the time spent in a function, including the time spent in other functions called by that function.
@@ -698,28 +715,28 @@ EditorProfiler::EditorProfiler() {
698715
display_time->add_item(TTR("Self"));
699716
display_time->set_tooltip_text(TTR("Inclusive: Includes time from other functions called by this function.\nUse this to spot bottlenecks.\n\nSelf: Only count the time spent in the function itself, not in other functions called by that function.\nUse this to find individual functions to optimize."));
700717
display_time->connect(SceneStringName(item_selected), callable_mp(this, &EditorProfiler::_combo_changed));
701-
702-
hb->add_child(display_time);
718+
hb_time->add_child(display_time);
703719

704720
display_internal_profiles = memnew(CheckButton(TTR("Display internal functions")));
705721
display_internal_profiles->set_visible(EDITOR_GET("debugger/profile_native_calls"));
706722
display_internal_profiles->set_pressed(false);
707723
display_internal_profiles->connect(SceneStringName(pressed), callable_mp(this, &EditorProfiler::_internal_profiles_pressed));
708-
hb->add_child(display_internal_profiles);
724+
container->add_child(display_internal_profiles);
709725

710-
hb->add_spacer();
726+
HBoxContainer *hb_frame = memnew(HBoxContainer);
727+
hb_frame->add_theme_constant_override(SNAME("separation"), 2 * EDSCALE);
728+
hb_frame->set_v_size_flags(SIZE_SHRINK_BEGIN);
729+
hb->add_child(hb_frame);
711730

712-
hb->add_child(memnew(Label(TTR("Frame #:"))));
731+
hb_frame->add_child(memnew(Label(TTR("Frame #:"))));
713732

714733
cursor_metric_edit = memnew(SpinBox);
715734
cursor_metric_edit->set_h_size_flags(SIZE_FILL);
716735
cursor_metric_edit->set_value(0);
717736
cursor_metric_edit->set_editable(false);
718-
hb->add_child(cursor_metric_edit);
737+
hb_frame->add_child(cursor_metric_edit);
719738
cursor_metric_edit->connect(SceneStringName(value_changed), callable_mp(this, &EditorProfiler::_cursor_metric_changed));
720739

721-
hb->add_theme_constant_override("separation", 8 * EDSCALE);
722-
723740
h_split = memnew(HSplitContainer);
724741
add_child(h_split);
725742
h_split->set_v_size_flags(SIZE_EXPAND_FILL);

editor/debugger/editor_visual_profiler.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "editor/editor_string_names.h"
3636
#include "editor/gui/editor_run_bar.h"
3737
#include "editor/themes/editor_scale.h"
38+
#include "scene/gui/flow_container.h"
3839
#include "scene/resources/image_texture.h"
3940

4041
void EditorVisualProfiler::set_hardware_info(const String &p_cpu_name, const String &p_gpu_name) {
@@ -742,55 +743,68 @@ Vector<Vector<String>> EditorVisualProfiler::get_data_as_csv() const {
742743

743744
EditorVisualProfiler::EditorVisualProfiler() {
744745
HBoxContainer *hb = memnew(HBoxContainer);
746+
hb->add_theme_constant_override(SNAME("separation"), 8 * EDSCALE);
745747
add_child(hb);
748+
749+
FlowContainer *container = memnew(FlowContainer);
750+
container->set_h_size_flags(SIZE_EXPAND_FILL);
751+
container->add_theme_constant_override(SNAME("h_separation"), 8 * EDSCALE);
752+
container->add_theme_constant_override(SNAME("v_separation"), 2 * EDSCALE);
753+
hb->add_child(container);
754+
746755
activate = memnew(Button);
747756
activate->set_toggle_mode(true);
748757
activate->set_disabled(true);
749758
activate->set_text(TTR("Start"));
750759
activate->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_activate_pressed));
751-
hb->add_child(activate);
760+
container->add_child(activate);
752761

753762
clear_button = memnew(Button);
754763
clear_button->set_text(TTR("Clear"));
755764
clear_button->set_disabled(true);
756765
clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_clear_pressed));
757-
hb->add_child(clear_button);
766+
container->add_child(clear_button);
758767

759768
CheckBox *autostart_checkbox = memnew(CheckBox);
760769
autostart_checkbox->set_text(TTR("Autostart"));
761770
autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false));
762771
autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorVisualProfiler::_autostart_toggled));
763-
hb->add_child(autostart_checkbox);
772+
container->add_child(autostart_checkbox);
764773

765-
hb->add_child(memnew(Label(TTR("Measure:"))));
774+
HBoxContainer *hb_measure = memnew(HBoxContainer);
775+
hb_measure->add_theme_constant_override(SNAME("separation"), 2 * EDSCALE);
776+
container->add_child(hb_measure);
777+
778+
hb_measure->add_child(memnew(Label(TTR("Measure:"))));
766779

767780
display_mode = memnew(OptionButton);
768781
display_mode->add_item(TTR("Frame Time (ms)"));
769782
display_mode->add_item(TTR("Frame %"));
770783
display_mode->connect(SceneStringName(item_selected), callable_mp(this, &EditorVisualProfiler::_combo_changed));
771784

772-
hb->add_child(display_mode);
785+
hb_measure->add_child(display_mode);
773786

774787
frame_relative = memnew(CheckBox(TTR("Fit to Frame")));
775788
frame_relative->set_pressed(true);
776-
hb->add_child(frame_relative);
789+
container->add_child(frame_relative);
777790
frame_relative->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_update_plot));
778791
linked = memnew(CheckBox(TTR("Linked")));
779792
linked->set_pressed(true);
780-
hb->add_child(linked);
793+
container->add_child(linked);
781794
linked->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_update_plot));
782795

783-
hb->add_spacer();
796+
HBoxContainer *hb_frame = memnew(HBoxContainer);
797+
hb_frame->add_theme_constant_override(SNAME("separation"), 2 * EDSCALE);
798+
hb_frame->set_v_size_flags(SIZE_SHRINK_BEGIN);
799+
hb->add_child(hb_frame);
784800

785-
hb->add_child(memnew(Label(TTR("Frame #:"))));
801+
hb_frame->add_child(memnew(Label(TTR("Frame #:"))));
786802

787803
cursor_metric_edit = memnew(SpinBox);
788804
cursor_metric_edit->set_h_size_flags(SIZE_FILL);
789-
hb->add_child(cursor_metric_edit);
805+
hb_frame->add_child(cursor_metric_edit);
790806
cursor_metric_edit->connect(SceneStringName(value_changed), callable_mp(this, &EditorVisualProfiler::_cursor_metric_changed));
791807

792-
hb->add_theme_constant_override("separation", 8 * EDSCALE);
793-
794808
h_split = memnew(HSplitContainer);
795809
add_child(h_split);
796810
h_split->set_v_size_flags(SIZE_EXPAND_FILL);

0 commit comments

Comments
 (0)