diff --git a/gui/package.json b/gui/package.json
index 138723e1b..d7a260d7b 100644
--- a/gui/package.json
+++ b/gui/package.json
@@ -25,6 +25,7 @@
"@twemoji/svg": "^15.0.0",
"browser-fs-access": "^0.35.0",
"classnames": "^2.5.1",
+ "convert": "^5.10.0",
"flatbuffers": "22.10.26",
"intl-pluralrules": "^2.0.1",
"ip-num": "^1.5.1",
diff --git a/gui/public/i18n/en/translation.ftl b/gui/public/i18n/en/translation.ftl
index eb41704bc..057e1ca49 100644
--- a/gui/public/i18n/en/translation.ftl
+++ b/gui/public/i18n/en/translation.ftl
@@ -651,6 +651,11 @@ settings-interface-appearance-font_size-description = This affects the font size
settings-interface-appearance-decorations = Use the system native decorations
settings-interface-appearance-decorations-description = This will not render the top bar of the interface and will use the operating system's instead.
settings-interface-appearance-decorations-label = Use native decorations
+settings-interface-appearance-unit_system = Select unit system
+settings-interface-appearance-unit_system-description = Change if you want to use the metric system or the imperial system for body measurements!
+settings-interface-appearance-unit_system-placeholder = Select the unit system to use
+settings-interface-appearance-unit_system-metric = ( cm - °C ) Metric units
+settings-interface-appearance-unit_system-imperial = ( ' " - °F ) Imperial units
## Notification settings
settings-interface-notifications = Notifications
diff --git a/gui/src/components/commons/Dropdown.tsx b/gui/src/components/commons/Dropdown.tsx
index ec6c5e8d1..c2c055969 100644
--- a/gui/src/components/commons/Dropdown.tsx
+++ b/gui/src/components/commons/Dropdown.tsx
@@ -72,7 +72,7 @@ export function DropdownItems({
{
diff --git a/gui/src/components/commons/HeightDisplay.tsx b/gui/src/components/commons/HeightDisplay.tsx
new file mode 100644
index 000000000..e80755d7f
--- /dev/null
+++ b/gui/src/components/commons/HeightDisplay.tsx
@@ -0,0 +1,71 @@
+import { defaultConfig, UnitType, useConfig } from '@/hooks/config';
+import { useLocaleConfig } from '@/i18n/config';
+import convert from 'convert';
+import { useMemo } from 'react';
+
+export function HeightDisplay({
+ height,
+ /**
+ * Unit type of only the input height
+ */
+ heightUnit = 'm',
+ unitDisplay = 'short',
+ className,
+}: {
+ heightUnit?: 'm' | 'cm' | 'in';
+ height: number;
+ unitDisplay?: 'narrow' | 'short' | 'long';
+ className?: string;
+}) {
+ const { currentLocales } = useLocaleConfig();
+ const { config } = useConfig();
+
+ const cmFormat = useMemo(
+ () =>
+ new Intl.NumberFormat(currentLocales, {
+ style: 'unit',
+ unit: 'centimeter',
+ unitDisplay,
+ maximumFractionDigits: 2,
+ }),
+ [currentLocales, unitDisplay]
+ );
+
+ const [footFormat, inchesFormat] = useMemo(
+ () => [
+ new Intl.NumberFormat(currentLocales, {
+ style: 'unit',
+ unit: 'foot',
+ unitDisplay: 'narrow',
+ maximumFractionDigits: 0,
+ roundingMode: 'trunc',
+ }),
+ new Intl.NumberFormat(currentLocales, {
+ style: 'unit',
+ unit: 'inch',
+ unitDisplay: 'narrow',
+ maximumFractionDigits: 1,
+ roundingMode: 'trunc',
+ }),
+ ],
+ [currentLocales]
+ );
+
+ const value = useMemo(() => {
+ const unitSystem = config?.unitSystem ?? defaultConfig.unitSystem;
+
+ if (unitSystem === UnitType.Metric) {
+ return cmFormat.format(convert(height, heightUnit).to('cm'));
+ } else {
+ const totalInches = convert(height, heightUnit).to('inches');
+ const feet = Math.trunc(totalInches / 12);
+ const remainingInches = totalInches % 12;
+ return (
+ (feet ? footFormat.format(feet) : '') +
+ inchesFormat.format(remainingInches)
+ );
+ }
+ }, [config?.unitSystem, height, heightUnit]);
+
+ return
{value};
+}
diff --git a/gui/src/components/commons/LangSelector.tsx b/gui/src/components/commons/LangSelector.tsx
index aaf6cfa8b..3cf36bbfb 100644
--- a/gui/src/components/commons/LangSelector.tsx
+++ b/gui/src/components/commons/LangSelector.tsx
@@ -1,7 +1,7 @@
import { useLocalization } from '@fluent/react';
import { useEffect, useMemo, useContext } from 'react';
import { useForm } from 'react-hook-form';
-import { useConfig } from '@/hooks/config';
+import { defaultConfig, useConfig } from '@/hooks/config';
import { LangContext } from '@/i18n/config';
import { langs } from '@/i18n/names';
import { Dropdown, DropdownDirection } from './Dropdown';
@@ -17,7 +17,7 @@ export function LangSelector({
const { l10n } = useLocalization();
const { config, setConfig } = useConfig();
const { control, watch, handleSubmit } = useForm<{ lang: string }>({
- defaultValues: { lang: config?.lang || 'en' },
+ defaultValues: { lang: config?.lang ?? defaultConfig.lang },
});
const languagesItems = useMemo(
diff --git a/gui/src/components/commons/NumberSelector.tsx b/gui/src/components/commons/NumberSelector.tsx
index a21d35634..19a9bca5d 100644
--- a/gui/src/components/commons/NumberSelector.tsx
+++ b/gui/src/components/commons/NumberSelector.tsx
@@ -1,7 +1,7 @@
import { Control, Controller } from 'react-hook-form';
import { Button } from './Button';
import { Typography } from './Typography';
-import { useCallback, useMemo } from 'react';
+import { ReactNode, useCallback, useMemo } from 'react';
import { useLocaleConfig } from '@/i18n/config';
export function NumberSelector({
@@ -14,10 +14,10 @@ export function NumberSelector({
step,
doubleStep,
disabled = false,
- showButtonWithNumber = false,
+ showButtonWithNumber,
}: {
label?: string;
- valueLabelFormat?: (value: number) => string;
+ valueLabelFormat?: (value: number) => string | ReactNode;
control: Control
;
name: string;
min: number;
@@ -25,7 +25,7 @@ export function NumberSelector({
step: number | ((value: number, add: boolean) => number);
doubleStep?: number;
disabled?: boolean;
- showButtonWithNumber?: boolean;
+ showButtonWithNumber?: number;
}) {
const { currentLocales } = useLocaleConfig();
@@ -69,8 +69,8 @@ export function NumberSelector({
onClick={() => onChange(doubleStepFn(value, false))}
disabled={doubleStepFn(value, false) < min || disabled}
>
- {showButtonWithNumber
- ? decimalFormat.format(-doubleStep)
+ {showButtonWithNumber !== undefined
+ ? decimalFormat.format(-showButtonWithNumber)
: '--'}
)}
@@ -102,8 +102,8 @@ export function NumberSelector({
onClick={() => onChange(doubleStepFn(value, true))}
disabled={doubleStepFn(value, true) > max || disabled}
>
- {showButtonWithNumber
- ? decimalFormat.format(doubleStep)
+ {showButtonWithNumber !== undefined
+ ? decimalFormat.format(showButtonWithNumber)
: '++'}
)}
diff --git a/gui/src/components/commons/UnitSelector.tsx b/gui/src/components/commons/UnitSelector.tsx
new file mode 100644
index 000000000..9f8c0003b
--- /dev/null
+++ b/gui/src/components/commons/UnitSelector.tsx
@@ -0,0 +1,54 @@
+import { defaultConfig, UnitType, useConfig } from '@/hooks/config';
+import { Dropdown, DropdownDirection } from './Dropdown';
+import { useForm } from 'react-hook-form';
+import { useEffect, useMemo } from 'react';
+import { useLocalization } from '@fluent/react';
+
+export function UnitSelector({
+ direction = 'up',
+ alignment = 'right',
+}: {
+ direction?: DropdownDirection;
+ alignment?: 'right' | 'left';
+}) {
+ const { l10n } = useLocalization();
+ const { config, setConfig } = useConfig();
+ const { control, watch, handleSubmit } = useForm<{ unitSystem: UnitType }>({
+ defaultValues: {
+ unitSystem: config?.unitSystem ?? defaultConfig.unitSystem,
+ },
+ });
+
+ const unitItems = useMemo(
+ () =>
+ Object.values(UnitType).map((type) => ({
+ label: l10n.getString(
+ `settings-interface-appearance-unit_system-${type}`
+ ),
+ value: type,
+ })),
+ [l10n]
+ );
+
+ useEffect(() => {
+ const subscription = watch(() => handleSubmit(onSubmit)());
+ return () => subscription.unsubscribe();
+ }, []);
+
+ const onSubmit = (value: { unitSystem: UnitType }) => {
+ setConfig({ unitSystem: value.unitSystem });
+ };
+
+ return (
+
+ );
+}
diff --git a/gui/src/components/onboarding/pages/Home.tsx b/gui/src/components/onboarding/pages/Home.tsx
index 3c33c21d3..1c5221363 100644
--- a/gui/src/components/onboarding/pages/Home.tsx
+++ b/gui/src/components/onboarding/pages/Home.tsx
@@ -4,6 +4,7 @@ import { Button } from '@/components/commons/Button';
import { SlimeVRIcon } from '@/components/commons/icon/SimevrIcon';
import { LangSelector } from '@/components/commons/LangSelector';
import { Typography } from '@/components/commons/Typography';
+import { UnitSelector } from '@/components/commons/UnitSelector';
export function HomePage() {
const { l10n } = useLocalization();
@@ -23,8 +24,9 @@ export function HomePage() {
{l10n.getString('onboarding-home-start')}
-
+
+
{
reset({
height:
- (currentHeight && currentHeight / EYE_HEIGHT_TO_HEIGHT_RATIO) ||
- DEFAULT_FULL_HEIGHT,
+ (currentHeight &&
+ convert(currentHeight / EYE_HEIGHT_TO_HEIGHT_RATIO, 'm').to(
+ currentUnit
+ )) ||
+ currentUnit === 'm'
+ ? DEFAULT_FULL_HEIGHT
+ : DEFAULT_FULL_HEIGHT_INCHES,
});
}, [currentHeight]);
- const mFormat = useMemo(
- () =>
- new Intl.NumberFormat(currentLocales, {
- style: 'unit',
- unit: 'meter',
- maximumFractionDigits: 2,
- }),
- [currentLocales]
- );
-
const submitFullHeight = (values: HeightForm) => {
- const newHeight = values.height * EYE_HEIGHT_TO_HEIGHT_RATIO;
+ const newHeight =
+ convert(values.height, currentUnit).to('m') * EYE_HEIGHT_TO_HEIGHT_RATIO;
setHmdHeight(newHeight);
const settingsRequest = new ChangeSettingsRequestT();
settingsRequest.modelSettings = new ModelSettingsT(
@@ -104,17 +103,23 @@ export function ManualHeightStep({
'onboarding-scaled_proportions-manual_height-height-v2'
)}
valueLabelFormat={(value) =>
- isNaN(value)
- ? l10n.getString(
- 'onboarding-scaled_proportions-manual_height-unknown'
- )
- : mFormat.format(value)
+ isNaN(value) ? (
+ l10n.getString(
+ 'onboarding-scaled_proportions-manual_height-unknown'
+ )
+ ) : (
+
+ )
}
- min={MIN_HEIGHT}
- max={4}
- step={0.01}
- showButtonWithNumber
- doubleStep={0.1}
+ min={convert(MIN_HEIGHT, 'm').to(currentUnit)}
+ max={convert(4, 'm').to(currentUnit)}
+ step={currentUnit === 'm' ? 0.01 : 1}
+ showButtonWithNumber={currentUnit === 'm' ? 10 : 12}
+ doubleStep={currentUnit === 'm' ? 0.1 : 12}
/>
@@ -124,7 +129,12 @@ export function ManualHeightStep({
)}
- {mFormat.format(height * EYE_HEIGHT_TO_HEIGHT_RATIO)}
+
diff --git a/gui/src/components/settings/pages/InterfaceSettings.tsx b/gui/src/components/settings/pages/InterfaceSettings.tsx
index f8d9ebb7d..9393c2117 100644
--- a/gui/src/components/settings/pages/InterfaceSettings.tsx
+++ b/gui/src/components/settings/pages/InterfaceSettings.tsx
@@ -18,6 +18,7 @@ import { Range } from '@/components/commons/Range';
import { Dropdown } from '@/components/commons/Dropdown';
import { ArrowRightLeftIcon } from '@/components/commons/icon/ArrowIcons';
import { isTrayAvailable } from '@/utils/tauri';
+import { UnitSelector } from '@/components/commons/UnitSelector';
interface InterfaceSettingsForm {
appearance: {
@@ -521,6 +522,20 @@ export function InterfaceSettings() {