Skip to content

Add rich-text tooltips for blocks #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions addons/block_code/ui/blocks/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ func serialize_props(prop_names: Array) -> Array:
for p in prop_names:
pairs.append([p, self.get(p)])
return pairs


func _make_custom_tooltip(for_text) -> Control:
var tooltip = preload("res://addons/block_code/ui/tooltip/tooltip.tscn").instantiate()
tooltip.text = for_text
return tooltip
9 changes: 9 additions & 0 deletions addons/block_code/ui/picker/categories/category_factory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,21 @@ static func get_general_blocks() -> Array[Block]:
b.block_formats = ["repeat {number: INT}"]
b.statements = ["for i in {number}:"]
b.category = "Loops"
b.tooltip_text = "Run the connected blocks [i]number[/i] times"
block_list.append(b)

b = BLOCKS["control_block"].instantiate()
b.block_formats = ["while {condition: BOOL}"]
b.statements = ["while {condition}:"]
b.category = "Loops"
b.tooltip_text = (
"""
Run the connected blocks as long as [i]condition[/i] is true.

Hint: snap a [b]Comparison[/b] block into the condition.
"""
. dedent()
)
block_list.append(b)

b = BLOCKS["statement_block"].instantiate()
Expand Down
24 changes: 24 additions & 0 deletions addons/block_code/ui/tooltip/tooltip.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@tool
class_name Tooltip
extends RichTextLabel
## Rich-text control for block tooltips that matches the built-in inspector's tooltips' font styles


func override_font(font_name: StringName, editor_font_name: StringName) -> Font:
var font = get_theme_font(editor_font_name, &"EditorFonts")
add_theme_font_override(font_name, font)
return font


func _ready():
# Set fonts to match documentation tooltips in inspector
override_font(&"normal_font", &"doc")
override_font(&"mono_font", &"doc_source")
override_font(&"bold_font", &"doc_bold")
var italics = override_font(&"italics_font", &"doc_italic")

# No doc_ style for bold italic; fake it by emboldening the italic style
var bold_italics = FontVariation.new()
bold_italics.set_base_font(italics)
bold_italics.set_variation_embolden(1.2)
add_theme_font_override(&"bold_italics_font", bold_italics)
14 changes: 14 additions & 0 deletions addons/block_code/ui/tooltip/tooltip.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=2 format=3 uid="uid://bmxco03vqyq2t"]

[ext_resource type="Script" path="res://addons/block_code/ui/tooltip/tooltip.gd" id="1_4ko6a"]

[node name="Tooltip" type="RichTextLabel"]
custom_minimum_size = Vector2(360, 48)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
bbcode_enabled = true
fit_content = true
script = ExtResource("1_4ko6a")
Loading