ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
Backend.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include "UIContext.hpp"
16
17#include <string>
18#include <string_view>
19
20namespace ZenitUI
21{
25
31 {
32 std::string title{"ZenitUI"};
33 int width{1280};
34 int height{800};
35 int minWidth{0};
36 int minHeight{0};
37 int targetFps{60};
38 bool resizable{true};
39 bool vsync{true};
40 bool msaa{true};
41 };
42
49 {
50 public:
51 virtual ~IBackend() = default;
52
54 virtual bool init(const WindowConfig &config) = 0;
55
57 virtual void shutdown() = 0;
58
60 virtual bool pollFrame() = 0;
61
63 virtual float deltaTime() const = 0;
64
66 virtual void beginDraw(Color clearColor) = 0;
67
69 virtual void endDraw() = 0;
70
72 virtual std::string_view name() const = 0;
73
75 virtual IPlatform &platform() = 0;
76
78 virtual IRenderer &renderer() = 0;
79
81 virtual IAssetProvider &assets() = 0;
82
84 void bindTo(UIContext &ctx)
85 {
86 if (boundCtx_ == &ctx)
87 return;
88 unbind();
89 ctx.attachBackend(&renderer(), &platform(), &assets(), &boundCtx_);
90 }
91
93 void unbind()
94 {
95 if (boundCtx_)
96 boundCtx_->detachBackend();
97 }
98
100 UIContext *boundContext() const { return boundCtx_; }
101
103 bool initAndBind(const WindowConfig &config, UIContext &ctx)
104 {
105 if (!init(config))
106 return false;
107 bindTo(ctx);
108 return true;
109 }
110
111 protected:
112 UIContext *boundCtx_{nullptr};
113 };
114
116} // namespace ZenitUI
Per-application state: renderer, platform, pointer, focus, portals.
Abstract name-based lookup and runtime lifecycle for textures and shaders.
Definition UIContext.hpp:449
Unified window, frame-loop, and subsystem host for interchangeable backends.
Definition Backend.hpp:49
virtual IPlatform & platform()=0
Access the underlying platform adapter.
virtual bool pollFrame()=0
Pump OS events for the next frame; returns false when the window should close.
virtual float deltaTime() const =0
Return the elapsed time in seconds since the previous pollFrame().
virtual void beginDraw(Color clearColor)=0
Begin presenting a frame and clear the main framebuffer to clearColor.
virtual void endDraw()=0
Finish the frame and swap buffers.
bool initAndBind(const WindowConfig &config, UIContext &ctx)
Initialize the backend and bind its adapters to ctx in one step.
Definition Backend.hpp:103
void bindTo(UIContext &ctx)
Attach this backend's adapters to ctx, unbinding any previous context.
Definition Backend.hpp:84
virtual bool init(const WindowConfig &config)=0
Create the window and graphics context, and bind subsystems to UIContext.
virtual void shutdown()=0
Release pooled targets, unbind UIContext, and tear down the window/context.
void unbind()
Flush pooled targets and detach this backend from its bound context.
Definition Backend.hpp:93
virtual IAssetProvider & assets()=0
Access the underlying asset provider.
virtual std::string_view name() const =0
Short human-readable backend identifier (e.g.
virtual IRenderer & renderer()=0
Access the underlying renderer adapter.
UIContext * boundContext() const
Return the currently bound UIContext, or nullptr if unbound.
Definition Backend.hpp:100
Abstract windowing, timing, input, and clipboard backend.
Definition UIContext.hpp:383
Abstract 2D rendering backend.
Definition UIContext.hpp:106
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Per-instance UI context: backends, theme, text engine, frame state, and routing.
Definition UIContext.hpp:725
void attachBackend(IRenderer *r, IPlatform *p, IAssetProvider *a, UIContext **ownerSlot=nullptr)
Attach renderer, platform, and asset backends to this context.
Definition UIContext.hpp:747
Backend-agnostic window and graphics-context creation parameters.
Definition Backend.hpp:31
int targetFps
Hint for backends with built-in frame pacing (0 = uncapped/vsync).
Definition Backend.hpp:37