Skip to content

Commit

Permalink
Make the tag title clickable instead of the icon to the side (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur authored May 27, 2024
1 parent 005f17d commit 8839cca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
29 changes: 18 additions & 11 deletions src/ui_parts/tag_frame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
17 changes: 2 additions & 15 deletions src/ui_parts/tag_frame.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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"]
2 changes: 1 addition & 1 deletion visual/icons/QuestionMark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8839cca

Please sign in to comment.