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. A specific entrypoint may be specified on platforms which do not understand export conditions.
```ts ```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 = { export type Config = {
free(): void;
isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean, isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean,
setExperimentalFeatureEnabled( setExperimentalFeatureEnabled(
feature: ExperimentalFeature, feature: ExperimentalFeature,
enabled: boolean, enabled: boolean,
): void, ): void,
setPointScaleFactor(factor: number): void, setPointScaleFactor(factor: number): void,
useLegacyStretchBehaviour(): boolean,
setUseLegacyStretchBehaviour(useLegacyStretchBehaviour: boolean): void,
useWebDefaults(): boolean,
setUseWebDefaults(useWebDefaults): void,
}; };
export type MeasureFunction = ( export type MeasureFunction = (
width: number, width: number,
widthMode: number, widthMode: number,
height: number, height: number,
heightMode: number) => Size; heightMode: number
) => Size;
export type Node = { export type Node = {
calculateLayout( calculateLayout(

View File

@@ -32,7 +32,23 @@ void Config::setPointScaleFactor(float pixelsInPoint) {
YGConfigSetPointScaleFactor(m_config, 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 { bool Config::isExperimentalFeatureEnabled(int feature) const {
return YGConfigIsExperimentalFeatureEnabled( return YGConfigIsExperimentalFeatureEnabled(
m_config, static_cast<YGExperimentalFeature>(feature)); 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 public: // Setters
void setExperimentalFeatureEnabled(int feature, bool enabled); void setExperimentalFeatureEnabled(int feature, bool enabled);
void setPointScaleFactor(float pixelsInPoint); void setPointScaleFactor(float pixelsInPoint);
void setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour);
void setUseWebDefaults(bool useWebDefaults);
public: // Getters public: // Getters
bool isExperimentalFeatureEnabled(int feature) const; bool isExperimentalFeatureEnabled(int feature) const;
bool useLegacyStretchBehaviour();
bool useWebDefaults();
private: private:
YGConfigRef m_config; YGConfigRef m_config;

View File

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