59 lines
959 B
C#
59 lines
959 B
C#
|
|
||
|
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() );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|