Lagrange
Common.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/Entity.h>
15#include <lagrange/utils/strings.h>
16#include <string>
17#include <unordered_set>
18
19
20namespace lagrange {
21namespace ui {
22
23
24struct Name
25{
26 operator const std::string&() const { return value; }
27 std::string value;
28};
29
30
32{
34 double t = 0.0;
36 double dt = 0.0;
37};
38
39
40// TODO move to utils:
41
42inline std::string get_name(const Registry& r, Entity e)
43{
44 if (!r.valid(e))
45 return lagrange::string_format("Invalid Entity (ID={})", static_cast<uint64_t>(e));
46 if (!r.all_of<Name>(e))
47 return lagrange::string_format("Unnamed Entity (ID={})", static_cast<uint64_t>(e));
48 return r.get<Name>(e);
49}
50
51inline bool set_name(Registry& r, Entity e, const std::string& name)
52{
53 if (!r.valid(e)) return false;
54 r.emplace_or_replace<Name>(e, name);
55 return true;
56}
57
58inline const GlobalTime& get_time(const Registry& r)
59{
60 return r.ctx().get<GlobalTime>();
61}
62
63
64} // namespace ui
65} // namespace lagrange
std::string string_format(fmt::format_string< Args... > format, Args &&... args)
Format args according to the format string fmt, and return the result as a string.
Definition: strings.h:103
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: Common.h:32
double dt
Time from last frame in seconds.
Definition: Common.h:36
double t
Time from start in seconds.
Definition: Common.h:34
Definition: Common.h:25