载入中...
搜索中...
未找到
ParentScaler.cpp
浏览该文件的文档.
1#include "ui/ParentScaler.h"
2#include <algorithm>
3#include <cmath>
4#include <simplesquirrel/simplesquirrel.hpp>
6
7// ParentScaler.cpp
8namespace eve::ui {
9
12 if (!state || !output || !settings || !input || !std::isfinite(settings->maxHeight) ||
13 !std::isfinite(input->canvasHeight) || input->targetCount < 0)
16 "ui.parentScaler: objects, finite heights and non-negative target count required"));
17
18 ParentScalerOutput candidate;
19 if (!settings->scaleWithCanvas || !input->hasCanvas || input->targetCount == 0 ||
20 (state->lastScaleHeight == input->canvasHeight && state->lastScaleHeight != 0.f)) {
21 *output = candidate;
22 return Result<void>::success();
23 }
24 candidate.applyHeight = true;
25 candidate.height = input->canvasHeight;
26 if (settings->partScreen) candidate.height = std::min(std::max(input->canvasHeight, 0.1f), settings->maxHeight);
27 state->lastScaleHeight = input->canvasHeight;
28 *output = candidate;
29 return Result<void>::success();
30}
31
32} // namespace eve::ui
33
34// ParentScalerBindings.cpp
35namespace eve::ui {
36
37void exposeParentScalerBindings(ssq::Table& table) {
38 auto settings = table.addClass("ParentScalerSettings", ssq::Class::Ctor<ParentScalerSettings()>());
39 settings.addVar("scaleWithCanvas", &ParentScalerSettings::scaleWithCanvas);
40 settings.addVar("partScreen", &ParentScalerSettings::partScreen);
41 settings.addVar("maxHeight", &ParentScalerSettings::maxHeight);
42 auto input = table.addClass("ParentScalerInput", ssq::Class::Ctor<ParentScalerInput()>());
43 input.addVar("hasCanvas", &ParentScalerInput::hasCanvas);
44 input.addVar("targetCount", &ParentScalerInput::targetCount);
45 input.addVar("canvasHeight", &ParentScalerInput::canvasHeight);
46 auto state = table.addClass("ParentScalerState", ssq::Class::Ctor<ParentScalerState()>());
47 state.addVar("lastScaleHeight", &ParentScalerState::lastScaleHeight);
48 auto output = table.addClass("ParentScalerOutput", ssq::Class::Ctor<ParentScalerOutput()>());
49 output.addVar("applyHeight", &ParentScalerOutput::applyHeight);
50 output.addVar("height", &ParentScalerOutput::height);
51 table.addFunc("evaluateParentScaler",
52 [vm = table.getHandle()](ParentScalerState* state, ParentScalerOutput* output,
54 return eve::script::projectResult(vm, evaluateParentScaler(state, output, settings, input));
55 });
56}
57
58} // namespace eve::ui
std::string output
HSQUIRRELVM vm
Definition ECS.cpp:38
EvpackChunkInput input
Definition Evpack.cpp:170
OceanWakeSettings settings
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
void exposeParentScalerBindings(ssq::Table &table)
Register ParentScaler value types and evaluator with the root script table.
Result< void > evaluateParentScaler(ParentScalerState *state, ParentScalerOutput *output, const ParentScalerSettings *settings, const ParentScalerInput *input)
Evaluate Pcg ParentScaler when canvas height changes.
Current canvas and target-list observation.
Height write emitted for every valid target rect.
Configuration for Pcg ParentScaler canvas-height behavior.
Caller-owned change detector retained across evaluations.