载入中...
搜索中...
未找到
Component.h
浏览该文件的文档.
1#pragma once
2
3#include "ui/UIHost.h"
4#include "ui/Widget.h"
5
6#include <memory>
7#include <string>
8
9namespace eve::ui {
10
15class Component {
16public:
17 virtual ~Component() = default;
18
19 virtual WidgetDesc build() = 0;
20
21 void attach(UIHost *host);
22 void mountAs(const std::string &hostName);
23 UIHost *host() const { return host_; }
24
26 void rebuild(bool forceFull = false);
27
28 void markDirty() { dirty_ = true; }
29 bool isDirty() const { return dirty_; }
30
32 bool updateIfDirty();
33
34protected:
36 void setState() { dirty_ = true; }
37
38private:
39 UIHost *host_ = nullptr;
40 bool dirty_ = true;
41};
42
43} // namespace eve::ui
React-style UI component: implement build(), call setState / markDirty, then rebuild()....
Definition Component.h:15
bool isDirty() const
Definition Component.h:29
UIHost * host() const
Definition Component.h:23
virtual WidgetDesc build()=0
virtual ~Component()=default
void rebuild(bool forceFull=false)
Rebuild tree onto host (reconcile by key when possible).
Definition Component.cpp:19
void setState()
Subclasses call after mutating local state that affects build().
Definition Component.h:36
void attach(UIHost *host)
Definition Component.cpp:7
void mountAs(const std::string &hostName)
Definition Component.cpp:12
bool updateIfDirty()
If dirty, rebuild and clear flag. Returns true if rebuilt.
Definition Component.cpp:27
ECS mount point for one UI panel/screen. Subclass to attach UI to game entities, e....
Definition UIHost.h:130
Declarative widget description (build once / on dirty → flatten into UIHost::Tree).
Definition Widget.h:13