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

86 lines
1.5 KiB
C#

using Godot;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class UI : Control
{
[Export]
public UISettings settings;
[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();
}
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() );
}
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;
}
}
}
}