From 8839cca6e90ba4b7693f7ca5d4778df814562f9d Mon Sep 17 00:00:00 2001
From: Mew Pur Pur <85438892+MewPurPur@users.noreply.github.com>
Date: Mon, 27 May 2024 13:05:50 +0300
Subject: [PATCH] Make the tag title clickable instead of the icon to the side
(#763)
---
src/ui_parts/tag_frame.gd | 29 ++++++++++++++++++-----------
src/ui_parts/tag_frame.tscn | 17 ++---------------
visual/icons/QuestionMark.svg | 2 +-
3 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/src/ui_parts/tag_frame.gd b/src/ui_parts/tag_frame.gd
index 9bb3d90e..e2fb67ae 100644
--- a/src/ui_parts/tag_frame.gd
+++ b/src/ui_parts/tag_frame.gd
@@ -14,7 +14,6 @@ const TagContentPath = preload("res://src/ui_elements/tag_content_path.tscn")
@onready var main_container: VBoxContainer = $Content/MainContainer
@onready var title_bar: Panel = $TitleBar
-@onready var title_button: Button = $TitleBar/TitleButton
var child_tags_container: VBoxContainer # Only created if there are child tags.
@onready var content: PanelContainer = $Content
@@ -25,7 +24,6 @@ var surface := RenderingServer.canvas_item_create() # Used for the drop indicat
@onready var title_bar_ci := title_bar.get_canvas_item()
func _ready() -> void:
- title_bar.custom_minimum_size.y = title_button.size.y + 4
RenderingServer.canvas_item_set_parent(surface, get_canvas_item())
RenderingServer.canvas_item_set_z_index(surface, 1)
Indications.selection_changed.connect(determine_selection_highlight)
@@ -98,10 +96,10 @@ func _on_title_button_pressed() -> void:
# in a multi-selection, only the mouse button release would change the selection.
Indications.normal_select(tid)
var viewport := get_viewport()
- var title_button_rect := title_button.get_global_rect()
+ var rect := title_bar.get_global_rect()
HandlerGUI.popup_under_rect_center(Indications.get_selection_context(
- HandlerGUI.popup_under_rect_center.bind(title_button_rect, viewport), Indications.SelectionContext.TAG_EDITOR),
- title_button_rect, viewport)
+ HandlerGUI.popup_under_rect_center.bind(rect, viewport),
+ Indications.SelectionContext.TAG_EDITOR), rect, viewport)
func _gui_input(event: InputEvent) -> void:
@@ -229,14 +227,23 @@ func _on_title_bar_draw() -> void:
var half_bar_width := title_bar.size.x / 2
var title_width := code_font.get_string_size(tag.name,
HORIZONTAL_ALIGNMENT_LEFT, 180, 12).x
- code_font.draw_string(title_bar_ci, Vector2(half_bar_width - title_width / 2, 18),
+ code_font.draw_string(title_bar_ci, Vector2(half_bar_width - title_width / 2 + 4, 18),
tag.name, HORIZONTAL_ALIGNMENT_LEFT, 180, 12)
- title_button.position = title_bar.position +\
- Vector2(half_bar_width + title_width / 2 + 3, 4)
- title_button.reset_size()
tag.icon.draw_rect(title_bar_ci, Rect2(Vector2(half_bar_width - title_width / 2 -\
- tag_icon_size.x - 4, 4).round(), tag_icon_size), false)
+ tag_icon_size.x, 4).round(), tag_icon_size), false)
+ # Add the button.
+ var title_button := Button.new()
+ title_button.focus_mode = Control.FOCUS_NONE
+ title_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
+ title_button.mouse_filter = Control.MOUSE_FILTER_PASS
+ title_button.theme_type_variation = "FlatButton"
+ title_button.position = title_bar.position +\
+ Vector2(half_bar_width - title_width / 2 - tag_icon_size.x - 2, 3)
+ title_button.size = Vector2(title_width + 28, 20)
+ title_bar.add_child(title_button)
+ title_button.gui_input.connect(_on_title_button_gui_input.bind(title_button))
+ title_button.pressed.connect(_on_title_button_pressed)
# Block dragging from starting when pressing the title button.
-func _on_title_button_gui_input(event: InputEvent) -> void:
+func _on_title_button_gui_input(event: InputEvent, title_button: Button) -> void:
title_button.mouse_filter = Utils.mouse_filter_pass_non_drag_events(event)
diff --git a/src/ui_parts/tag_frame.tscn b/src/ui_parts/tag_frame.tscn
index 78669486..19ee53d7 100644
--- a/src/ui_parts/tag_frame.tscn
+++ b/src/ui_parts/tag_frame.tscn
@@ -1,7 +1,6 @@
-[gd_scene load_steps=3 format=3 uid="uid://dfvfsput41mnw"]
+[gd_scene load_steps=2 format=3 uid="uid://dfvfsput41mnw"]
[ext_resource type="Script" path="res://src/ui_parts/tag_frame.gd" id="1_5mc4m"]
-[ext_resource type="Texture2D" uid="uid://cmepkbqde0jh0" path="res://visual/icons/SmallMore.svg" id="2_5jajt"]
[node name="TagFrame" type="VBoxContainer"]
offset_left = 2.0
@@ -12,21 +11,10 @@ theme_override_constants/separation = 0
script = ExtResource("1_5mc4m")
[node name="TitleBar" type="Panel" parent="."]
+custom_minimum_size = Vector2(0, 26)
layout_mode = 2
mouse_filter = 2
-[node name="TitleButton" type="Button" parent="TitleBar"]
-layout_mode = 2
-offset_right = 22.0
-offset_bottom = 22.0
-size_flags_horizontal = 0
-focus_mode = 0
-mouse_filter = 1
-mouse_default_cursor_shape = 2
-theme_type_variation = &"FlatButton"
-icon = ExtResource("2_5jajt")
-icon_alignment = 1
-
[node name="Content" type="PanelContainer" parent="."]
layout_mode = 2
mouse_filter = 2
@@ -38,4 +26,3 @@ theme_override_constants/separation = 8
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
[connection signal="draw" from="TitleBar" to="." method="_on_title_bar_draw"]
-[connection signal="pressed" from="TitleBar/TitleButton" to="." method="_on_title_button_pressed"]
diff --git a/visual/icons/QuestionMark.svg b/visual/icons/QuestionMark.svg
index 5fe10d35..0ac6871a 100644
--- a/visual/icons/QuestionMark.svg
+++ b/visual/icons/QuestionMark.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file