Skip to content

Commit ad084ee

Browse files
committed
Update
- New renderer formats. - Added new features of Menu abstract.
1 parent 56c292d commit ad084ee

File tree

6 files changed

+566
-16
lines changed

6 files changed

+566
-16
lines changed

source/abstracts/menu.hpp

+392-16
Large diffs are not rendered by default.

source/core/core-meta.hpp

+42
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
# error "Cell's "common.hpp" was not found!"
2020
#endif
2121

22+
#if __has_include("renderer.hpp")
23+
# include "renderer.hpp"
24+
#else
25+
# error "Cell's "renderer.hpp" was not found!"
26+
#endif
27+
28+
#if __has_include("renderformat.hpp")
29+
# include "renderformat.hpp"
30+
#else
31+
# error "Cell's "renderformat.hpp" was not found!"
32+
#endif
33+
2234
#if __has_include("core-concepts.hpp")
2335
# include "core-concepts.hpp"
2436
#else
@@ -147,6 +159,8 @@ class ContainerCleaner<std::forward_list<T>> {
147159
};
148160

149161
class MetaEngine {
162+
private:
163+
std::unordered_map<std::type_index, std::unique_ptr<System::Renderer>> renderers; ///< Map of renderers for different types.
150164
public:
151165

152166
/**
@@ -314,6 +328,34 @@ class MetaEngine {
314328
return randomString;
315329
}
316330

331+
/**
332+
* @brief Register a renderer for a specific component type.
333+
* @tparam T The type of data the renderer can render.
334+
* @param renderer The renderer to register.
335+
*/
336+
template <typename T>
337+
void registerRenderer(std::unique_ptr<System::Renderer> renderer) {
338+
renderers[typeid(T)] = std::move(renderer);
339+
}
340+
341+
/**
342+
* @brief Render a component using the appropriate renderer.
343+
* @tparam T The type of data to render.
344+
* @param data The data to render.
345+
* @param format The desired rendering format.
346+
* @return A generic result (e.g., std::string, std::vector<uint8_t>, etc.).
347+
* @throws std::runtime_error If no renderer is registered for the given type.
348+
*/
349+
template <typename T>
350+
std::any render(const T& data, System::RenderFormat format) const {
351+
auto it = renderers.find(typeid(T));
352+
if (it == renderers.end()) {
353+
throw std::runtime_error("No renderer registered for this type.");
354+
}
355+
return it->second->render(&data, format);
356+
}
357+
358+
317359
/**
318360
* Enum representing the character sets available for UID generation.
319361
*/

source/core/renderer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "renderer.hpp"

source/core/renderer.hpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*!
2+
* @file renderer.hpp
3+
* @brief This file is part of the Cell Engine.
4+
* @details Renderer system.
5+
* @author <a href='https://github.com/thecompez'>Kambiz Asadzadeh</a>
6+
* @package Genyleap
7+
* @since 16 Jan 2025
8+
* @copyright Copyright (c) 2025 The Genyleap. All rights reserved.
9+
* @license https://github.com/genyleap/cell/blob/main/LICENSE.md
10+
*
11+
*/
12+
13+
#ifndef RENDERER_HPP
14+
#define RENDERER_HPP
15+
16+
#if __has_include("renderformat.hpp")
17+
# include "renderformat.hpp"
18+
#else
19+
# error "Cell's "renderformat.hpp" was not found!"
20+
#endif
21+
22+
#if __has_include("common.hpp")
23+
# include "common.hpp"
24+
#else
25+
# error "Cell's "common.hpp" was not found!"
26+
#endif
27+
28+
CELL_NAMESPACE_BEGIN(Cell::System)
29+
30+
31+
/**
32+
* @class Renderer
33+
* @brief Abstract interface for rendering components in the Cell engine.
34+
*
35+
* This class defines the contract for rendering any component in the engine.
36+
*/
37+
class Renderer {
38+
public:
39+
__cell_virtual ~Renderer() = default;
40+
41+
/**
42+
* @brief Render a component in the specified format.
43+
* @param data The data required to render the component.
44+
* @param format The desired rendering format.
45+
* @return A generic result (e.g., std::string, std::vector<uint8_t>, etc.).
46+
*/
47+
__cell_virtual std::any render(const void* data, RenderFormat format) const = 0;
48+
};
49+
50+
CELL_NAMESPACE_END
51+
52+
#endif // RENDERER_HPP

source/core/renderformat.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "renderformat.hpp"

source/core/renderformat.hpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*!
2+
* @file renderformat.hpp
3+
* @brief This file is part of the Cell Engine.
4+
* @details Renderer system.
5+
* @author <a href='https://github.com/thecompez'>Kambiz Asadzadeh</a>
6+
* @package Genyleap
7+
* @since 16 Jan 2025
8+
* @copyright Copyright (c) 2025 The Genyleap. All rights reserved.
9+
* @license https://github.com/genyleap/cell/blob/main/LICENSE.md
10+
*
11+
*/
12+
13+
#ifndef RENDERFORMAT_HPP
14+
#define RENDERFORMAT_HPP
15+
16+
#if __has_include("common.hpp")
17+
# include "common.hpp"
18+
#else
19+
# error "Cell's "common.hpp" was not found!"
20+
#endif
21+
22+
CELL_NAMESPACE_BEGIN(Cell::System)
23+
24+
/**
25+
* @enum RenderFormat
26+
* @brief Defines the supported rendering formats.
27+
*/
28+
enum class RenderFormat
29+
{
30+
// Basic Formats
31+
32+
HTML, //!< Render as HTML.
33+
QML, //!< Render as QML.
34+
XHTML, //!< Render as XHTML.
35+
JSON, //!< Render as JSON.
36+
XML, //!< Render as XML.
37+
PDF, //!< Render as PDF.
38+
Markdown, //!< Render as Markdown.
39+
40+
// UI Frameworks
41+
42+
React, //!< Render as React components.
43+
Vue, //!< Render as Vue components.
44+
Angular, //!< Render as Angular templates.
45+
Flutter, //!< Render as Flutter widgets.
46+
47+
// Data Formats
48+
49+
YAML, //!< Render as YAML.
50+
CSV, //!< Render as CSV.
51+
Protobuf, //!< Render as Protocol Buffers.
52+
53+
// Graphics and Visualization
54+
55+
SVG, //!< Render as Scalable Vector Graphics.
56+
Canvas, //!< Render as HTML5 Canvas commands.
57+
OpenGL, //!< Render as OpenGL commands.
58+
WebGPU, //!< Render as WebGPU commands.
59+
60+
// Documentation
61+
62+
LaTeX, //!< Render as LaTeX.
63+
AsciiDoc, //!< Render as AsciiDoc.
64+
65+
// Serialization
66+
67+
BSON, //!< Render as Binary JSON.
68+
MessagePack, //!< Render as MessagePack.
69+
70+
// Custom Formats
71+
72+
CustomBinary, //!< Render as a custom binary format.
73+
CustomText //!< Render as a custom text-based format.
74+
};
75+
76+
CELL_NAMESPACE_END
77+
78+
#endif // RENDERFORMAT_HPP

0 commit comments

Comments
 (0)