rj-action-library/Runtime/UI/UI.cs

86 lines
1.5 KiB
C#
Raw Normal View History

2024-08-09 13:52:49 +00:00
using Godot;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class UI : Control
{
2024-09-14 06:41:52 +00:00
[Export]
public UISettings settings;
2024-08-09 13:52:49 +00:00
[Export]
public UINumber fontSize;
[Export]
public float fontZoom = 1;
[Export]
public float X_computedFontSizePixels = 1;
[Export]
public bool updateFlag = false;
[Export]
public bool updateAlways = true;
public override void _Process( double delta )
{
UpdateFontSize();
UpdateUIElements();
}
2024-08-11 17:38:06 +00:00
2024-08-09 13:52:49 +00:00
void UpdateFontSize()
{
X_computedFontSizePixels = UINumber.Compute( this, fontSize ) * fontZoom;
if ( Theme != null )
{
Theme.DefaultFontSize = Mathf.RoundToInt( X_computedFontSizePixels );
}
}
void UpdateUIElements()
{
if ( ! ( updateFlag || updateAlways ) )
{
return;
}
updateFlag = false;
Nodes.ForEachDirectChild<UIRegion>( this, r => r.Layout() );
}
2024-08-11 17:38:06 +00:00
public static float GetWindowWidth( Control control )
{
if ( Engine.IsEditorHint() )
{
return ProjectSettings.GetSetting( "display/window/size/viewport_width" ).AsInt32();
}
else
{
return control.GetWindow().Size.X;
}
}
public static float GetWindowHeight( Control control )
{
if ( Engine.IsEditorHint() )
{
return ProjectSettings.GetSetting( "display/window/size/viewport_height" ).AsInt32();
}
else
{
return control.GetWindow().Size.Y;
}
}
2024-08-09 13:52:49 +00:00
}
}