We got CSS at home

This commit is contained in:
2025-06-29 22:21:13 +02:00
parent 681496d812
commit 207c8a20a4
15 changed files with 404 additions and 292 deletions

View File

@@ -0,0 +1,46 @@
[Button]
BackgroundColor = "#0f62fe"
TextColor = "#37eb34"
Padding = 16.0
# Creates an empty rule for Button.Normal.
# This will inherit style from Button, this is a temporary workaround.
[Button.Normal]
[Button.Hovered]
BackgroundColor = "#0353e9"
[Button.Pressed]
BackgroundColor = "#002d9c"
[Button.Danger]
TextColor = "#ffffff"
[Button.Danger.Normal]
BackgroundColor = "#da1e28"
[Button.Danger.Hovered]
BackgroundColor = "#ba1b23"
[Button.Danger.Pressed]
BackgroundColor = "#750e13"
[Button.Outline]
BackgroundColor = [0, 0, 0, 0]
BorderSize = 1.0
BorderColor = "#0f62fe"
TextColor = "#0353e9"
[Button.Outline.Normal]
TextColor = "#0353e9"
[Button.Outline.Hovered]
BackgroundColor = "#0353e9"
[Button.Outline.Pressed]
BackgroundColor = "#002d9c"
BorderColor = [0, 0, 0, 0]
# Default background color for all Container derived classes.
[Container]
BackgroundColor = "#e0e0e0"

View File

@@ -19,7 +19,7 @@ public class TestGame : Game
{
InitializeSystemsDefault();
_uiSystem = new UISystem(Input, StyleSheet.Default);
_uiSystem = new UISystem(Input);
// _uiSystem.RenderDebugRects = true;
_particleSystem = new ParticleSystem();
@@ -36,6 +36,7 @@ public class TestGame : Game
protected override void LoadResources()
{
ResourceManager.AddResourceLoaderAssociation(new ParticleEmitterSettingsResourceLoader());
ResourceManager.AddResourceLoaderAssociation(new StyleSheetLoader());
if (!ResourceManager.TryLoad("fonts/Inter-Regular.ttf", out _font))
{
@@ -55,27 +56,32 @@ public class TestGame : Game
throw new Exception("Failed to load emitter settings!");
}
if (ResourceManager.TryLoad("default.style.toml", out _styleSheet))
{
}
_defaultFontSet = new([_font, _jpFont]);
}
protected override void Ready()
{
Input.AddInputMapping("reload", new IInputAction[] { new KeyInputAction(KeyboardKey.R) });
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _fireEffect);
// _emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _fireEffect);
var addButton = new Button("Add element", _defaultFontSet, () => { _container.AddChild(new Label("Hello, World!", _defaultFontSet)); });
_uiSystem.SetStyleSheet(_styleSheet);
var removeButton = new Button("Remove element", _defaultFontSet, () =>
{
if (_container.Children.Count == 0) return;
var lastChild = _container.Children.Last();
_container.RemoveChild(lastChild);
});
var addButton = new Button("Default button", _defaultFontSet);
var removeButton = new Button("Danger button", _defaultFontSet);
removeButton.StyleVariant = "Danger";
// _buttonContainer.AddChild(addButton);
// _buttonContainer.AddChild(removeButton);
var outlineButton = new Button("Outline button", _defaultFontSet);
outlineButton.StyleVariant = "Outline";
_buttonContainer.AddChild(addButton);
_buttonContainer.AddChild(removeButton);
var c = new HorizontalContainer()
{
@@ -86,11 +92,12 @@ public class TestGame : Game
c.AddChild(addButton);
c.AddChild(removeButton);
c.AddChild(outlineButton);
var vc = new VerticalContainer(0.0f);
vc.AddChild(c);
var f = new MarginContainer(new Margin(0.0f));
var f = new MarginContainer(new Size(0.0f));
f.AddChild(_container);
vc.AddChild(f);
@@ -105,7 +112,7 @@ public class TestGame : Game
if (Input.IsActionPressed("reload"))
{
ResourceManager.Reload();
_particleSystem!.RestartEmitter(_emitterId);
// _particleSystem!.RestartEmitter(_emitterId);
}
}
@@ -147,6 +154,7 @@ public class TestGame : Game
private ResourceRef<ParticleEmitterSettingsResource> _fireEffect;
private ResourceRef<Font> _font;
private ResourceRef<Font> _jpFont;
private ResourceRef<StyleSheet> _styleSheet;
private FontSet _defaultFontSet;