Files
Renderive/web_server/app/Gallery_Session_Control_Adminive.h
T
2026-08-12 06:16:00 +08:00

141 lines
6.1 KiB
C++

#pragma once
#include "Gallery_Session_Control.h"
#include "Gallery_Renderables.h"
#include <concepts>
#include <utility>
namespace renderive::web::gallery_adminive {
template <class Object, class Value, class Reader, class Writer>
auto callback_property(std::string name, std::string label,
adminive::Field_Control control, Reader reader, Writer writer) {
auto accessor = structive::trusted_callable_accessor<Object>(
std::move(reader), std::move(writer));
static_assert(std::same_as<typename decltype(accessor)::value_type, Value>);
return adminive::field(std::move(name), std::move(label), std::move(accessor))
.editable()
.unsynchronized()
.control(control);
}
} // namespace renderive::web::gallery_adminive
namespace adminive {
template <>
struct Type_Descriptor<renderive::web::Gallery_Feedback_Policy> {
static auto get() {
using T = renderive::web::Gallery_Feedback_Policy;
using namespace renderive::web::gallery_adminive;
return adminive::object<T>("feedback_policy", "Consumer feedback",
boolean<&T::enabled>("enabled", "Enabled"),
boolean<&T::pixel>("pixel", "Pixel feedback"),
boolean<&T::presentation>("presentation", "Presentation feedback"),
boolean<&T::manual>("manual", "Manual feedback"),
number<&T::manual_fps>("manual_fps", "Manual FPS"));
}
};
template <>
struct Type_Descriptor<renderive::web::Gallery_Session_Control> {
static auto get() {
using T = renderive::web::Gallery_Session_Control;
using namespace renderive::web::gallery_adminive;
const auto dirty = [](T& value) { value.plot_.notify_model_dirty(); };
return adminive::object<T>("scene", "Scene",
callback_property<T, renderive::Color>(
"background_color", "Background", Field_Control::color,
[](const T& value) { return value.plot_.background_color(); },
[dirty](T& value, renderive::Color color) {
value.plot_.set_background_color(color);
dirty(value);
}),
callback_property<T, bool>(
"performance_overlay", "Performance overlay", Field_Control::boolean,
[](const T& value) {
const auto overlay = value.plot_.performance_overlay();
return overlay && overlay->enabled();
},
[dirty](T& value, bool enabled) {
renderive::set_performance_overlay_enabled(value.plot_, enabled);
dirty(value);
}),
callback_property<T, bool>(
"renderable_visible", "Renderable visible", Field_Control::boolean,
[](const T& value) { return value.renderable_.is_visible(); },
[dirty](T& value, bool visible) {
value.renderable_.set_visible(visible);
dirty(value);
}),
callback_property<T, renderive::Renderable_Cache_Mode>(
"cache_mode", "Cache mode", Field_Control::select,
[](const T& value) { return value.renderable_.get_cache_mode(); },
[dirty](T& value, renderive::Renderable_Cache_Mode mode) {
value.renderable_.set_cache_mode(mode);
dirty(value);
}),
callback_property<T, std::string>(
"object_name", "Object name", Field_Control::text,
[](const T& value) { return value.renderable_.object_name(); },
[dirty](T& value, std::string name) {
value.renderable_.set_object_name(std::move(name));
dirty(value);
}),
callback_property<T, bool>(
"frequency_limit_enabled", "Frequency limit", Field_Control::boolean,
[](const T& value) { return value.plot_.max_render_fps() > 0.0; },
[dirty](T& value, bool enabled) {
if (enabled) {
if (value.plot_.max_render_fps() <= 0.0)
value.plot_.set_max_render_fps(30.0);
} else {
value.plot_.clear_max_render_fps();
}
dirty(value);
}),
callback_property<T, double>(
"max_render_fps", "Maximum render FPS", Field_Control::number,
[](const T& value) {
const double fps = value.plot_.max_render_fps();
return fps > 0.0 ? fps : 30.0;
},
[dirty](T& value, double fps) {
if (value.plot_.max_render_fps() > 0.0)
value.plot_.set_max_render_fps(fps);
dirty(value);
}),
callback_property<T, renderive::web::Gallery_Feedback_Policy>(
"feedback", "Consumer feedback", Field_Control::automatic,
[](const T& value) { return value.feedback_; },
[dirty](T& value, renderive::web::Gallery_Feedback_Policy feedback) {
value.feedback_ = std::move(feedback);
dirty(value);
}));
}
};
static_assert(Described_Type<renderive::web::Gallery_Session_Control>);
static_assert(Direct_Described_Object<renderive::web::Gallery_Session_Control>);
} // namespace adminive
namespace structive {
template <>
struct Type_Descriptor<renderive::web::Gallery_Session_Control> {
static auto get() {
using T = renderive::web::Gallery_Session_Control;
using renderive::web::gallery_action;
return object<T>(type_metadata(
gallery_action("reset", "恢复本图默认值", "Gallery_Scene::rebuild", "Session"),
gallery_action("toggle_view", "切换 View 生命周期",
"Plot_Core::activate_view / deactivate_view", "Session"),
gallery_action("read_data_shape", "读取数据形状",
"Renderable data query / observer telemetry", "Observer")));
}
};
} // namespace structive