addon for remapping inputs
font size tuning
TODO: make it automatically find the best font size based on `icon_size`
bendn 2022-11-25
parent 82b8fe5 · commit 6a3a327
-rw-r--r--Test.tscn5
-rw-r--r--addons/remap/ActionLabel.gd5
-rw-r--r--addons/remap/RemapButton.gd7
-rw-r--r--addons/remap/package.json2
-rw-r--r--addons/remap/private/ActionIcon.gd3
-rw-r--r--addons/remap/private/ActionIcons.gd6
6 files changed, 20 insertions, 8 deletions
diff --git a/Test.tscn b/Test.tscn
index 2390284..504424e 100644
--- a/Test.tscn
+++ b/Test.tscn
@@ -22,6 +22,8 @@ layout_mode = 2
script = ExtResource("4")
_name = "left"
action = "ui_left"
+icon_size = Vector2(80, 80)
+font_size = 50
continuous_updating = true
[node name="remapbutton" type="HBoxContainer" parent="v"]
@@ -31,4 +33,5 @@ offset_bottom = 4.0
script = ExtResource("2_dj1bu")
_name = "left"
action = "ui_left"
-continuous_updating = true
+icon_size = Vector2(80, 80)
+font_size = 50
diff --git a/addons/remap/ActionLabel.gd b/addons/remap/ActionLabel.gd
index 956357f..446540a 100644
--- a/addons/remap/ActionLabel.gd
+++ b/addons/remap/ActionLabel.gd
@@ -19,6 +19,9 @@ const SaveLoadUtils := preload("./private/SaveLoadUtils.gd")
## The font to use. Only change if your font has the [url=https://github.com/Shinmera/promptfont/blob/c27797b49dee560e3ea3eaa40e87f9a7f35e8913/glyphs.json]necessary glyphs[/url].
@export var font: Font = preload("./PromptFont.ttf")
+## The font size
+@export var font_size: int = 16
+
## Wether to update continuously. Usefull if you have RemapButtons on this action.
@export var continuous_updating := false
@@ -44,7 +47,7 @@ func _ready() -> void:
name_label.horizontal_alignment = ALIGNMENT_CENTER
var spacer := Control.new()
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
- icons = ActionIcons.new(action, icon_size, font)
+ icons = ActionIcons.new(action, icon_size, font, font_size)
add_child(spacer)
add_child(icons)
if not continuous_updating:
diff --git a/addons/remap/RemapButton.gd b/addons/remap/RemapButton.gd
index 190262a..324f439 100644
--- a/addons/remap/RemapButton.gd
+++ b/addons/remap/RemapButton.gd
@@ -25,7 +25,10 @@ const SaveLoadUtils := preload("./private/SaveLoadUtils.gd")
## The minimum ActionIcon size.
@export var icon_size := Vector2(20, 20)
-## The font to use.
+## The font size
+@export var font_size: int = 16
+
+## The font to use. Only change if your font has the [url=https://github.com/Shinmera/promptfont/blob/c27797b49dee560e3ea3eaa40e87f9a7f35e8913/glyphs.json]necessary glyphs[/url].
@export var font: Font = preload("./PromptFont.ttf")
## Wether to update continuously. Usefull if you have multple RemapButtons following this action.
@@ -62,7 +65,7 @@ func _ready() -> void:
button.pressed.connect(_pressed)
var spacer := Control.new()
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
- icons = ActionIcons.new(action, icon_size, font)
+ icons = ActionIcons.new(action, icon_size, font, font_size)
add_child(button)
add_child(spacer)
add_child(icons)
diff --git a/addons/remap/package.json b/addons/remap/package.json
index abe7afa..89dd732 100644
--- a/addons/remap/package.json
+++ b/addons/remap/package.json
@@ -1,6 +1,6 @@
{
"name": "@bendn/remap",
- "version": "4.0.2",
+ "version": "4.1.0",
"description": "godot input remapping",
"main": "InteractiveActionLabel.gd",
"scripts": {
diff --git a/addons/remap/private/ActionIcon.gd b/addons/remap/private/ActionIcon.gd
index 3f923e7..5df00bc 100644
--- a/addons/remap/private/ActionIcon.gd
+++ b/addons/remap/private/ActionIcon.gd
@@ -6,7 +6,7 @@ extends PanelContainer
## The inner label.
var label := Label.new()
-func _init(text: String, min_size: Vector2, font: Font) -> void:
+func _init(text: String, min_size: Vector2, font: Font, font_size: int) -> void:
label.horizontal_alignment = BoxContainer.ALIGNMENT_CENTER
label.vertical_alignment = BoxContainer.ALIGNMENT_CENTER
add_child(label)
@@ -14,3 +14,4 @@ func _init(text: String, min_size: Vector2, font: Font) -> void:
label.text = text
if font:
label.add_theme_font_override("font", font)
+ label.add_theme_font_size_override("font_size", font_size)
diff --git a/addons/remap/private/ActionIcons.gd b/addons/remap/private/ActionIcons.gd
index ea94cea..03ba1a2 100644
--- a/addons/remap/private/ActionIcons.gd
+++ b/addons/remap/private/ActionIcons.gd
@@ -14,11 +14,13 @@ var min_size := Vector2(20, 20)
## The font to use
var font: Font
+var font_size: int
-func _init(p_action: String, p_min_size: Vector2, p_font: Font) -> void:
+func _init(p_action: String, p_min_size: Vector2, p_font: Font, p_font_size: int) -> void:
action = p_action
min_size = p_min_size
font = p_font
+ font_size = p_font_size
## Updates the icons to the latest inputs.
func update():
@@ -26,4 +28,4 @@ func update():
i.queue_free()
for e in InputMap.action_get_events(action):
var icon := IconMap.get_icon(e)
- add_child(ActionIcon.new(icon, min_size, font))
+ add_child(ActionIcon.new(icon, min_size, font, font_size))