Use a SubViewport for CanvasItem inspector preview

This commit is contained in:
Tetane 2023-04-28 20:10:04 +02:00
parent 9f12e7b52d
commit d3792a2373
2 changed files with 13 additions and 1 deletions

View file

@ -164,9 +164,19 @@ void MaterialEditor::_button_pressed(Node *p_button) {
MaterialEditor::MaterialEditor() { MaterialEditor::MaterialEditor() {
// canvas item // canvas item
vc_2d = memnew(SubViewportContainer);
vc_2d->set_stretch(true);
add_child(vc_2d);
vc_2d->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
viewport_2d = memnew(SubViewport);
vc_2d->add_child(viewport_2d);
viewport_2d->set_disable_input(true);
viewport_2d->set_transparent_background(true);
layout_2d = memnew(HBoxContainer); layout_2d = memnew(HBoxContainer);
layout_2d->set_alignment(BoxContainer::ALIGNMENT_CENTER); layout_2d->set_alignment(BoxContainer::ALIGNMENT_CENTER);
add_child(layout_2d); viewport_2d->add_child(layout_2d);
layout_2d->set_anchors_and_offsets_preset(PRESET_FULL_RECT); layout_2d->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
rect_instance = memnew(ColorRect); rect_instance = memnew(ColorRect);

View file

@ -51,6 +51,8 @@ class MaterialEditor : public Control {
Vector2 rot; Vector2 rot;
SubViewportContainer *vc_2d = nullptr;
SubViewport *viewport_2d = nullptr;
HBoxContainer *layout_2d = nullptr; HBoxContainer *layout_2d = nullptr;
ColorRect *rect_instance = nullptr; ColorRect *rect_instance = nullptr;