Add missing config bindings

This commit is contained in:
Nick Gerleman
2022-12-24 08:17:17 -08:00
parent cb4e9492ea
commit de9db1bc03
5 changed files with 36 additions and 6 deletions

View File

@@ -44,7 +44,7 @@ For better performance and smaller packages, WebAssembly is preferred to asm.js
A specific entrypoint may be specified on platforms which do not understand export conditions.
```ts
import { loadYoga } from "yoga-layout/entrypoint/wasm-async";
import { loadYoga } from "yoga-layout/dist/entrypoint/wasm-async";
```

View File

@@ -43,19 +43,25 @@ type Value = {
}
export type Config = {
free(): void;
isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean,
setExperimentalFeatureEnabled(
feature: ExperimentalFeature,
enabled: boolean,
): void,
setPointScaleFactor(factor: number): void,
useLegacyStretchBehaviour(): boolean,
setUseLegacyStretchBehaviour(useLegacyStretchBehaviour: boolean): void,
useWebDefaults(): boolean,
setUseWebDefaults(useWebDefaults): void,
};
export type MeasureFunction = (
width: number,
widthMode: number,
height: number,
heightMode: number) => Size;
heightMode: number
) => Size;
export type Node = {
calculateLayout(

View File

@@ -32,7 +32,23 @@ void Config::setPointScaleFactor(float pixelsInPoint) {
YGConfigSetPointScaleFactor(m_config, pixelsInPoint);
}
void Config::setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour) {
YGConfigSetUseLegacyStretchBehaviour(m_config, useLegacyStretchBehaviour);
}
void Config::setUseWebDefaults(bool useWebDefaults) {
YGConfigSetUseWebDefaults(m_config, useWebDefaults);
}
bool Config::isExperimentalFeatureEnabled(int feature) const {
return YGConfigIsExperimentalFeatureEnabled(
m_config, static_cast<YGExperimentalFeature>(feature));
}
bool Config::useLegacyStretchBehaviour() {
return YGConfigGetUseLegacyStretchBehaviour(m_config);
}
bool Config::useWebDefaults() {
return YGConfigGetUseWebDefaults(m_config);
}

View File

@@ -32,9 +32,13 @@ public: // Prevent accidental copy
public: // Setters
void setExperimentalFeatureEnabled(int feature, bool enabled);
void setPointScaleFactor(float pixelsInPoint);
void setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour);
void setUseWebDefaults(bool useWebDefaults);
public: // Getters
bool isExperimentalFeatureEnabled(int feature) const;
bool useLegacyStretchBehaviour();
bool useWebDefaults();
private:
YGConfigRef m_config;

View File

@@ -32,9 +32,13 @@ EMSCRIPTEN_BINDINGS(YOGA_LAYOUT) {
"setExperimentalFeatureEnabled",
&Config::setExperimentalFeatureEnabled)
.function("setPointScaleFactor", &Config::setPointScaleFactor)
.function("setUseLegacyStretchBehaviour", &Config::setUseLegacyStretchBehaviour)
.function("setUseWebDefaults", &Config::setUseWebDefaults)
.function(
"isExperimentalFeatureEnabled",
&Config::isExperimentalFeatureEnabled);
&Config::isExperimentalFeatureEnabled)
.function("useLegacyStretchBehaviour", &Config::useLegacyStretchBehaviour)
.function("useWebDefaults", &Config::useWebDefaults);
value_object<Layout>("Layout")
.field("left", &Layout::left)