Skip to content

Instantly share code, notes, and snippets.

@me2beats
Created July 5, 2021 18:33
Show Gist options
  • Save me2beats/f41d368f77031acd7dcde359bd379ebc to your computer and use it in GitHub Desktop.
Save me2beats/f41d368f77031acd7dcde359bd379ebc to your computer and use it in GitHub Desktop.
Toggle expand bottom panel from plugin (hacky)
tool
extends EditorPlugin
func _enter_tree():
var base = get_editor_interface().get_base_control()
var expand_button:ToolButton = get_expand_bottom_panel_button(base)
expand_button.pressed = not expand_button.pressed
# =========================== utils ==========================
static func get_node_by_class_path(node:Node, class_path:Array)->Node:
var res:Node
var stack = []
var depths = []
var first = class_path[0]
for c in node.get_children():
if c.get_class() == first:
stack.push_back(c)
depths.push_back(0)
if not stack: return res
var max_ = class_path.size()-1
while stack:
var d = depths.pop_back()
var n = stack.pop_back()
if d>max_:
continue
if n.get_class() == class_path[d]:
if d == max_:
res = n
return res
for c in n.get_children():
stack.push_back(c)
depths.push_back(d+1)
return res
static func get_expand_bottom_panel_button(base:Control)->Button:
var result: Button = get_node_by_class_path(
base, [
'VBoxContainer',
'HSplitContainer',
'HSplitContainer',
'HSplitContainer',
'VBoxContainer',
'VSplitContainer',
'PanelContainer',
'VBoxContainer',
'HBoxContainer',
'ToolButton'
]
)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment