mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-10 04:40:25 +01:00
Add popup label to show terminal and panel size on resize
Shows the terminal cols/rows (if a terminal is open) and the size of the the tab_container in pixels. Shows centered for 1 second, then closes.
This commit is contained in:
parent
de7980c077
commit
ec0d4ddf43
2 changed files with 65 additions and 0 deletions
|
@ -32,6 +32,12 @@ onready var tabbar_container: HBoxContainer = $VBoxContainer/TabbarContainer
|
|||
onready var add_button: ToolButton = $VBoxContainer/TabbarContainer/Tabs/AddButton
|
||||
onready var tab_container: TabContainer = $VBoxContainer/TabContainer
|
||||
onready var terminal_popup_menu: PopupMenu = $VBoxContainer/TerminalPopupMenu
|
||||
|
||||
# Size label.
|
||||
# Used to show the size of the terminal (rows/cols) and panel (pixels) when resized.
|
||||
onready var size_label: Label = $SizeLabel
|
||||
onready var size_label_timer: Timer = $SizeLabel/SizeLabelTimer
|
||||
|
||||
onready var ready := true
|
||||
|
||||
var _theme := Theme.new()
|
||||
|
@ -62,6 +68,7 @@ func _update_settings() -> void:
|
|||
|
||||
var editor_scale: float = editor_interface.get_editor_scale()
|
||||
rect_min_size = Vector2(0, tabbar_container.rect_size.y + 182) * editor_scale
|
||||
rect_size.y = 415
|
||||
|
||||
tabs.tab_close_display_policy = Tabs.CLOSE_BUTTON_SHOW_ALWAYS
|
||||
|
||||
|
@ -239,3 +246,26 @@ func _on_TerminalPopupMenu_id_pressed(id):
|
|||
func _on_Tabs_reposition_active_tab_request(idx_to):
|
||||
var active = tab_container.get_child(tab_container.current_tab)
|
||||
tab_container.move_child(active, idx_to)
|
||||
|
||||
|
||||
func _on_Panel_resized():
|
||||
if not size_label:
|
||||
return
|
||||
|
||||
var size = tab_container.rect_size
|
||||
if tabs.get_tab_count() > 0:
|
||||
var terminal = tab_container.get_child(tabs.current_tab)
|
||||
var cols = terminal.cols
|
||||
var rows = terminal.rows
|
||||
size_label.text = "Size: %d cols; %d rows\n(%d x %d px)" % [cols, rows, size.x, size.y]
|
||||
else:
|
||||
size_label.text = "Size:\n(%d x %d px)" % [size.x, size.y]
|
||||
|
||||
size_label.visible = true
|
||||
size_label_timer.wait_time = 1
|
||||
size_label_timer.start()
|
||||
|
||||
|
||||
func _on_SizeLabelTimer_timeout():
|
||||
if size_label:
|
||||
size_label.visible = false
|
||||
|
|
|
@ -112,9 +112,44 @@ __meta__ = {
|
|||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="SizeLabel" type="Label" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -52.0
|
||||
margin_top = -15.5
|
||||
margin_right = 52.0
|
||||
margin_bottom = 15.5
|
||||
text = "Size: %d rows; %d cols
|
||||
(%d x %d)"
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Panel" type="Panel" parent="SizeLabel"]
|
||||
show_behind_parent = true
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -5.0
|
||||
margin_top = -5.0
|
||||
margin_right = 5.0
|
||||
margin_bottom = 5.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="SizeLabelTimer" type="Timer" parent="SizeLabel"]
|
||||
|
||||
[connection signal="resized" from="." to="." method="_on_Panel_resized"]
|
||||
[connection signal="reposition_active_tab_request" from="VBoxContainer/TabbarContainer/Tabs" to="." method="_on_Tabs_reposition_active_tab_request"]
|
||||
[connection signal="tab_changed" from="VBoxContainer/TabbarContainer/Tabs" to="." method="_on_Tabs_tab_changed"]
|
||||
[connection signal="tab_close" from="VBoxContainer/TabbarContainer/Tabs" to="." method="_on_Tabs_tab_close"]
|
||||
[connection signal="pressed" from="VBoxContainer/TabbarContainer/Tabs/AddButton" to="." method="_on_AddButton_pressed"]
|
||||
[connection signal="gui_input" from="VBoxContainer/TabContainer" to="." method="_on_TabContainer_gui_input"]
|
||||
[connection signal="id_pressed" from="VBoxContainer/TerminalPopupMenu" to="." method="_on_TerminalPopupMenu_id_pressed"]
|
||||
[connection signal="timeout" from="SizeLabel/SizeLabelTimer" to="." method="_on_SizeLabelTimer_timeout"]
|
||||
|
|
Loading…
Reference in a new issue