CodeEditorPanel - Change font size via Ctrl+Scroll Wheel (#44)

Co-authored-by: Matt Parker <61717342+MattParkerDev@users.noreply.github.com>
This commit is contained in:
XiaoDong Ma
2025-12-18 08:05:42 +08:00
committed by GitHub
parent 74f9ebbc18
commit d66ecfc017
3 changed files with 229 additions and 186 deletions

View File

@@ -35,6 +35,37 @@ public partial class CodeEditorPanel : MarginContainer
GlobalEvents.Instance.ProjectStoppedDebugging.Subscribe(OnProjectStoppedDebugging); GlobalEvents.Instance.ProjectStoppedDebugging.Subscribe(OnProjectStoppedDebugging);
} }
public override void _GuiInput(InputEvent @event)
{
if (Input.IsActionPressed(InputStringNames.EditorFontSizeIncrease))
{
AdjustCodeEditorUiScale(true);
}
else if (Input.IsActionPressed(InputStringNames.EditorFontSizeDecrease))
{
AdjustCodeEditorUiScale(false);
}
}
private void AdjustCodeEditorUiScale(bool increase)
{
const int minFontSize = 8;
const int maxFontSize = 72;
var editors = _tabContainer.GetChildren().OfType<SharpIdeCodeEdit>().ToList();
if (editors.Count is 0) return;
var currentFontSize = editors.First().GetThemeFontSize(ThemeStringNames.FontSize);
var newFontSize = increase
? Mathf.Clamp(currentFontSize + 2, minFontSize, maxFontSize)
: Mathf.Clamp(currentFontSize - 2, minFontSize, maxFontSize);
foreach (var editor in editors)
{
editor.AddThemeFontSizeOverride(ThemeStringNames.FontSize, newFontSize);
}
}
public override void _ExitTree() public override void _ExitTree()
{ {
var selectedTabIndex = _tabContainer.CurrentTab; var selectedTabIndex = _tabContainer.CurrentTab;

View File

@@ -14,6 +14,8 @@ public static class InputStringNames
public static readonly StringName FindFiles = nameof(FindFiles); public static readonly StringName FindFiles = nameof(FindFiles);
public static readonly StringName SaveFile = nameof(SaveFile); public static readonly StringName SaveFile = nameof(SaveFile);
public static readonly StringName SaveAllFiles = nameof(SaveAllFiles); public static readonly StringName SaveAllFiles = nameof(SaveAllFiles);
public static readonly StringName EditorFontSizeIncrease = nameof(EditorFontSizeIncrease);
public static readonly StringName EditorFontSizeDecrease = nameof(EditorFontSizeDecrease);
} }
public static class ThemeStringNames public static class ThemeStringNames

View File

@@ -88,6 +88,16 @@ DebuggerStepOut={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194342,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194342,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
] ]
} }
EditorFontSizeIncrease={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"button_mask":8,"position":Vector2(96, 15),"global_position":Vector2(105, 63),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
EditorFontSizeDecrease={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"button_mask":16,"position":Vector2(120, 12),"global_position":Vector2(129, 60),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
[rendering] [rendering]