Layers 2.0 is archived. The latest version is 3.0. Read the 3.0 docs

LController Class

#include <Layers/lcontroller.h>

Public Functions

LController()
~LController()
LController(const LController &)
LController & operator=(const LController &)
LStyleList active_custom_styles()
LStyle * find_style(const LString & path)
LStyle * find_style(std::deque<LString> name_list)
void include(const LString & path, const LString & name_space = "")
void include_internal(const LString & path, const LString & name_space = "")
LController & instance()
void load_user_styles(const std::filesystem::path & path)
LStyle * root_style()
std::map<LString, std::unique_ptr<LStyle>> & custom_styles()
bool toggle_custom_style(const LString & style_id)
LUnresolvedLinkList unresolved_links()

Detailed Description

Central manager for styles in the Layers framework.

The controller loads, manages, and provides access to all styles. It handles inheritance resolution and link resolution.

For related JSON syntax, file organization, and resource compiling, see the Layers README. This documentation covers the C++ interface for working with the controller in code.

A default controller instance is available via the lController macro.

Loading Developer Styles

Compiled developer styles should be loaded via library initializers to ensure proper load order:

// mylib_init.cpp

namespace Layers::Resources {
    extern void initResources_styles();
}

class Initializer {
public:
    Initializer() {
        Layers::Resources::initResources_styles();
        lController.include("/styles/mylib");
    }
} static initializer;

This ensures styles load before main() and in dependency order.

Loading User Styles

User styles are toggleable customizations loaded from a directory:

lController.load_user_styles("/path/to/user/styles");

Toggle them on or off by name:

lController.toggle_custom_style("Square Corners");

Get a list of currently active custom styles:

LStyleList active = lController.active_custom_styles();

Finding Styles

Find styles by path:

LStyle* button = lController.find_style("Button");

LAttribute* fill = button->find_attribute("Fill");

Iterate through all loaded styles:

for (auto& [path, style] : lController.custom_styles())
    cout << path << endl;

Loading Order

The proper sequence matters:

  1. Load developer styles (via library initializers)
  2. Load user styles with load_user_styles() (optional)

This ensures inheritance resolves and links establish correctly.

Member Function Documentation

LController()

No description available.

~LController()

No description available.

LController(const LController &)

No description available.

LController & operator=(const LController &)

No description available.

LStyleList active_custom_styles()

Returns a list of all currently active custom styles.

LStyle * find_style(const LString & path)

Finds a style by its path.

Returns nullptr if the style is not found.

LStyle * find_style(std::deque<LString> name_list)

Finds a style by a list of path components.

Returns nullptr if the style is not found.

void include(const LString & path, const LString & name_space = "")

Loads styles from the given directory path.

All top-level styles in the set are placed under a namespace node named name_space (so they resolve at "name_space/..."), keeping one library's style names from colliding with another's. Pass an empty name_space (the default) to load them directly at the root.

void include_internal(const LString & path, const LString & name_space = "")

Loads compiled internal (resource-compiled) styles at the given path.

name_space has the same meaning as in include().

LController & instance()

Returns the singleton controller instance.

Prefer using the lController macro instead.

void load_user_styles(const std::filesystem::path & path)

Loads user-created custom styles from the given directory path.

User styles can override developer styles for customization.

LStyle * root_style()

Returns the root style that contains all loaded styles.

std::map<LString, std::unique_ptr<LStyle>> & custom_styles()

Returns a map of all loaded custom styles.

bool toggle_custom_style(const LString & style_id)

Toggles a custom user style on or off.

Returns true if the style was found and toggled successfully.

Appearance
Theme
—