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.
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::Corealways - 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
Flagenum - Set and read by your application code
- Great for: selected, disabled, highlighted, active
- Example:
MyManifest::Flag::Selected
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.
| Flag | Set by | Meaning |
|---|---|---|
ml::Flag::HOVERED | HoverableDispatcher | Mouse cursor is currently over this component |
ml::Flag::CLICKED | ClickableDispatcher | Mouse button is held down over this component |
ml::Flag::FOCUSED | ClickableDispatcher | Component has keyboard focus |
ml::Flag::DRAGGING | DraggableDispatcher | A drag gesture is currently in progress |
ml::Flag::DRAGGABLE | User code | Enables mouse-drag handling — set this to allow dragging |
ml::Flag::HIDDEN | User code | Conventionally marks a component as not visible |
ml::Flag::ENABLED | User code | Marks a component as active and interactive |
ml::Flag::VERTICAL | User code | Layout/scroll axis hint |
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)
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.
class CardManifest : public ml::Manifest
{
public:
enum class Flag { Selected, Highlighted, Completed, Disabled };
enum class State { Idle, Active, Done };
};
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);
}
};
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.
| Method | Description |
|---|---|
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 |
// 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);
false — a flag that has never been set returns false from checkFlag(). You never need to initialize them.