Ss14 ui styles palettes sheetlets

From space-sunrise/project-fire · View interactive version

Ss14 ui styles palettes sheetlets is an AI agent skill from the GitHub repository space-sunrise/project-fire. A practical guide to the SS14 style system: StyleClass, palettes, StyleProperties, sheetlets, pseudo-classes and rules composition. Use it when developing and refactoring a visual UI language without hardcode.

How to use this skill

Skill file

Styles, palettes and sheetlets in SS14 UI

This skill only covers the UI style system: classes, palettes, sheetlets and application rules :)

Window layout and network lifecycle UI should be done in separate skills.

System framework

Pseudo-classes: complete list and when issued

| Pseudo-class | Where is it used | When is exhibited |

|---|---|---|

| normal | ContainerButton, TextureButton, heirs | Normal rendering mode (DrawModeEnum.Normal). |

| hover | ContainerButton, TextureButton, ScrollBar | The cursor is over the control/grabber, but there is no active click/drag. |

| pressed | ContainerButton, TextureButton, heirs | Control in pressed state (DrawModeEnum.Pressed). |

| disabled | ContainerButton, TextureButton, heirs | Control disabled (DrawModeEnum.Disabled). |

| grabbed | ScrollBar | The scrollbar slider is captured by the mouse (drag is active). |

| placeholder | LineEdit, TextEdit | Empty text + placeholder specified, the placeholder is displayed. |

| notEditable | TextEdit | The control has been converted to read-only (Editable = false). |

| confirm-normal | ConfirmButton | The button is in confirm mode and in its normal state. |

| confirm-hover | ConfirmButton | Confirm mode + guidance. |

| confirm-pressed | ConfirmButton | Confirm mode + press. |

| confirm-disabled | ConfirmButton | Confirm mode + disabled. |

Code examples: issuing pseudo-classes

// Basic Button: Pseudo-class follows DrawMode.
protected override void DrawModeChanged()
{
    switch (DrawMode)
    {
        case DrawModeEnum.Normal:
            SetOnlyStylePseudoClass(StylePseudoClassNormal);
            break;
        case DrawModeEnum.Pressed:
            SetOnlyStylePseudoClass(StylePseudoClassPressed);
            break;
        case DrawModeEnum.Hover:
            SetOnlyStylePseudoClass(StylePseudoClassHover);
            break;
        case DrawModeEnum.Disabled:
            SetOnlyStylePseudoClass(StylePseudoClassDisabled);
            break;
    }
}
// ScrollBar: grabbed takes precedence over hover.
private void _updatePseudoClass()
{
    if (_grabData != null)
        SetOnlyStylePseudoClass(StylePseudoClassGrabbed);
    else if (_isHovered)
        SetOnlyStylePseudoClass(StylePseudoClassHover);
    else
        SetOnlyStylePseudoClass(null);
}
// TextEdit: placeholder + notEditable.
private void UpdatePseudoClass()
{
    SetOnlyStylePseudoClass(IsPlaceholderVisible ? StylePseudoClassPlaceholder : null);
    if (!Editable)
        AddStylePseudoClass(StylePseudoClassNotEditable);
}
// ConfirmButton: Adds the confirm- prefix to the base states.
protected override void DrawModeChanged()
{
    if (IsConfirming)
    {
        switch (DrawMode)
        {
            case DrawModeEnum.Normal:
                SetOnlyStylePseudoClass(ConfirmPrefix + StylePseudoClassNormal);
                break;
            case DrawModeEnum.Pressed:
                SetOnlyStylePseudoClass(ConfirmPrefix + StylePseudoClassPressed);
                break;
            case DrawModeEnum.Hover:
                SetOnlyStylePseudoClass(ConfirmPrefix + StylePseudoClassHover);
                break;
            case DrawModeEnum.Disabled:
                SetOnlyStylePseudoClass(ConfirmPrefix + StylePseudoClassDisabled);
                break;
        }
        return;
    }

    base.DrawModeChanged();
}

All wrapper helpers over `Prop`

Below is a complete list of wrappers from StylesheetHelpers that ultimately call Prop(...).

| Helper | What exposes |

|---|---|

| Modulate(Color) | Control.StylePropertyModulateSelf |

| Margin(Thickness) | Control.Margin |

| Margin(float) | Control.Margin (via Thickness) |

