@@ -90,7 +90,7 @@ jobs:
|
|||||||
key: conan-${{ runner.os }}-${{ hashFiles('conanfile.py', 'modulus.json') }}
|
key: conan-${{ runner.os }}-${{ hashFiles('conanfile.py', 'modulus.json') }}
|
||||||
restore-keys: conan-${{ runner.os }}-
|
restore-keys: conan-${{ runner.os }}-
|
||||||
- name: Configure native release
|
- name: Configure native release
|
||||||
run: python3 modulus.py configure --target x86_64_gcc12_release
|
run: python3 modulus.py configure --target x86_64_gcc12_release --update
|
||||||
- name: Check code style
|
- name: Check code style
|
||||||
run: |
|
run: |
|
||||||
python3 -m pip install --no-cache-dir -r build/build_tools/docker/format-requirements.txt
|
python3 -m pip install --no-cache-dir -r build/build_tools/docker/format-requirements.txt
|
||||||
@@ -106,4 +106,4 @@ jobs:
|
|||||||
CONAN_TOKEN: ${{ secrets.CONAN_TOKEN }}
|
CONAN_TOKEN: ${{ secrets.CONAN_TOKEN }}
|
||||||
LUMA_CONAN_UPLOAD: "1"
|
LUMA_CONAN_UPLOAD: "1"
|
||||||
MODULUS_ALLOW_PACKAGE_REPLACE: "1"
|
MODULUS_ALLOW_PACKAGE_REPLACE: "1"
|
||||||
run: python3 modulus.py package --all --replace
|
run: python3 modulus.py package --all --replace --update
|
||||||
|
|||||||
+4
-1
@@ -28,8 +28,11 @@ class luma_conan(conan.ConanFile):
|
|||||||
"fPIC": True,
|
"fPIC": True,
|
||||||
"with_tests": False,
|
"with_tests": False,
|
||||||
}
|
}
|
||||||
exports = "modulus.json"
|
exports = "modulus.json", "!build", "!.git", "!test_package/build"
|
||||||
exports_sources = (
|
exports_sources = (
|
||||||
|
"!build",
|
||||||
|
"!.git",
|
||||||
|
"!test_package/build",
|
||||||
"CMakeLists.txt",
|
"CMakeLists.txt",
|
||||||
"cmake/*.in",
|
"cmake/*.in",
|
||||||
"include/*.hpp",
|
"include/*.hpp",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace luma {
|
|||||||
enum class dialog_result {
|
enum class dialog_result {
|
||||||
NONE,
|
NONE,
|
||||||
ACCEPTED,
|
ACCEPTED,
|
||||||
CANCELLED,
|
CANCELED,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dialog_options {
|
struct dialog_options {
|
||||||
|
|||||||
+37
-73
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# Canonical consumer bootstrap. Copy this file unchanged to a project's modulus.py.
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
@@ -17,6 +18,7 @@ COMMANDS = (
|
|||||||
"lsp",
|
"lsp",
|
||||||
"clangd",
|
"clangd",
|
||||||
"format",
|
"format",
|
||||||
|
"run",
|
||||||
)
|
)
|
||||||
COMMON_DIR = pathlib.Path("build") / "build_common"
|
COMMON_DIR = pathlib.Path("build") / "build_common"
|
||||||
TOOLS_DIR = pathlib.Path("build") / "build_tools"
|
TOOLS_DIR = pathlib.Path("build") / "build_tools"
|
||||||
@@ -66,13 +68,6 @@ def runtime_ready(root):
|
|||||||
and (root / RUNTIME_DIR / "modulus" / "format_layout.py").is_file()
|
and (root / RUNTIME_DIR / "modulus" / "format_layout.py").is_file()
|
||||||
)
|
)
|
||||||
|
|
||||||
def optional_credentials():
|
|
||||||
user = os.environ.get("CONAN_USER")
|
|
||||||
token = os.environ.get("CONAN_TOKEN")
|
|
||||||
if bool(user) != bool(token):
|
|
||||||
raise SystemExit("CONAN_USER and CONAN_TOKEN must either both be set or both be unset")
|
|
||||||
return user, token
|
|
||||||
|
|
||||||
def env_flag(name):
|
def env_flag(name):
|
||||||
return os.environ.get(name, "").lower() in {"1", "true", "yes", "on"}
|
return os.environ.get(name, "").lower() in {"1", "true", "yes", "on"}
|
||||||
|
|
||||||
@@ -128,7 +123,7 @@ RUN python -m pip install --no-cache-dir conan=={CONAN_VERSION}
|
|||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def ensure_fetch_image():
|
def ensure_fetch_image(offline=False):
|
||||||
inspected = subprocess.run(
|
inspected = subprocess.run(
|
||||||
[
|
[
|
||||||
"docker",
|
"docker",
|
||||||
@@ -140,12 +135,15 @@ def ensure_fetch_image():
|
|||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
if inspected.returncode == 0:
|
if inspected.returncode == 0 and (offline or not docker_platform_args()):
|
||||||
return
|
return
|
||||||
|
if offline:
|
||||||
|
raise SystemExit('offline bootstrap requires the existing Modulus fetch image or MODULUS_DIRECT=1 with Conan installed')
|
||||||
run(
|
run(
|
||||||
[
|
[
|
||||||
"docker",
|
"docker",
|
||||||
"build",
|
"build",
|
||||||
|
*docker_platform_args(),
|
||||||
"--tag",
|
"--tag",
|
||||||
FETCH_IMAGE,
|
FETCH_IMAGE,
|
||||||
"-",
|
"-",
|
||||||
@@ -156,6 +154,10 @@ def ensure_fetch_image():
|
|||||||
def in_container():
|
def in_container():
|
||||||
return pathlib.Path("/.dockerenv").exists()
|
return pathlib.Path("/.dockerenv").exists()
|
||||||
|
|
||||||
|
def docker_platform_args():
|
||||||
|
platform = os.environ.get("MODULUS_DOCKER_PLATFORM", "").strip()
|
||||||
|
return ["--platform", platform] if platform else []
|
||||||
|
|
||||||
def docker_workspace_args(root):
|
def docker_workspace_args(root):
|
||||||
if in_container():
|
if in_container():
|
||||||
container = os.environ.get("HOSTNAME", "").strip()
|
container = os.environ.get("HOSTNAME", "").strip()
|
||||||
@@ -172,18 +174,24 @@ def docker_workspace_args(root):
|
|||||||
|
|
||||||
def fetch_env(root):
|
def fetch_env(root):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
|
for name in list(env):
|
||||||
|
if name in {"CONAN_USER", "CONAN_TOKEN"} or name.startswith(("CONAN_LOGIN_USERNAME", "CONAN_PASSWORD")):
|
||||||
|
del env[name]
|
||||||
env["CONAN_HOME"] = str(root / CONAN_HOME_DIR)
|
env["CONAN_HOME"] = str(root / CONAN_HOME_DIR)
|
||||||
|
env["CONAN_NON_INTERACTIVE"] = "1"
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def run_fetch(root, command, capture=False, display_command=None, check=True):
|
def run_fetch(root, command, capture=False, display_command=None, check=True, offline=False):
|
||||||
if direct_mode(root):
|
if direct_mode(root):
|
||||||
return run(command, capture=capture, display_command=display_command, env=fetch_env(root), check=check)
|
return run(command, capture=capture, display_command=display_command, env=fetch_env(root), check=check)
|
||||||
ensure_fetch_image()
|
ensure_fetch_image(offline=offline)
|
||||||
docker_command = [
|
docker_command = [
|
||||||
"docker",
|
"docker",
|
||||||
"run",
|
"run",
|
||||||
"--rm",
|
"--rm",
|
||||||
"--interactive",
|
"--interactive",
|
||||||
|
*(["--pull=never", "--network=none"] if offline else []),
|
||||||
|
*docker_platform_args(),
|
||||||
"--user",
|
"--user",
|
||||||
f"{os.getuid()}:{os.getgid()}",
|
f"{os.getuid()}:{os.getgid()}",
|
||||||
"--env",
|
"--env",
|
||||||
@@ -191,9 +199,7 @@ def run_fetch(root, command, capture=False, display_command=None, check=True):
|
|||||||
"--env",
|
"--env",
|
||||||
"CONAN_HOME",
|
"CONAN_HOME",
|
||||||
"--env",
|
"--env",
|
||||||
"CONAN_USER",
|
"CONAN_NON_INTERACTIVE",
|
||||||
"--env",
|
|
||||||
"CONAN_TOKEN",
|
|
||||||
*docker_workspace_args(root),
|
*docker_workspace_args(root),
|
||||||
"--workdir",
|
"--workdir",
|
||||||
str(root),
|
str(root),
|
||||||
@@ -203,7 +209,6 @@ def run_fetch(root, command, capture=False, display_command=None, check=True):
|
|||||||
return run(docker_command, capture=capture, display_command=display_command, env=fetch_env(root), check=check)
|
return run(docker_command, capture=capture, display_command=display_command, env=fetch_env(root), check=check)
|
||||||
|
|
||||||
def configure_remote(root, remote_name, remote_url):
|
def configure_remote(root, remote_name, remote_url):
|
||||||
user, token = optional_credentials()
|
|
||||||
run_fetch(
|
run_fetch(
|
||||||
root,
|
root,
|
||||||
[
|
[
|
||||||
@@ -215,29 +220,7 @@ def configure_remote(root, remote_name, remote_url):
|
|||||||
remote_url,
|
remote_url,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
if not user and not token:
|
run_fetch(root, ["conan", "remote", "logout", remote_name])
|
||||||
return
|
|
||||||
run_fetch(
|
|
||||||
root,
|
|
||||||
[
|
|
||||||
"conan",
|
|
||||||
"remote",
|
|
||||||
"login",
|
|
||||||
remote_name,
|
|
||||||
user,
|
|
||||||
"-p",
|
|
||||||
token,
|
|
||||||
],
|
|
||||||
display_command=[
|
|
||||||
"conan",
|
|
||||||
"remote",
|
|
||||||
"login",
|
|
||||||
remote_name,
|
|
||||||
user,
|
|
||||||
"-p",
|
|
||||||
"<hidden>",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def package_refs(data):
|
def package_refs(data):
|
||||||
refs = []
|
refs = []
|
||||||
@@ -274,46 +257,26 @@ def package_refs(data):
|
|||||||
refs.append(f"{PACKAGE_REF}#{recipe_revision}:{package_id}")
|
refs.append(f"{PACKAGE_REF}#{recipe_revision}:{package_id}")
|
||||||
return sorted(refs)
|
return sorted(refs)
|
||||||
|
|
||||||
def remove_cached_modulus(root):
|
def find_modulus(root, remote_name=None):
|
||||||
run_fetch(
|
|
||||||
root,
|
|
||||||
[
|
|
||||||
"conan",
|
|
||||||
"remove",
|
|
||||||
PACKAGE_REF + ":*",
|
|
||||||
"-c",
|
|
||||||
],
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
def download_modulus(root, remote_name):
|
|
||||||
remove_cached_modulus(root)
|
|
||||||
run_fetch(
|
|
||||||
root,
|
|
||||||
[
|
|
||||||
"conan",
|
|
||||||
"download",
|
|
||||||
PACKAGE_REF + ":*",
|
|
||||||
"-r",
|
|
||||||
remote_name,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
completed = run_fetch(
|
completed = run_fetch(
|
||||||
root,
|
root,
|
||||||
[
|
[
|
||||||
"conan",
|
"conan",
|
||||||
"list",
|
"list",
|
||||||
PACKAGE_REF + ":*",
|
PACKAGE_REF + "#latest:*#latest",
|
||||||
"-c",
|
*(["-r", remote_name] if remote_name else ["-c"]),
|
||||||
"-f",
|
"-f",
|
||||||
"json",
|
"json",
|
||||||
],
|
],
|
||||||
capture=True,
|
capture=True,
|
||||||
|
offline=remote_name is None,
|
||||||
)
|
)
|
||||||
refs = package_refs(json.loads(completed.stdout))
|
refs = package_refs(json.loads(completed.stdout))
|
||||||
if not refs:
|
if not refs:
|
||||||
raise SystemExit(f"no downloaded {PACKAGE_REF} package found in the Conan cache")
|
raise SystemExit(f"no {PACKAGE_REF} package available in {remote_name or 'the local Conan cache'}")
|
||||||
package_ref = refs[-1]
|
package_ref = refs[-1]
|
||||||
|
if remote_name:
|
||||||
|
run_fetch(root, ["conan", "download", package_ref, "-r", remote_name])
|
||||||
completed = run_fetch(
|
completed = run_fetch(
|
||||||
root,
|
root,
|
||||||
[
|
[
|
||||||
@@ -323,24 +286,25 @@ def download_modulus(root, remote_name):
|
|||||||
package_ref,
|
package_ref,
|
||||||
],
|
],
|
||||||
capture=True,
|
capture=True,
|
||||||
|
offline=remote_name is None,
|
||||||
)
|
)
|
||||||
package_root = pathlib.Path(completed.stdout.strip())
|
package_root = pathlib.Path(completed.stdout.strip())
|
||||||
if not (package_root / "modulus" / "export.py").is_file() or not (package_root / "tools").is_dir():
|
if not (package_root / "modulus" / "export.py").is_file() or not (package_root / "tools").is_dir():
|
||||||
raise SystemExit(f"downloaded {PACKAGE_REF} package does not contain Modulus export files: {package_root}")
|
raise SystemExit(f"downloaded {PACKAGE_REF} package does not contain Modulus export files: {package_root}")
|
||||||
return package_root
|
return package_root
|
||||||
|
|
||||||
def materialize_runtime(root):
|
def materialize_runtime(root, no_remote=False):
|
||||||
remote_name, remote_url = remote_config(root)
|
remote_name, remote_url = remote_config(root)
|
||||||
configure_remote(root, remote_name, remote_url)
|
if not no_remote:
|
||||||
package_root = download_modulus(root, remote_name)
|
configure_remote(root, remote_name, remote_url)
|
||||||
|
package_root = find_modulus(root, None if no_remote else remote_name)
|
||||||
sys.path.insert(0, str(package_root))
|
sys.path.insert(0, str(package_root))
|
||||||
import modulus.export
|
import modulus.export
|
||||||
modulus.export.sync_project(root, package_root)
|
modulus.export.sync_project(root, package_root)
|
||||||
|
|
||||||
def ensure_runtime(root):
|
def ensure_runtime(root, update=False, no_remote=False):
|
||||||
if runtime_ready(root):
|
if update or not runtime_ready(root):
|
||||||
return
|
materialize_runtime(root, no_remote=no_remote)
|
||||||
materialize_runtime(root)
|
|
||||||
|
|
||||||
def delegate(command, argv):
|
def delegate(command, argv):
|
||||||
root = repo_root()
|
root = repo_root()
|
||||||
@@ -349,7 +313,7 @@ def delegate(command, argv):
|
|||||||
print(f"Modulus {command} tooling is missing; run ./modulus.py configure first", file=sys.stderr)
|
print(f"Modulus {command} tooling is missing; run ./modulus.py configure first", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
ensure_runtime(root)
|
ensure_runtime(root, update=command == "configure" and "--update" in argv, no_remote="--no-remote" in argv)
|
||||||
sys.path.insert(0, str(root / RUNTIME_DIR))
|
sys.path.insert(0, str(root / RUNTIME_DIR))
|
||||||
import modulus.cli
|
import modulus.cli
|
||||||
previous_argv = sys.argv
|
previous_argv = sys.argv
|
||||||
|
|||||||
+11
-41
@@ -55,11 +55,7 @@ auto luma::asset_cache::texture(std::string const &path) -> std::expected<std::s
|
|||||||
assert(cached->second != nullptr);
|
assert(cached->second != nullptr);
|
||||||
return modulus::success(cached->second);
|
return modulus::success(cached->second);
|
||||||
}
|
}
|
||||||
if (!loading->result) {
|
return loading->result;
|
||||||
return modulus::fail<std::shared_ptr<luma::texture>>(loading->result.error());
|
|
||||||
}
|
|
||||||
assert(*loading->result != nullptr);
|
|
||||||
return modulus::success(*loading->result);
|
|
||||||
}
|
}
|
||||||
loading = std::make_shared<luma::asset_cache::in_flight_load>();
|
loading = std::make_shared<luma::asset_cache::in_flight_load>();
|
||||||
loading->owner = std::this_thread::get_id();
|
loading->owner = std::this_thread::get_id();
|
||||||
@@ -75,49 +71,23 @@ auto luma::asset_cache::texture(std::string const &path) -> std::expected<std::s
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
loaded = luma::detail::fail<std::shared_ptr<luma::texture>>(luma::detail::error_internal, "texture load failed with an unknown exception");
|
loaded = luma::detail::fail<std::shared_ptr<luma::texture>>(luma::detail::error_internal, "texture load failed with an unknown exception");
|
||||||
}
|
}
|
||||||
|
if (loaded && !*loaded) {
|
||||||
|
loaded = luma::detail::fail<std::shared_ptr<luma::texture>>(luma::detail::error_not_found, "texture load returned no texture: " + path);
|
||||||
|
}
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
modulus::log_debug("luma texture load failed: " + path);
|
modulus::log_debug("luma texture load failed: " + path);
|
||||||
|
}
|
||||||
|
{
|
||||||
auto lock = std::scoped_lock{mutex_};
|
auto lock = std::scoped_lock{mutex_};
|
||||||
loading->result = modulus::fail<std::shared_ptr<luma::texture>>(loaded.error());
|
if (loaded && generation == generation_) {
|
||||||
|
loaded = textures_.emplace(path, *loaded).first->second;
|
||||||
|
}
|
||||||
|
loading->result = loaded;
|
||||||
loading->done = true;
|
loading->done = true;
|
||||||
loading_.erase(path);
|
loading_.erase(path);
|
||||||
loading->ready.notify_all();
|
|
||||||
return loaded;
|
|
||||||
}
|
}
|
||||||
if (*loaded == nullptr) {
|
|
||||||
modulus::log_debug("luma texture load returned null: " + path);
|
|
||||||
auto result = luma::detail::fail<std::shared_ptr<luma::texture>>(luma::detail::error_not_found, "texture load returned no texture: " + path);
|
|
||||||
auto lock = std::scoped_lock{mutex_};
|
|
||||||
loading->result = modulus::fail<std::shared_ptr<luma::texture>>(result.error());
|
|
||||||
loading->done = true;
|
|
||||||
loading_.erase(path);
|
|
||||||
loading->ready.notify_all();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
auto texture = *loaded;
|
|
||||||
auto lock = std::scoped_lock{mutex_};
|
|
||||||
if (auto found = textures_.find(path); found != textures_.end()) {
|
|
||||||
assert(found->second != nullptr);
|
|
||||||
loading->result = modulus::success(found->second);
|
|
||||||
loading->done = true;
|
|
||||||
loading_.erase(path);
|
|
||||||
loading->ready.notify_all();
|
|
||||||
return modulus::success(found->second);
|
|
||||||
}
|
|
||||||
if (generation != generation_) {
|
|
||||||
loading->result = modulus::success(texture);
|
|
||||||
loading->done = true;
|
|
||||||
loading_.erase(path);
|
|
||||||
loading->ready.notify_all();
|
|
||||||
return modulus::success(std::move(texture));
|
|
||||||
}
|
|
||||||
auto inserted = textures_.emplace(path, std::move(texture));
|
|
||||||
assert(inserted.first->second != nullptr);
|
|
||||||
loading->result = modulus::success(inserted.first->second);
|
|
||||||
loading->done = true;
|
|
||||||
loading_.erase(path);
|
|
||||||
loading->ready.notify_all();
|
loading->ready.notify_all();
|
||||||
return modulus::success(inserted.first->second);
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto luma::asset_cache::clear() -> void {
|
auto luma::asset_cache::clear() -> void {
|
||||||
|
|||||||
+1
-1
@@ -323,7 +323,7 @@ auto luma::overlay_host::handle_touch(luma::touch_event const &event) -> std::bo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (has_cancel && first_point_inside(event, cancel_bounds(bounds()), luma::touch_phase::UP) != nullptr) {
|
if (has_cancel && first_point_inside(event, cancel_bounds(bounds()), luma::touch_phase::UP) != nullptr) {
|
||||||
throw_if_failed(close_dialog(luma::dialog_result::CANCELLED));
|
throw_if_failed(close_dialog(luma::dialog_result::CANCELED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (dialog_->body && any_point_inside(event, dialog_body_bounds(bounds()))) {
|
if (dialog_->body && any_point_inside(event, dialog_body_bounds(bounds()))) {
|
||||||
|
|||||||
+21
-42
@@ -4,7 +4,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
#include <optional>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -60,7 +60,14 @@ auto apply_color(boost::json::object const &object, std::char_t const *name, lum
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto number_value(boost::json::value const &value) -> std::optional<std::float64_t>;
|
auto apply_number(boost::json::object const &object, std::char_t const *name, std::float32_t &target) -> std::expected<void, modulus::error> {
|
||||||
|
auto value = modulus::json_config::optional_float64_field(object, name, target, 0.0, std::numeric_limits<std::float32_t>::max(), json_options);
|
||||||
|
if (!value) {
|
||||||
|
return modulus::fail<void>(value.error());
|
||||||
|
}
|
||||||
|
target = static_cast<std::float32_t>(*value);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto apply_text_style(boost::json::object const &object, std::char_t const *name, luma::text_style &target) -> std::expected<void, modulus::error> {
|
auto apply_text_style(boost::json::object const &object, std::char_t const *name, luma::text_style &target) -> std::expected<void, modulus::error> {
|
||||||
assert(name != nullptr);
|
assert(name != nullptr);
|
||||||
@@ -78,41 +85,21 @@ auto apply_text_style(boost::json::object const &object, std::char_t const *name
|
|||||||
if (!unknown) {
|
if (!unknown) {
|
||||||
return modulus::fail<void>(unknown.error());
|
return modulus::fail<void>(unknown.error());
|
||||||
}
|
}
|
||||||
if (auto const *font = (*style)->if_contains("font")) {
|
auto font = modulus::json_config::optional_string_field(**style, "font", target.font, json_options);
|
||||||
auto const *text = font->if_string();
|
if (!font) {
|
||||||
if (text == nullptr) {
|
return modulus::fail<void>(font.error());
|
||||||
return luma::detail::fail<void>(luma::detail::error_invalid_argument, std::string{name} + ".font must be a string");
|
|
||||||
}
|
|
||||||
target.font = std::string{text->c_str()};
|
|
||||||
}
|
}
|
||||||
if (auto const *size = (*style)->if_contains("size")) {
|
target.font = std::move(*font);
|
||||||
auto number = number_value(*size);
|
if (auto status = apply_number(**style, "size", target.size); !status) {
|
||||||
if (!number || *number <= 0.0) {
|
return status;
|
||||||
return luma::detail::fail<void>(luma::detail::error_invalid_argument, std::string{name} + ".size must be positive");
|
|
||||||
}
|
|
||||||
target.size = static_cast<std::float32_t>(*number);
|
|
||||||
}
|
}
|
||||||
if (auto const *line_height = (*style)->if_contains("line_height")) {
|
if (auto status = apply_number(**style, "line_height", target.line_height); !status) {
|
||||||
auto number = number_value(*line_height);
|
return status;
|
||||||
if (!number || *number <= 0.0) {
|
|
||||||
return luma::detail::fail<void>(luma::detail::error_invalid_argument, std::string{name} + ".line_height must be positive");
|
|
||||||
}
|
|
||||||
target.line_height = static_cast<std::float32_t>(*number);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto number_value(boost::json::value const &value) -> std::optional<std::float64_t> {
|
|
||||||
if (auto const *number = value.if_double()) {
|
|
||||||
return *number;
|
|
||||||
}
|
|
||||||
if (auto const *integer = value.if_int64()) {
|
|
||||||
return static_cast<std::float64_t>(*integer);
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto luma::default_theme() -> luma::theme {
|
auto luma::default_theme() -> luma::theme {
|
||||||
@@ -247,19 +234,11 @@ auto luma::parse_theme(boost::json::value const &value) -> std::expected<luma::t
|
|||||||
if (auto status = apply_text_style(**object, "title", parsed.title); !status) {
|
if (auto status = apply_text_style(**object, "title", parsed.title); !status) {
|
||||||
return invalid_theme(std::string{status.error().message()});
|
return invalid_theme(std::string{status.error().message()});
|
||||||
}
|
}
|
||||||
if (auto const *radius = (*object)->if_contains("radius")) {
|
if (auto status = apply_number(**object, "radius", parsed.radius); !status) {
|
||||||
auto number = number_value(*radius);
|
return std::unexpected(status.error());
|
||||||
if (!number || *number < 0.0) {
|
|
||||||
return invalid_theme("theme.radius must be non-negative");
|
|
||||||
}
|
|
||||||
parsed.radius = static_cast<std::float32_t>(*number);
|
|
||||||
}
|
}
|
||||||
if (auto const *spacing = (*object)->if_contains("spacing")) {
|
if (auto status = apply_number(**object, "spacing", parsed.spacing); !status) {
|
||||||
auto number = number_value(*spacing);
|
return std::unexpected(status.error());
|
||||||
if (!number || *number < 0.0) {
|
|
||||||
return invalid_theme("theme.spacing must be non-negative");
|
|
||||||
}
|
|
||||||
parsed.spacing = static_cast<std::float32_t>(*number);
|
|
||||||
}
|
}
|
||||||
if (auto status = luma::validate(parsed); !status) {
|
if (auto status = luma::validate(parsed); !status) {
|
||||||
return invalid_theme(std::string{status.error().message()});
|
return invalid_theme(std::string{status.error().message()});
|
||||||
|
|||||||
+59
-2
@@ -564,7 +564,7 @@ auto closing_dialog_control::close_if(close_phase phase) const -> void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state_->in_handle = true;
|
state_->in_handle = true;
|
||||||
auto status = host_.close_dialog(luma::dialog_result::CANCELLED);
|
auto status = host_.close_dialog(luma::dialog_result::CANCELED);
|
||||||
state_->status_ok = status.has_value();
|
state_->status_ok = status.has_value();
|
||||||
state_->in_handle = false;
|
state_->in_handle = false;
|
||||||
}
|
}
|
||||||
@@ -1085,6 +1085,63 @@ BOOST_AUTO_TEST_CASE(asset_cache_rejects_recursive_same_path_load) {
|
|||||||
BOOST_TEST(resources.recursive_code == 3);
|
BOOST_TEST(resources.recursive_code == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(asset_cache_clear_does_not_retain_an_in_flight_texture) {
|
||||||
|
auto resources = blocking_resources{};
|
||||||
|
auto assets = luma::asset_cache{resources};
|
||||||
|
auto first = std::expected<std::shared_ptr<luma::texture>, modulus::error>{};
|
||||||
|
auto thread = std::thread{[&] { first = assets.texture("page.png"); }};
|
||||||
|
auto entered = resources.wait_for_loads(1);
|
||||||
|
assets.clear();
|
||||||
|
resources.release();
|
||||||
|
thread.join();
|
||||||
|
BOOST_REQUIRE(entered);
|
||||||
|
BOOST_REQUIRE(first);
|
||||||
|
auto second = assets.texture("page.png");
|
||||||
|
BOOST_REQUIRE(second);
|
||||||
|
BOOST_TEST(resources.load_count() == 2);
|
||||||
|
BOOST_TEST(*first != *second);
|
||||||
|
BOOST_REQUIRE(assets.texture("page.png"));
|
||||||
|
BOOST_TEST(resources.load_count() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(asset_cache_failed_loads_complete_and_can_be_retried) {
|
||||||
|
struct resources final : luma::renderer_resources {
|
||||||
|
std::uint32_t calls{};
|
||||||
|
auto load_texture(std::string const &path) -> std::expected<std::shared_ptr<luma::texture>, modulus::error> override {
|
||||||
|
if (++calls == 1U) {
|
||||||
|
if (path == "null") {
|
||||||
|
return std::shared_ptr<luma::texture>{};
|
||||||
|
}
|
||||||
|
if (path == "throw") {
|
||||||
|
throw std::runtime_error{"loader failed"};
|
||||||
|
}
|
||||||
|
return std::unexpected(modulus::make_error("loader", 5, "failed"));
|
||||||
|
}
|
||||||
|
return std::make_shared<fake_texture>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto const *path : {"null", "throw", "error"}) {
|
||||||
|
auto loader = resources{};
|
||||||
|
auto assets = luma::asset_cache{loader};
|
||||||
|
BOOST_CHECK(!assets.texture(path));
|
||||||
|
BOOST_REQUIRE(assets.texture(path));
|
||||||
|
BOOST_REQUIRE(assets.texture(path));
|
||||||
|
BOOST_TEST(loader.calls == 2U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(theme_numbers_reject_nonfinite_and_unrepresentable_values) {
|
||||||
|
for (auto number : {-1.0, std::numeric_limits<double>::infinity(), std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::max()}) {
|
||||||
|
auto parsed = luma::parse_theme(boost::json::object{{"spacing", number}});
|
||||||
|
BOOST_REQUIRE(!parsed);
|
||||||
|
BOOST_TEST(std::string{parsed.error().category()} == "luma");
|
||||||
|
}
|
||||||
|
auto parsed = luma::parse_theme(boost::json::object{{"spacing", std::uint64_t{8}}});
|
||||||
|
BOOST_REQUIRE(parsed);
|
||||||
|
BOOST_TEST(parsed->spacing == 8.0F);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(text_input_state_filters_modes_and_keyboard_updates_bound_field) {
|
BOOST_AUTO_TEST_CASE(text_input_state_filters_modes_and_keyboard_updates_bound_field) {
|
||||||
auto changes = std::vector<std::string>{};
|
auto changes = std::vector<std::string>{};
|
||||||
auto input = luma::make_text_input({
|
auto input = luma::make_text_input({
|
||||||
@@ -1270,7 +1327,7 @@ BOOST_AUTO_TEST_CASE(dialog_accept_and_cancel_close_with_callbacks) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
BOOST_TEST(static_cast<std::int32_t>(result) == static_cast<std::int32_t>(luma::dialog_result::CANCELLED));
|
BOOST_TEST(static_cast<std::int32_t>(result) == static_cast<std::int32_t>(luma::dialog_result::CANCELED));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(dialog_uses_matching_touch_when_not_first_point) {
|
BOOST_AUTO_TEST_CASE(dialog_uses_matching_touch_when_not_first_point) {
|
||||||
|
|||||||
Reference in New Issue
Block a user