ml::docs | Your First App Manifests Events Messaging Plugins Scenes Resources
See all tutorials →
Beginner 4 sections ~15 min C++17/20

Flags

Flags are named boolean properties on every component. Use system flags to enable built-in behaviors, and custom manifest flags to track your own component state.

Introduction

What Are Flags?

Flags are named boolean properties on every ml::Core object. Two kinds exist: system flags (ml::Flag) managed automatically by the framework, and custom flags declared in your manifest. Both use the same five-method API.

ml::Flag — System Flags

  • Available on every ml::Core always
  • Set and cleared automatically by framework dispatchers
  • Control built-in behavior like dragging and focus
  • Example: ml::Flag::HOVERED, DRAGGABLE

Custom Flags — from Manifest

  • Declared in your manifest's Flag enum
  • Set and read by your application code
  • Great for: selected, disabled, highlighted, active
  • Example: MyManifest::Flag::Selected

1Core Concepts

System Flags — ml::Flag

Framework subsystems read and write these flags automatically. You can read them in draw() to adjust visual appearance, or write them to enable built-in behaviors.

FlagSet byMeaning
ml::Flag::HOVEREDHoverableDispatcherMouse cursor is currently over this component
ml::Flag::CLICKEDClickableDispatcherMouse button is held down over this component
ml::Flag::FOCUSEDClickableDispatcherComponent has keyboard focus
ml::Flag::DRAGGINGDraggableDispatcherA drag gesture is currently in progress
ml::Flag::DRAGGABLEUser codeEnables mouse-drag handling — set this to allow dragging
ml::Flag::HIDDENUser codeConventionally marks a component as not visible
ml::Flag::ENABLEDUser codeMarks a component as active and interactive
ml::Flag::VERTICALUser codeLayout/scroll axis hint
Reading system flags in draw() cpp
void MyWidget::draw(sf::RenderTarget& t, sf::RenderStates s) const
{
    // Highlight border on hover (HOVERED set automatically by framework)
    if (checkFlag(ml::Flag::HOVERED))
        _body.setOutlineColor(sf::Color(255, 255, 255, 100));
    else
        _body.setOutlineColor(sf::Color::Transparent);

    // Teal glow while dragging
    if (checkFlag(ml::Flag::DRAGGING))
        _body.setOutlineColor(sf::Color(93, 202, 165, 180));

    t.draw(_body, s);
}

// Enabling drag
myRect.setFlag(ml::Flag::DRAGGABLE);  // or: enableFlag(ml::Flag::DRAGGABLE)

2Core Concepts

Custom Flags — From Your Manifest

Declare a Flag enum in your manifest and every component that inherits ComponentWith<M> automatically gets a dedicated flag store for those values.

Manifest with custom flags cpp
class CardManifest : public ml::Manifest
{
public:
    enum class Flag { Selected, Highlighted, Completed, Disabled };
    enum class State { Idle, Active, Done };
};
Using custom flags in a component cpp
class TaskCard : public ml::ComponentWith
{
public:
    void select()
    {
        enableFlag(Flag::Selected);
        disableFlag(Flag::Highlighted);
    }

    void complete()
    {
        enableFlag(Flag::Completed);
        disableFlag(Flag::Selected);
        // Fade to 80% when done
        setFillOpacity(0.8f);
    }

    void draw(sf::RenderTarget& target, sf::RenderStates states) const override
    {
        // Custom flags drive visual appearance
        if (checkFlag(Flag::Selected))
            _body.setOutlineColor(sf::Color(124, 106, 247, 200));  // purple
        else if (checkFlag(Flag::Highlighted))
            _body.setOutlineColor(sf::Color(255, 255, 255, 60));   // white dim
        else
            _body.setOutlineColor(sf::Color::Transparent);

        // Grey out disabled components
        auto c = _body.getFillColor();
        c.a = checkFlag(Flag::Disabled) ? 80 : 255;
        _body.setFillColor(c);

        target.draw(_body, states);
    }
};

3Core Concepts

Flag API Reference

All five flag methods work identically for both system flags (ml::Flag) and custom manifest flags. The overload set automatically dispatches to the correct flag store.

MethodDescription
enableFlag(flag)Set this flag to true
disableFlag(flag)Set this flag to false
setFlag(flag, bool)Set to an explicit true or false
toggleFlag(flag)Flip between true and false
checkFlag(flag)Return true if set, false otherwise
All flag operations cpp
// System flag
myCard.enableFlag(ml::Flag::DRAGGABLE);
myCard.setFlag(ml::Flag::HIDDEN, false);

// Custom flag
myCard.enableFlag(CardManifest::Flag::Selected);
myCard.disableFlag(CardManifest::Flag::Highlighted);
myCard.toggleFlag(CardManifest::Flag::Completed);

bool hovered  = myCard.checkFlag(ml::Flag::HOVERED);
bool selected = myCard.checkFlag(CardManifest::Flag::Selected);
Flags default to false — a flag that has never been set returns false from checkFlag(). You never need to initialize them.