| MinWidth(float) | Control.MinWidth |

| MinHeight(float) | Control.MinHeight |

| MinSize(Vector2) | Control.MinWidth + Control.MinHeight |

| MaxWidth(float) | Control.MaxWidth |

| MaxHeight(float) | Control.MaxHeight |

| MaxSize(Vector2) | Control.MaxWidth + Control.MaxHeight |

| SetWidth(float) | Control.SetWidth |

| SetHeight(float) | Control.SetHeight |

| SetSize(Vector2) | Control.SetWidth + Control.SetHeight |

| HorizontalExpand(bool) | Control.HorizontalExpand |

| VerticalExpand(bool) | Control.VerticalExpand |

| HorizontalAlignment(HAlignment) | in the current implementation, helper writes to the key Control.HorizontalExpand |

| VerticalAlignment(VAlignment) | in the current implementation, helper writes to the key Control.VerticalExpand |

| AlignMode(Label.AlignMode) | Label.StylePropertyAlignMode |

| Panel(StyleBox) | PanelContainer.StylePropertyPanel |

| Box(StyleBox) | ContainerButton.StylePropertyStyleBox |

| Font(Font) | Label.StylePropertyFont |

| FontColor(Color) | Label.StylePropertyFontColor |

Additionally (not Prop wrappers, but often go hand in hand):

Important:

Schemes: child by parent and parent by child

1) Change child by parent (directly supported)

Scheme:

Parent selector -> Child selector -> Style props child

Example from code:

// The style of the inner PanelContainer depends on the NanoHeading parent.
return
[
    E<NanoHeading>()
        .ParentOf(E<PanelContainer>())
        .Panel(nanoHeadingBox),
];

2) Changing parent by child (no direct selector)

This is not done purely with CSS style; the working pattern is as follows:

Child state/event -> code sets parent class/pseudoclass -> style matches parent

Recommendation:

Mini example approach:

// Code-behind: the child control has changed state -> mark the parent with a class.
if (childIsWarning)
    parent.AddStyleClass("child-warning");
else
    parent.RemoveStyleClass("child-warning");

// Stylesheet: the parent is styled by the class set from the code.
E<PanelContainer>()
    .Class("child-warning")
    .Modulate(sheet.NegativePalette.Element);

Using textures for UI

Basic rules

Code examples

// Button texture from stylesheet resources.
var buttonTex = sheet.GetTextureOr(cfg.BaseButtonPath, NanotrasenStylesheet.TextureRoot);

var topButtonBase = new StyleBoxTexture
{
    Texture = buttonTex,
};
topButtonBase.SetPatchMargin(StyleBox.Margin.All, 10);
// Texture icon style.
E<TextureRect>()
    .Class(OptionButton.StyleClassOptionTriangle)
    .Prop(TextureRect.StylePropertyTexture, invertedTriangleTex);
// Convenient wrapper for 9-slice.
var styleBox = texture.IntoPatch(StyleBox.Margin.All, 3);
styleBox.SetContentMarginOverride(StyleBox.Margin.Horizontal, 5);

Rules for choosing colors for styles

  1. First choose a semantic palette:
  1. For interactive states, follow the chain:
  1. For text and background, use the assigned roles:
  1. Do statuses and scales using StatusPalette, and not manual if/hex:
var good = Palettes.Status.GetStatusColor(1.0f);
var warning = Palettes.Status.GetStatusColor(0.5f);
var critical = Palettes.Status.GetStatusColor(0.0f);
  1. Color.FromHex(...) is valid in one place: when creating a new palette.
  1. For icons/texture buttons, do color variation through Modulate(...), so as not to produce duplicate textures.

Working with fonts

###What to use

Code examples

// Large bold signature for menu buttons.
E<Label>()
    .Class(MenuButton.StyleClassLabelTopButton)
    .Prop(Label.StylePropertyFont, sheet.BaseFont.GetFont(14, FontKind.Bold));
// Regular and italic style for status texts.
E()
    .Class(StyleClass.ItemStatus)
    .Prop("font", sheet.BaseFont.GetFont(10));

E()
    .Class(StyleClass.ItemStatusNotHeld)
    .Prop("font", sheet.BaseFont.GetFont(10, FontKind.Italic))
    .Prop("font-color", Color.Gray);

Practice

Patterns 😎

Anti-patterns

Quality checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.