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

59 lines
959 B
C#
Raw Normal View History

2024-08-09 13:52:49 +00:00
using Godot;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class UI : Control
{
[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() );
}
}
}