Add a few demo controls.
This commit is contained in:
parent
1cd005f827
commit
49257574f4
@ -10,30 +10,31 @@ namespace Dashboard.ImmediateUI
|
||||
{
|
||||
public class DimUIConfig
|
||||
{
|
||||
public float Margin = 4f;
|
||||
public float Padding = 4f;
|
||||
|
||||
public Vector2 Margin = new Vector2(8, 4);
|
||||
public Vector2 Padding = new Vector2(4);
|
||||
public required IFont Font { get; init; }
|
||||
|
||||
public IBrush TextBrush = new SolidBrush(Color.Black);
|
||||
public IBrush DisabledText = new SolidBrush(Color.Gray);
|
||||
|
||||
public float ButtonBorderSize = 2f;
|
||||
public IBrush ButtonBorderBrush = new SolidBrush(Color.DarkSlateGray);
|
||||
public IBrush ButtonBorderBrush = new SolidBrush(Color.SteelBlue);
|
||||
public IBrush ButtonFillBrush = new SolidBrush(Color.SlateGray);
|
||||
public IBrush? ButtonShadowBrush = new SolidBrush(Color.FromArgb(32, Color.LightSteelBlue));
|
||||
public float ButtonShadowOffset = 4f;
|
||||
public float ButtonShadowOffset = 2f;
|
||||
|
||||
public float InputBorderSize = 2f;
|
||||
public IBrush InputPlaceholderTextBrush = new SolidBrush(Color.SlateGray);
|
||||
public IBrush InputPlaceholderTextBrush = new SolidBrush(Color.SteelBlue);
|
||||
public IBrush InputBorderBrush = new SolidBrush(Color.SlateGray);
|
||||
public IBrush InputFillBrush = new SolidBrush(Color.LightGray);
|
||||
public IBrush? InputShadowBrush = new SolidBrush(Color.FromArgb(32, Color.LightSteelBlue));
|
||||
public float InputShadowOffset = -4f;
|
||||
public float InputShadowOffset = -2f;
|
||||
|
||||
public float MenuBorderSize = 2f;
|
||||
public IBrush MenuBorderBrush = new SolidBrush(Color.DarkSlateGray);
|
||||
public IBrush MenuBorderBrush = new SolidBrush(Color.SteelBlue);
|
||||
public IBrush MenuFillBrush = new SolidBrush(Color.SlateGray);
|
||||
public IBrush? MenuShadowBrush = new SolidBrush(Color.FromArgb(32, Color.LightSteelBlue));
|
||||
public float MenuShadowOffset = 6f;
|
||||
public float MenuShadowOffset = 2f;
|
||||
}
|
||||
|
||||
public class DimUI
|
||||
@ -80,7 +81,7 @@ namespace Dashboard.ImmediateUI
|
||||
_sameLine = false;
|
||||
}
|
||||
|
||||
_pen.X += _config.Margin;
|
||||
_pen.X += _config.Margin.X;
|
||||
_lineHeight = 0;
|
||||
}
|
||||
|
||||
@ -95,24 +96,101 @@ namespace Dashboard.ImmediateUI
|
||||
|
||||
SizeF sz = Typesetter.MeasureString(_config.Font, text);
|
||||
float z = Z();
|
||||
float h = _config.Margin * 2 + sz.Height;
|
||||
_queue.Text(new Vector3(_pen + new Vector2(0, _config.Margin), z), _config.TextBrush, text, _config.Font);
|
||||
float h = _config.Margin.Y * 2 + sz.Height;
|
||||
_queue.Text(new Vector3(_pen + new Vector2(0, _config.Margin.X), z), _config.TextBrush, text, _config.Font);
|
||||
|
||||
_lineHeight = Math.Max(_lineHeight, h);
|
||||
_pen.X += sz.Width;
|
||||
}
|
||||
|
||||
public void DrawBox(
|
||||
Vector2 position,
|
||||
Vector2 size,
|
||||
IBrush fill,
|
||||
IBrush border, float borderWidth,
|
||||
IBrush? shadow, float offset)
|
||||
{
|
||||
float z = Z();
|
||||
|
||||
if (shadow != null)
|
||||
{
|
||||
if (offset >= 0)
|
||||
{
|
||||
_queue.Rect(position + new Vector2(offset), position + size + new Vector2(offset + borderWidth), z, shadow);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inset shadows are draw a bit weirdly.
|
||||
_queue.Rect(position, position + new Vector2(offset, size.Y), z, shadow);
|
||||
_queue.Rect(position + new Vector2(offset, 0), position + new Vector2(size.X - offset, offset), z, shadow);
|
||||
}
|
||||
}
|
||||
|
||||
_queue.Rect(position, position + size, z, fill, border, borderWidth, BorderKind.Outset);
|
||||
}
|
||||
|
||||
public bool Button(string label)
|
||||
{
|
||||
Line();
|
||||
|
||||
SizeF sz = Typesetter.MeasureString(_config.Font, label);
|
||||
|
||||
float h = _config.Margin.Y * 2 + _config.Padding.Y * 2 + sz.Height;
|
||||
DrawBox(
|
||||
_pen + new Vector2(0, _config.Margin.Y),
|
||||
new Vector2(sz.Width + 2 * _config.Padding.X, sz.Height + 2 * _config.Padding.Y),
|
||||
_config.ButtonFillBrush,
|
||||
_config.ButtonBorderBrush,
|
||||
_config.ButtonBorderSize,
|
||||
_config.ButtonShadowBrush,
|
||||
_config.ButtonShadowOffset);
|
||||
|
||||
float z = Z();
|
||||
|
||||
_queue.Text(new Vector3(_pen + new Vector2(_config.Padding.X, _config.Margin.Y + _config.Padding.Y), z),
|
||||
_config.TextBrush, label, _config.Font);
|
||||
_lineHeight = Math.Max(_lineHeight, h);
|
||||
|
||||
_pen.X += sz.Width + 2 * _config.Padding.X;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Input(string placeholder, StringBuilder value)
|
||||
{
|
||||
Line();
|
||||
|
||||
IBrush textBrush;
|
||||
string str;
|
||||
if (value.Length == 0)
|
||||
{
|
||||
textBrush = _config.DisabledText;
|
||||
str = placeholder;
|
||||
}
|
||||
else
|
||||
{
|
||||
textBrush = _config.TextBrush;
|
||||
str = value.ToString();
|
||||
}
|
||||
|
||||
SizeF sz = Typesetter.MeasureString(_config.Font, str);
|
||||
|
||||
float h = _config.Margin.Y * 2 + _config.Padding.Y * 2 + sz.Height;
|
||||
DrawBox(
|
||||
_pen + new Vector2(0, _config.Margin.Y),
|
||||
new Vector2(sz.Width + 2 * _config.Padding.X, sz.Height + 2 * _config.Padding.Y),
|
||||
_config.InputFillBrush,
|
||||
_config.InputBorderBrush,
|
||||
_config.InputBorderSize,
|
||||
_config.InputShadowBrush,
|
||||
_config.InputShadowOffset);
|
||||
|
||||
float z = Z();
|
||||
|
||||
_queue.Text(new Vector3(_pen + new Vector2(_config.Padding.X, _config.Margin.Y + _config.Padding.Y), z),
|
||||
textBrush, str, _config.Font);
|
||||
_lineHeight = Math.Max(_lineHeight, h);
|
||||
|
||||
_pen.X += sz.Width + 2 * _config.Padding.X;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Dashboard.Drawing;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using Dashboard;
|
||||
using Dashboard.Drawing.OpenGL;
|
||||
using Dashboard.Drawing.OpenGL.Text;
|
||||
@ -92,6 +93,7 @@ TK.Window.SetMode(wnd, WindowMode.Normal);
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
|
||||
IFont font = Typesetter.LoadFont("Nimbus Mono", 12f);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
while (!shouldExit)
|
||||
{
|
||||
@ -101,6 +103,10 @@ while (!shouldExit)
|
||||
|
||||
dimUI.Begin(new Box2d(0, 0, framebufferSize.X, framebufferSize.Y), queue);
|
||||
dimUI.Text("Hello World!");
|
||||
dimUI.Button("Cancel"); dimUI.SameLine();
|
||||
dimUI.Button("OK");
|
||||
|
||||
dimUI.Input("type me!", builder);
|
||||
|
||||
dimUI.BeginMenu();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user