From 86e58449c278b694fb3405c859be6efbbac97f3b Mon Sep 17 00:00:00 2001 From: Jonathan Steffan Date: Sat, 25 Jul 2026 11:56:18 -0600 Subject: [PATCH 001/147] feat(vulkan): use distro Vulkan packages instead of setup-vulkan-sdk With the pinned SDK gone, CI builds against distro headers, so raise the server requirement to 1.4.304 to match what is actually tested and supported: Ubuntu 26.04 has 1.4.341, the Ubuntu package build (plucky) has 1.4.304, as does Debian 13. This subsumes the separate 1.3.283 check for Vulkan video encode, and makes VK_HEADER_VERSION >= 304 always true for the server. The client conditionals stay, it is built for Android against the 1.3.268 headers fetched in common/CMakeLists.txt. --- .github/workflows/APK-Release.yml | 9 +-------- .github/workflows/Build.yml | 21 +++------------------ CMakeLists.txt | 10 ++-------- debian/control | 2 +- server/utils/wivrn_vk_bundle.cpp | 6 ------ 5 files changed, 7 insertions(+), 41 deletions(-) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 49ce4cf4..bf2ec47a 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -25,16 +25,9 @@ jobs: ref: ${{ github.sha }} fetch-depth: 0 - - name: Prepare Vulkan SDK - uses: humbletim/setup-vulkan-sdk@v1.2.1 - with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Glslang, SPIRV-Tools - vulkan-use-cache: true - - name: Install dependencies run: | - sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext npm + sudo apt-get update && sudo apt-get install glslang-tools spirv-tools librsvg2-bin gettext npm wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.4.0/KTX-Software-4.4.0-Linux-x86_64.deb sudo dpkg --install KTX-Software-4.4.0-Linux-x86_64.deb npm install --global @gltf-transform/cli@4.1.1 diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index da376320..86d5ae66 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -30,7 +30,6 @@ jobs: # Perfetto SDK glue don't bitrot (WIVRN_TRACE_MONADO needs percetto, not packaged in CI) - preset: 'server-tracing' packages: libboost-all-dev libsystemd-dev - perfetto: true - preset: 'server-no-systemd' packages: libboost-all-dev - preset: 'server-no-system-boost' @@ -42,7 +41,7 @@ jobs: - name: Apt dependencies uses: awalsh128/cache-apt-pkgs-action@v1.6.1 with: - packages: ccache ${{matrix.config.packages}} ${{ startsWith(matrix.config.preset, 'server') && env.SERVER_DEPS || ''}} + packages: ccache libvulkan-dev glslang-tools spirv-tools libwayland-dev libxrandr-dev ${{matrix.config.packages}} ${{ startsWith(matrix.config.preset, 'server') && env.SERVER_DEPS || ''}} - name: ccache uses: hendrikmuhs/ccache-action@v1.2.23 @@ -69,15 +68,8 @@ jobs: sudo dpkg --install KTX-Software-4.4.2-Linux-x86_64.deb npm install --global @gltf-transform/cli@4.1.1 - - name: Prepare Vulkan SDK - uses: humbletim/setup-vulkan-sdk@v1.2.1 - with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang, SPIRV-Reflect, SPIRV-Tools - vulkan-use-cache: true - - name: Fetch Perfetto SDK - if: ${{ matrix.config.perfetto }} + if: ${{ matrix.config.preset == 'server-tracing' }} # The amalgamated SDK is two files; install them where server/CMakeLists.txt looks. env: PERFETTO_TAG: v51.0 @@ -192,13 +184,6 @@ jobs: with: fetch-depth: 0 - - name: Prepare Vulkan SDK - uses: humbletim/setup-vulkan-sdk@v1.2.1 - with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Glslang, SPIRV-Tools - vulkan-use-cache: true - - uses: actions/cache@v5 with: key: cmake-android-${{matrix.buildtype}} @@ -212,7 +197,7 @@ jobs: - name: Install dependencies run: | - sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext + sudo apt-get update && sudo apt-get install glslang-tools spirv-tools librsvg2-bin gettext wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.3.2/KTX-Software-4.3.2-Linux-x86_64.deb sudo dpkg --install KTX-Software-4.3.2-Linux-x86_64.deb npm install --global @gltf-transform/cli diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ddb7d23..57b16fd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,8 +123,8 @@ endif() if (WIVRN_BUILD_SERVER) find_program(GDBUS_CODEGEN gdbus-codegen REQUIRED) - if (Vulkan_VERSION VERSION_LESS "1.3.261") - message(FATAL_ERROR "Vulkan version must be at least 1.3.261, found ${Vulkan_VERSION}") + if (Vulkan_VERSION VERSION_LESS "1.4.304") + message(FATAL_ERROR "Vulkan version must be at least 1.4.304, found ${Vulkan_VERSION}") endif() if (NOT WIVRN_USE_NVENC AND NOT WIVRN_USE_VAAPI AND NOT WIVRN_USE_X264 AND NOT WIVRN_USE_VULKAN_ENCODE) @@ -136,12 +136,6 @@ if (WIVRN_BUILD_SERVER) pkg_check_modules(LIBDRM REQUIRED IMPORTED_TARGET libdrm) endif() - if (WIVRN_USE_VULKAN_ENCODE) - if (Vulkan_VERSION VERSION_LESS 1.3.283) - message(FATAL_ERROR "Vulkan video encode requires 1.3.283, found ${Vulkan_VERSION}") - endif() - endif() - if (WIVRN_USE_X264) pkg_check_modules(X264 REQUIRED IMPORTED_TARGET x264) endif() diff --git a/debian/control b/debian/control index dc17a4ef..5e444d43 100644 --- a/debian/control +++ b/debian/control @@ -29,7 +29,7 @@ Build-Depends: libsystemd-dev, libudev-dev, libva-dev, - libvulkan-dev (>= 1.3.261), + libvulkan-dev (>= 1.4.304), libwayland-dev, libx11-xcb-dev, libx264-dev, diff --git a/server/utils/wivrn_vk_bundle.cpp b/server/utils/wivrn_vk_bundle.cpp index a99000b3..6c0b2104 100644 --- a/server/utils/wivrn_vk_bundle.cpp +++ b/server/utils/wivrn_vk_bundle.cpp @@ -36,15 +36,9 @@ namespace { VkBool32 message_callback( -#if VK_HEADER_VERSION >= 304 vk::DebugUtilsMessageSeverityFlagBitsEXT messageSeverity, vk::DebugUtilsMessageTypeFlagsEXT messageTypes, const vk::DebugUtilsMessengerCallbackDataEXT * pCallbackData, -#else - VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, - VkDebugUtilsMessageTypeFlagsEXT messageTypes, - const VkDebugUtilsMessengerCallbackDataEXT * pCallbackData, -#endif void * pUserData) { u_logging_level level = U_LOGGING_ERROR; From 04639417c4202f199f839e92e94c9fd9b1c70fce Mon Sep 17 00:00:00 2001 From: Jonathan Steffan Date: Sat, 25 Jul 2026 12:19:42 -0600 Subject: [PATCH 002/147] fix(flatpak): add source mirrors and match the container to the runtime The toolchain tarballs are each fetched from a single host, and ftpmirror.gnu.org timing out failed the whole job. Add mirror-urls fallbacks where a byte-identical alternate host exists. Also bump the builder container to kde-6.10, matching runtime-version in the manifest. --- .github/workflows/Build.yml | 3 ++- flatpak/io.github.wivrn.wivrn.yml.in | 32 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 86d5ae66..af952c99 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -122,7 +122,8 @@ jobs: runs-on: ubuntu-24.04 if: ${{ vars.APK_ONLY == '' }} container: - image: ghcr.io/flathub-infra/flatpak-github-actions:kde-6.9 + # Tag matches runtime-version in the manifest. + image: ghcr.io/flathub-infra/flatpak-github-actions:kde-6.10 options: --privileged steps: diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index e6a53101..41bbc571 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -102,8 +102,11 @@ modules: - name: toolchain sources: + # mirror-urls are fallbacks, used when the primary url fails. - type: file url: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.177.tar.xz + mirror-urls: + - https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.15.177.tar.xz sha256: ea9eb8088d4231f8a01b191ceef5f4d92238f6c7519f6fbcb57e448ee9e0a6e0 - type: file url: https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.xz @@ -113,34 +116,63 @@ modules: sha256: 8c29e06cf42aacc1eafc4077ae2ec6c6fcb96a626157e0593d5e82a34fd403c1 - type: file url: https://ftpmirror.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz + mirror-urls: + - https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz + - https://mirrors.kernel.org/gnu/gmp/gmp-6.3.0.tar.xz sha256: a3c2b80201b89e68616f4ad30bc66aee4927c3ce50e33929ca819d5c43538898 - type: file url: https://www.mpfr.org/mpfr-4.2.1/mpfr-4.2.1.tar.xz + mirror-urls: + - https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz + - https://mirrors.kernel.org/gnu/mpfr/mpfr-4.2.1.tar.xz sha256: 277807353a6726978996945af13e52829e3abd7a9a5b7fb2793894e18f1fcbb2 - type: file dest-filename: isl-0.26.tar.xz url: https://sourceforge.net/projects/libisl/files/isl-0.26.tar.xz/download + mirror-urls: + - https://libisl.sourceforge.io/isl-0.26.tar.xz sha256: a0b5cb06d24f9fa9e77b55fabbe9a3c94a336190345c2555f9915bb38e976504 - type: file url: https://ftpmirror.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz + mirror-urls: + - https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz + - https://mirrors.kernel.org/gnu/mpc/mpc-1.3.1.tar.gz sha256: ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8 - type: file url: https://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz + mirror-urls: + - https://ftp.gnu.org/gnu/ncurses/ncurses-6.4.tar.gz + - https://mirrors.kernel.org/gnu/ncurses/ncurses-6.4.tar.gz sha256: 6931283d9ac87c5073f30b6290c4c75f21632bb4fc3603ac8100812bed248159 - type: file url: https://ftpmirror.gnu.org/gnu/libiconv/libiconv-1.16.tar.gz + mirror-urls: + - https://ftp.gnu.org/gnu/libiconv/libiconv-1.16.tar.gz + - https://mirrors.kernel.org/gnu/libiconv/libiconv-1.16.tar.gz sha256: e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04 - type: file url: https://ftpmirror.gnu.org/gnu/gettext/gettext-0.23.1.tar.xz + mirror-urls: + - https://ftp.gnu.org/gnu/gettext/gettext-0.23.1.tar.xz + - https://mirrors.kernel.org/gnu/gettext/gettext-0.23.1.tar.xz sha256: c1f97a72a7385b7e71dd07b5fea6cdaf12c9b88b564976b23bd8c11857af2970 - type: file url: https://ftpmirror.gnu.org/gnu/binutils/binutils-2.43.1.tar.xz + mirror-urls: + - https://ftp.gnu.org/gnu/binutils/binutils-2.43.1.tar.xz + - https://mirrors.kernel.org/gnu/binutils/binutils-2.43.1.tar.xz sha256: 13f74202a3c4c51118b797a39ea4200d3f6cfbe224da6d1d95bb938480132dfd - type: file url: https://ftpmirror.gnu.org/gnu/gcc/gcc-11.5.0/gcc-11.5.0.tar.xz + mirror-urls: + - https://ftp.gnu.org/gnu/gcc/gcc-11.5.0/gcc-11.5.0.tar.xz + - https://mirrors.kernel.org/gnu/gcc/gcc-11.5.0/gcc-11.5.0.tar.xz sha256: a6e21868ead545cf87f0c01f84276e4b5281d672098591c1c896241f09363478 - type: file url: https://ftpmirror.gnu.org/gnu/glibc/glibc-2.35.tar.xz + mirror-urls: + - https://ftp.gnu.org/gnu/glibc/glibc-2.35.tar.xz + - https://mirrors.kernel.org/gnu/glibc/glibc-2.35.tar.xz sha256: 5123732f6b67ccd319305efd399971d58592122bcc2a6518a1bd2510dd0cf52e - type: file path: ct-ng-x86_64.config From d747f4dd04835d2b88957d57a22399aee163f97e Mon Sep 17 00:00:00 2001 From: Jonathan Steffan Date: Sat, 25 Jul 2026 13:49:22 -0600 Subject: [PATCH 003/147] fix(android): cache the gradle distribution and dependencies Every Android job downloads gradle-8.13-bin.zip and the whole Android plugin dependency tree from Maven Central on each run, so a Maven Central 403 fails the build before it configures anything: Could not GET '.../kotlin-stdlib-2.2.0.pom'. Received status code 403 from server: Forbidden Cache ~/.gradle/caches and ~/.gradle/wrapper, keyed on the wrapper properties and build.gradle. --- .github/workflows/APK-Release.yml | 9 +++++++++ .github/workflows/Build.yml | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index bf2ec47a..ffc7a338 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -25,6 +25,15 @@ jobs: ref: ${{ github.sha }} fetch-depth: 0 + # Gradle distribution and the Android plugin's dependencies. + - uses: actions/cache@v5 + with: + key: gradle-android-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'build.gradle') }} + path: | + ~/.gradle/caches + ~/.gradle/wrapper + restore-keys: gradle-android- + - name: Install dependencies run: | sudo apt-get update && sudo apt-get install glslang-tools spirv-tools librsvg2-bin gettext npm diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index af952c99..7e561ad1 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -196,6 +196,15 @@ jobs: ${{github.workspace}}/cmake-fetch/*.tgz restore-keys: cmake-android- + # Gradle distribution and the Android plugin's dependencies. + - uses: actions/cache@v5 + with: + key: gradle-android-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'build.gradle') }} + path: | + ~/.gradle/caches + ~/.gradle/wrapper + restore-keys: gradle-android- + - name: Install dependencies run: | sudo apt-get update && sudo apt-get install glslang-tools spirv-tools librsvg2-bin gettext From 44879e45abbccbe55ab5d2e5eecc7f87027a6791 Mon Sep 17 00:00:00 2001 From: ahsanswr Date: Sat, 13 Jun 2026 14:05:00 +0500 Subject: [PATCH 004/147] Add new UI framework --- client/render/imgui_impl.cpp | 17 +- client/render/ui_theme.cpp | 219 +++++++ client/render/ui_theme.h | 126 ++++ client/render/ui_widgets.cpp | 863 +++++++++++++++++++++++++ client/render/ui_widgets.h | 121 ++++ client/scenes/lobby.h | 2 + client/scenes/lobby_gui.cpp | 27 +- client/scenes/lobby_gui_components.cpp | 324 ++++++++++ 8 files changed, 1697 insertions(+), 2 deletions(-) create mode 100644 client/render/ui_theme.cpp create mode 100644 client/render/ui_theme.h create mode 100644 client/render/ui_widgets.cpp create mode 100644 client/render/ui_widgets.h create mode 100644 client/scenes/lobby_gui_components.cpp diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 31a15ffb..f78f5ca5 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -1329,9 +1329,22 @@ void ScrollWhenDragging() static int active_id; static ImVec2 cumulated_delta; + // Suppress drag-scroll while a popup is open and for the frame one closes: in VR + // the ray snaps from the popup layer back to this window when the popup dismisses, + // which can synthesise a spurious click (see the focused-controller handling) that + // would otherwise start a scroll right after picking a combo value. + static bool popup_was_open; + const bool popup_open = ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel); + bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true); bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true); - if (active_id == 0 and ImGui::ItemHoverable(window->Rect(), 0, g.CurrentItemFlags) and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any)) + // Begin a drag-scroll only when the press lands on this window or one of its + // child panels and no widget grabbed it. IsWindowHovered(ChildWindows) lets the + // drag work over card child windows (ItemHoverable would fail there), and the + // g.ActiveId guard keeps manipulating a control (slider, toggle, combo...) from + // scrolling the page. Controls must claim the active id on press for this to hold. + const bool over = ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows); + if (active_id == 0 and g.ActiveId == 0 and not popup_open and not popup_was_open and over and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any)) { active_id = id; @@ -1357,6 +1370,8 @@ void ScrollWhenDragging() g.HoveredIdAllowOverlap = HoveredIdAllowOverlap_backup; g.ActiveIdAllowOverlap = ActiveIdAllowOverlap_backup; + + popup_was_open = popup_open; } void CenterTextH(const std::string & text) diff --git a/client/render/ui_theme.cpp b/client/render/ui_theme.cpp new file mode 100644 index 00000000..00a87e00 --- /dev/null +++ b/client/render/ui_theme.cpp @@ -0,0 +1,219 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ui_theme.h" + +namespace wivrn::ui +{ + +static ImVec4 rgb(int r, int g, int b, float a = 1) +{ + return {r / 255.f, g / 255.f, b / 255.f, a}; +} + +static theme dark_default() +{ + theme t; + t.name = "Dark"; + + t.accent = rgb(59, 130, 246); + t.accent_hovered = rgb(82, 146, 247); + t.accent_active = rgb(43, 110, 222); + t.on_accent = rgb(255, 255, 255); + + t.background = rgb(10, 11, 13); + t.card = rgb(22, 24, 29); + t.card_hovered = rgb(28, 30, 36); + t.control = rgb(35, 38, 46); + t.control_hovered = rgb(44, 48, 57); + t.control_active = rgb(52, 57, 68); + + t.text = rgb(244, 245, 248); + t.text_muted = rgb(150, 156, 167); + t.border = rgb(40, 43, 51); + + t.danger = rgb(239, 68, 68); + t.danger_hovered = rgb(248, 96, 96); + t.success = rgb(52, 199, 123); + t.warning = rgb(249, 115, 6); + + t.rounding = 8; + t.card_rounding = 14; + t.border_size = 1; + t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base + t.background_alpha = 0.88f; // ~ the previous hardcoded 224/255 + return t; +} + +static theme midnight() +{ + theme t = dark_default(); + t.name = "Midnight"; + t.background = rgb(6, 8, 16); + t.card = rgb(16, 20, 34); + t.card_hovered = rgb(22, 27, 44); + t.control = rgb(28, 34, 54); + t.control_hovered = rgb(36, 43, 66); + t.control_active = rgb(44, 52, 78); + t.border = rgb(30, 37, 58); + return t; +} + +static theme slate_light() +{ + theme t = dark_default(); + t.name = "Slate"; + t.background = rgb(28, 30, 36); + t.card = rgb(38, 41, 49); + t.card_hovered = rgb(46, 50, 60); + t.control = rgb(54, 59, 70); + t.control_hovered = rgb(64, 70, 83); + t.control_active = rgb(74, 81, 96); + t.text = rgb(236, 238, 242); + t.text_muted = rgb(168, 174, 186); + t.border = rgb(58, 63, 75); + return t; +} + +// True black, ideal for OLED panels +static theme oled() +{ + theme t = dark_default(); + t.name = "OLED"; + t.background = rgb(0, 0, 0); + t.card = rgb(6, 6, 8); + t.card_hovered = rgb(11, 12, 14); + t.control = rgb(22, 24, 28); + t.control_hovered = rgb(30, 32, 38); + t.control_active = rgb(40, 43, 50); + t.border = rgb(26, 28, 33); + return t; +} + +// Neutral dark gray +static theme graphite() +{ + theme t = dark_default(); + t.name = "Graphite"; + t.background = rgb(20, 21, 23); + t.card = rgb(31, 33, 36); + t.card_hovered = rgb(39, 41, 45); + t.control = rgb(48, 51, 56); + t.control_hovered = rgb(58, 62, 68); + t.control_active = rgb(68, 72, 80); + t.text = rgb(238, 240, 243); + t.text_muted = rgb(160, 164, 172); + t.border = rgb(50, 53, 59); + return t; +} + +// Light surfaces, dark text +static theme light() +{ + theme t = dark_default(); + t.name = "Light"; + t.background = rgb(236, 238, 242); + t.card = rgb(255, 255, 255); + t.card_hovered = rgb(246, 247, 250); + t.control = rgb(212, 216, 224); + t.control_hovered = rgb(199, 204, 213); + t.control_active = rgb(184, 190, 201); + t.text = rgb(22, 24, 30); + t.text_muted = rgb(108, 114, 126); + t.border = rgb(205, 209, 217); + return t; +} + +std::vector presets() +{ + return {oled(), dark_default(), midnight(), graphite(), slate_light(), light()}; +} + +std::vector accent_swatches() +{ + return { + {"Blue", rgb(59, 130, 246), rgb(82, 146, 247), rgb(43, 110, 222)}, + {"Violet", rgb(139, 92, 246), rgb(157, 116, 247), rgb(120, 72, 226)}, + {"Emerald", rgb(16, 185, 129), rgb(34, 200, 145), rgb(8, 160, 110)}, + {"Amber", rgb(245, 158, 11), rgb(248, 173, 40), rgb(220, 138, 6)}, + {"Rose", rgb(244, 63, 94), rgb(247, 90, 117), rgb(222, 48, 78)}, + {"Cyan", rgb(6, 182, 212), rgb(34, 197, 224), rgb(6, 158, 184)}, + }; +} + +void set_accent(const accent_swatch & swatch) +{ + theme & t = current(); + t.accent = swatch.base; + t.accent_hovered = swatch.hovered; + t.accent_active = swatch.active; +} + +theme & current() +{ + static theme t = dark_default(); + return t; +} + +void set_theme(const theme & t) +{ + current() = t; +} + +void theme::apply() const +{ + ImGuiStyle & style = ImGui::GetStyle(); + + style.FontScaleMain = font_scale; + style.WindowRounding = card_rounding; + style.ChildRounding = card_rounding; + style.PopupRounding = card_rounding; + style.FrameRounding = rounding; + style.GrabRounding = rounding; + style.TabRounding = rounding; + style.FrameBorderSize = border_size; + style.WindowBorderSize = border_size; + + ImVec4 * c = style.Colors; + c[ImGuiCol_Text] = text; + c[ImGuiCol_TextDisabled] = text_muted; + c[ImGuiCol_WindowBg] = background; + c[ImGuiCol_ChildBg] = card; + c[ImGuiCol_PopupBg] = card; + c[ImGuiCol_Border] = border; + c[ImGuiCol_FrameBg] = control; + c[ImGuiCol_FrameBgHovered] = control_hovered; + c[ImGuiCol_FrameBgActive] = control_active; + c[ImGuiCol_Button] = control; + c[ImGuiCol_ButtonHovered] = control_hovered; + c[ImGuiCol_ButtonActive] = accent; + c[ImGuiCol_Header] = control_hovered; + c[ImGuiCol_HeaderHovered] = control_hovered; + c[ImGuiCol_HeaderActive] = accent; + c[ImGuiCol_SliderGrab] = accent; + c[ImGuiCol_SliderGrabActive] = accent_active; + c[ImGuiCol_CheckMark] = accent; + c[ImGuiCol_ScrollbarBg] = {0, 0, 0, 0}; + c[ImGuiCol_ScrollbarGrab] = control; + c[ImGuiCol_ScrollbarGrabHovered] = control_hovered; + c[ImGuiCol_ScrollbarGrabActive] = control_active; + c[ImGuiCol_Separator] = border; +} + +} // namespace wivrn::ui diff --git a/client/render/ui_theme.h b/client/render/ui_theme.h new file mode 100644 index 00000000..814576a7 --- /dev/null +++ b/client/render/ui_theme.h @@ -0,0 +1,126 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include + +namespace wivrn::ui +{ + +struct theme +{ + std::string name; + + // Accent + ImVec4 accent; + ImVec4 accent_hovered; + ImVec4 accent_active; + ImVec4 on_accent; // text/icon on an accent fill + + // Surfaces, back to front + ImVec4 background; + ImVec4 card; + ImVec4 card_hovered; + ImVec4 control; // slider rail, secondary button, input + ImVec4 control_hovered; + ImVec4 control_active; + + // Content + ImVec4 text; + ImVec4 text_muted; + ImVec4 border; + + // Semantic + ImVec4 danger; + ImVec4 danger_hovered; + ImVec4 success; + ImVec4 warning; + + // Shape, in pixels + float rounding; // buttons, inputs, sliders + float card_rounding; // cards + float border_size; + + float font_scale; // global text size multiplier + float background_alpha; // opacity of the main panel background, 0..1 + + ImU32 col(const ImVec4 & c) const + { + return ImGui::ColorConvertFloat4ToU32(c); + } + + // Push colors and metrics into the global ImGui style + void apply() const; +}; + +// Fixed design tokens shared by the widgets +namespace metrics +{ +constexpr float font_base = 0.765; // design default text scale, i.e. what the user-facing 100% maps to +constexpr float font_title = 1.7; // page header, x base font size +constexpr float font_description = 0.82; // muted secondary text, x base font size + +constexpr ImVec2 button_padding = {26, 14}; +constexpr ImVec2 card_padding = {28, 22}; + +// Shared height of every full-width control (slider, segmented, combo, input) +// so they line up in a setting row, in multiples of ImGui::GetFrameHeight() +constexpr float control_height = 1.65; + +constexpr float toggle_aspect = 1.9; // track width / height +constexpr float toggle_knob_inset = 3; // gap between track edge and knob + +constexpr float slider_grab_width = 14; + +constexpr float segmented_inset = 3; // gap around the active segment + +constexpr float icon_button_glyph = 0.5; // glyph height as a fraction of the button side + +constexpr float combo_row_height = 2.2; // x frame height, big touch rows in the modal +constexpr float combo_chevron = 12; // chevron size in the closed box +constexpr float combo_modal_min_width = 460; // popup never narrower than this +constexpr ImVec2 combo_padding = {16, 0}; // horizontal inner padding of box and rows + +constexpr ImVec2 chip_padding = {12, 6}; // inner padding of a chip/badge +constexpr float input_padding_x = 14; // horizontal text padding inside inputs +constexpr float font_modal_title = 1.2; // modal heading, x base font size + +constexpr float label_line_gap = 5; // title to description +} // namespace metrics + +// Theme in effect, call current().apply() after mutating +theme & current(); +void set_theme(const theme & t); + +std::vector presets(); + +struct accent_swatch +{ + const char * name; + ImVec4 base; + ImVec4 hovered; + ImVec4 active; +}; +std::vector accent_swatches(); +void set_accent(const accent_swatch & swatch); + +} // namespace wivrn::ui diff --git a/client/render/ui_widgets.cpp b/client/render/ui_widgets.cpp new file mode 100644 index 00000000..f45b4d60 --- /dev/null +++ b/client/render/ui_widgets.cpp @@ -0,0 +1,863 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define IMGUI_DEFINE_MATH_OPERATORS + +#include "ui_widgets.h" + +#include "imgui.h" +#include "imgui_internal.h" +#include "ui_theme.h" + +#include "IconsFontAwesome6.h" + +#include +#include +#include +#include + +namespace wivrn::ui +{ + +namespace +{ +std::function hover_haptic_hook; +std::function tooltip_hook; +} // namespace + +void set_hover_haptic(std::function hook) +{ + hover_haptic_hook = std::move(hook); +} + +void set_tooltip_hook(std::function hook) +{ + tooltip_hook = std::move(hook); +} + +// Fire the hover haptic for the last submitted item, if a hook is installed. +// The hook itself checks whether that item is actually hovered. +static void hover_haptic() +{ + if (hover_haptic_hook) + hover_haptic_hook(); +} + +// Show a tooltip for the last submitted item; caller ensures it is hovered. +static void show_tooltip(const char * text) +{ + if (text and text[0] and tooltip_hook) + tooltip_hook(text); +} + +void page_header(const char * title, const char * subtitle) +{ + const theme & t = current(); + + ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * metrics::font_title); + ImGui::TextUnformatted(title); + ImGui::PopFont(); + + if (subtitle and subtitle[0]) + { + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); + ImGui::TextUnformatted(subtitle); + ImGui::PopStyleColor(); + } + ImGui::Dummy({0, ImGui::GetStyle().ItemSpacing.y}); +} + +// A card is purely a visual rounded panel, NOT a child window: its content is +// laid out directly in the parent window so the page stays a single scroll +// surface (drag-to-scroll and clicks behave uniformly everywhere). The panel is +// drawn behind the upcoming content using the height measured last frame, then +// the full extent is reserved so layout and scrolling account for it. +// Always pair begin_card with end_card. +namespace +{ +struct card_frame +{ + ImGuiID id; + ImVec2 origin; + float width; + float content_max_x_backup; + float work_max_x_backup; +}; +std::vector card_stack; +std::unordered_map card_heights; +} // namespace + +bool begin_card(const char * id, const ImVec2 &) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + const theme & t = current(); + const ImGuiID gid = window->GetID(id); + + card_stack.push_back({gid, + window->DC.CursorPos, + ImGui::GetContentRegionAvail().x, + window->ContentRegionRect.Max.x, + window->WorkRect.Max.x}); + const card_frame & cf = card_stack.back(); + + if (const float h = card_heights[gid]; h > 0) + { + const ImVec2 bb_max = {cf.origin.x + cf.width, cf.origin.y + h}; + window->DrawList->AddRectFilled(cf.origin, bb_max, t.col(t.card), t.card_rounding); + if (t.border_size > 0) + window->DrawList->AddRect(cf.origin, bb_max, t.col(t.border), t.card_rounding, 0, t.border_size); + } + + ImGui::PushID(id); + window->ContentRegionRect.Max.x -= metrics::card_padding.x; + window->WorkRect.Max.x -= metrics::card_padding.x; + ImGui::Indent(metrics::card_padding.x); + ImGui::SetCursorScreenPos({ImGui::GetCursorScreenPos().x, cf.origin.y + metrics::card_padding.y}); + ImGui::BeginGroup(); + return true; +} + +void end_card() +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + const card_frame cf = card_stack.back(); + card_stack.pop_back(); + + ImGui::EndGroup(); + ImGui::Unindent(metrics::card_padding.x); + window->ContentRegionRect.Max.x = cf.content_max_x_backup; + window->WorkRect.Max.x = cf.work_max_x_backup; + ImGui::PopID(); + + const float height = ImGui::GetItemRectMax().y + metrics::card_padding.y - cf.origin.y; + card_heights[cf.id] = height; + + // reserve the full card extent so layout and scrolling account for it + ImGui::SetCursorScreenPos(cf.origin); + ImGui::Dummy({cf.width, height}); +} + +void row_separator() +{ + const theme & t = current(); + ImGui::PushStyleColor(ImGuiCol_Separator, t.border); + ImGui::Separator(); + ImGui::PopStyleColor(); +} + +void setting_label(const char * title, const char * description, float control_width) +{ + const theme & t = current(); + const ImGuiStyle & style = ImGui::GetStyle(); + + const ImVec2 start = ImGui::GetCursorPos(); + const float avail = ImGui::GetContentRegionAvail().x; + float text_w = avail - control_width - style.ItemSpacing.x; + if (text_w < 1) + text_w = avail; + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {style.ItemSpacing.x, metrics::label_line_gap}); + ImGui::PushTextWrapPos(start.x + text_w); + ImGui::TextUnformatted(title); + if (description and description[0]) + { + ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * metrics::font_description); + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); + ImGui::TextUnformatted(description); + ImGui::PopStyleColor(); + ImGui::PopFont(); + } + ImGui::PopTextWrapPos(); + ImGui::PopStyleVar(); + + // right-aligned control slot, vertically centered against the label block. + // Controls are control_height x frame height, so centre against that. + const float label_h = ImGui::GetCursorPos().y - start.y; + const float ctrl_h = ImGui::GetFrameHeight() * metrics::control_height; + const float ctrl_y = start.y + ImMax(0.f, (label_h - ctrl_h) * 0.5f); + ImGui::SetCursorPos({start.x + avail - control_width, ctrl_y}); +} + +bool button(const char * label, button_style s, const ImVec2 & size) +{ + const theme & t = current(); + + // default to the shared control height; width still auto-fits the label + const float h = size.y > 0 ? size.y : ImGui::GetFrameHeight() * metrics::control_height; + + switch (s) + { + case button_style::primary: + ImGui::PushStyleColor(ImGuiCol_Button, t.accent); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.accent_hovered); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.accent_active); + ImGui::PushStyleColor(ImGuiCol_Text, t.on_accent); + break; + case button_style::secondary: + ImGui::PushStyleColor(ImGuiCol_Button, t.control); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.control_hovered); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.control_active); + ImGui::PushStyleColor(ImGuiCol_Text, t.text); + break; + case button_style::danger: + ImGui::PushStyleColor(ImGuiCol_Button, t.danger); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.danger_hovered); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.danger); + ImGui::PushStyleColor(ImGuiCol_Text, t.on_accent); + break; + case button_style::ghost: + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0, 0, 0, 0}); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.control); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.control_active); + ImGui::PushStyleColor(ImGuiCol_Text, t.text); + break; + } + + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, t.rounding); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, metrics::button_padding); + const bool pressed = ImGui::Button(label, {size.x, h}); + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(4); + hover_haptic(); + return pressed; +} + +bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const char * tooltip) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext & g = *GImGui; + const ImGuiStyle & style = g.Style; + const theme & t = current(); + + // square touch target, same height as the sliders and other controls + const float side = ImGui::GetFrameHeight() * metrics::control_height; + const ImVec2 size = size_arg.x > 0 ? size_arg : ImVec2{side, side}; + + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + size); + ImGui::ItemSize(bb, style.FramePadding.y); + const ImGuiID gid = window->GetID(icon); + if (not ImGui::ItemAdd(bb, gid)) + return false; + + bool hovered, held; + const bool pressed = ImGui::ButtonBehavior(bb, gid, &hovered, &held); + hover_haptic(); + if (hovered) + show_tooltip(tooltip); + + ImVec4 bg = active ? t.accent : t.control; + if (held) + bg = active ? t.accent_active : t.control_active; + else if (hovered) + bg = active ? t.accent_hovered : t.control_hovered; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); + + // glyph drawn manually so it scales with the button. Centre on the glyph's real + // ink box (X0..X1, Y0..Y1) rather than CalcTextSize, which returns the advance + // width and line height and leaves the glyph up-and-left of true centre. + const float glyph_size = size.y * metrics::icon_button_glyph; + ImGui::PushFont(nullptr, glyph_size); + const ImU32 col = t.col(active ? t.on_accent : t.text); + const ImVec2 center = bb.GetCenter(); + + unsigned int codepoint = 0; + ImTextCharFromUtf8(&codepoint, icon, nullptr); + const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint); + if (glyph) + draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon); + else + { + const ImVec2 ts = ImGui::CalcTextSize(icon); + draw->AddText({center.x - ts.x * 0.5f, center.y - ts.y * 0.5f}, col, icon); + } + ImGui::PopFont(); + + return pressed; +} + +// Horizontal space a trailing reset slot consumes, gap included +static float reset_slot_width() +{ + return ImGui::GetFrameHeight() * metrics::control_height + ImGui::GetStyle().ItemSpacing.x; +} + +// Trailing reset affordance placed on the same row as a value control, right after +// it (the control should have shrunk its width by reset_slot_width() to make room). +// Draws a reset icon button when show is true, or an empty slot when false so the +// right edge stays put. Returns true when the user taps reset. +static bool reset_slot(const char * id, bool show) +{ + const float side = ImGui::GetFrameHeight() * metrics::control_height; + ImGui::SameLine(0, ImGui::GetStyle().ItemSpacing.x); + if (not show) + { + ImGui::Dummy({side, side}); + return false; + } + ImGui::PushID(id); + const bool clicked = icon_button(ICON_FA_ARROW_ROTATE_LEFT, {side, side}, false, "Reset to default"); + ImGui::PopID(); + return clicked; +} + +bool toggle(const char * id, bool * v, const bool * default_value) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + const theme & t = current(); + const ImGuiStyle & style = ImGui::GetStyle(); + + // match the height of the other controls (sliders, combo, ...) + const float height = ImGui::GetFrameHeight() * metrics::control_height; + const float width = height * metrics::toggle_aspect; + const float radius = height * 0.5f; + + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + ImVec2(width, height)); + ImGui::ItemSize(bb, style.FramePadding.y); + const ImGuiID gid = window->GetID(id); + if (not ImGui::ItemAdd(bb, gid)) + return false; + + bool hovered, held; + bool changed = ImGui::ButtonBehavior(bb, gid, &hovered, &held); + hover_haptic(); + if (changed) + *v = not *v; + + ImVec4 track = *v ? t.accent : t.control; + if (hovered) + track = *v ? t.accent_hovered : t.control_hovered; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(track), radius); + const float cx = *v ? (bb.Max.x - radius) : (bb.Min.x + radius); + draw->AddCircleFilled({cx, bb.Min.y + radius}, radius - metrics::toggle_knob_inset, t.col(t.on_accent)); + + if (default_value and reset_slot(id, *v != *default_value)) + { + *v = *default_value; + changed = true; + } + + return changed; +} + +bool slider_int(const char * id, int * v, int v_min, int v_max, const char * format, const ImVec2 & size_arg, const int * default_value) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext & g = *GImGui; + const ImGuiStyle & style = g.Style; + const theme & t = current(); + const ImGuiID gid = window->GetID(id); + + ImVec2 size = ImGui::CalcItemSize(size_arg, ImGui::CalcItemWidth(), ImGui::GetFrameHeight() * metrics::control_height); + if (default_value) + size.x -= reset_slot_width(); + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + size); + ImGui::ItemSize(bb, style.FramePadding.y); + if (not ImGui::ItemAdd(bb, gid, &bb)) + return false; + + // activation, mirrors ImGui::SliderScalar + const bool hovered = ImGui::ItemHoverable(bb, gid, g.LastItemData.ItemFlags); + hover_haptic(); + const bool clicked = hovered and ImGui::IsMouseClicked(ImGuiMouseButton_Left, ImGuiInputFlags_None, gid); + if (clicked or g.NavActivateId == gid) + { + if (clicked) + ImGui::SetKeyOwner(ImGuiKey_MouseLeft, gid); + ImGui::SetActiveID(gid, window); + ImGui::SetFocusID(gid, window); + ImGui::FocusWindow(window); + g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); + } + + ImRect grab; + const bool changed = ImGui::SliderBehavior(bb, gid, ImGuiDataType_S32, v, &v_min, &v_max, format, ImGuiSliderFlags_None, &grab); + if (changed) + ImGui::MarkItemEdited(gid); + + const float fraction = v_max > v_min ? float(*v - v_min) / float(v_max - v_min) : 0; + const float fill_x = bb.Min.x + (bb.Max.x - bb.Min.x) * fraction; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.rounding); + if (fraction > 0) + draw->AddRectFilled(bb.Min, {fill_x, bb.Max.y}, t.col(t.accent_active), t.rounding, ImDrawFlags_RoundCornersLeft); + // bright grab at the fill edge + const float grab_w = metrics::slider_grab_width; + const float gx = ImClamp(fill_x, bb.Min.x + grab_w * 0.5f, bb.Max.x - grab_w * 0.5f); + draw->AddRectFilled({gx - grab_w * 0.5f, bb.Min.y}, {gx + grab_w * 0.5f, bb.Max.y}, t.col(t.accent), t.rounding); + + char buf[64]; + std::snprintf(buf, sizeof(buf), format, *v); + const ImVec2 ts = ImGui::CalcTextSize(buf); + draw->AddText({bb.Min.x + (size.x - ts.x) * 0.5f, bb.Min.y + (size.y - ts.y) * 0.5f}, t.col(t.text), buf); + + bool reset = false; + if (default_value and reset_slot(id, *v != *default_value)) + { + *v = *default_value; + reset = true; + } + + return changed or reset; +} + +bool segmented(const char * id, const std::vector & options, int * selected, const ImVec2 & size_arg, const int * default_value) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems or options.empty()) + return false; + + ImGuiContext & g = *GImGui; + const ImGuiStyle & style = g.Style; + const theme & t = current(); + + ImVec2 size = ImGui::CalcItemSize(size_arg, ImGui::CalcItemWidth(), ImGui::GetFrameHeight() * metrics::control_height); + if (default_value) + size.x -= reset_slot_width(); + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + size); + ImGui::ItemSize(bb, style.FramePadding.y); + const ImGuiID gid = window->GetID(id); + if (not ImGui::ItemAdd(bb, gid)) + return false; + + const bool hovered = ImGui::ItemHoverable(bb, gid, g.LastItemData.ItemFlags); + hover_haptic(); + // claim the active id on press so a drag here scrolls nothing (see ScrollWhenDragging) + if (hovered and ImGui::IsMouseClicked(ImGuiMouseButton_Left)) + { + ImGui::SetActiveID(gid, window); + ImGui::FocusWindow(window); + } + if (g.ActiveId == gid and not g.IO.MouseDown[ImGuiMouseButton_Left]) + ImGui::ClearActiveID(); + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.rounding); + + const int n = int(options.size()); + const float seg_w = size.x / n; + const float pad = metrics::segmented_inset; + bool changed = false; + + for (int i = 0; i < n; ++i) + { + const ImRect seg({bb.Min.x + seg_w * i, bb.Min.y}, {bb.Min.x + seg_w * (i + 1), bb.Max.y}); + const bool seg_hovered = hovered and seg.Contains(g.IO.MousePos); + if (seg_hovered and ImGui::IsMouseClicked(ImGuiMouseButton_Left)) + { + *selected = i; + changed = true; + } + + const bool active = *selected == i; + if (active) + draw->AddRectFilled(seg.Min + ImVec2(pad, pad), seg.Max - ImVec2(pad, pad), t.col(t.accent), t.rounding); + else if (seg_hovered) + draw->AddRectFilled(seg.Min + ImVec2(pad, pad), seg.Max - ImVec2(pad, pad), t.col(t.control_hovered), t.rounding); + + const char * label = options[i].c_str(); + const ImVec2 ts = ImGui::CalcTextSize(label); + draw->AddText({seg.Min.x + (seg_w - ts.x) * 0.5f, seg.Min.y + (size.y - ts.y) * 0.5f}, t.col(active ? t.on_accent : t.text), label); + } + + if (default_value and reset_slot(id, *selected != *default_value)) + { + *selected = *default_value; + changed = true; + } + + return changed; +} + +namespace +{ +// Where combo modals open, in imgui display coords. Set each frame by the lobby. +ImVec2 popup_center = {0, 0}; + +// One selectable option inside the combo modal. A tall, full-width touch target +// with the name (accent when selected) and an optional muted description. +bool combo_row(const combo_item & item, bool selected) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + const theme & t = current(); + + const float row_h = ImGui::GetFrameHeight() * metrics::combo_row_height; + const float row_w = ImGui::GetContentRegionAvail().x; + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + ImVec2(row_w, row_h)); + ImGui::ItemSize(bb, 0); + const ImGuiID gid = window->GetID(item.name); + if (not ImGui::ItemAdd(bb, gid)) + return false; + + bool hovered, held; + const bool pressed = ImGui::ButtonBehavior(bb, gid, &hovered, &held); + hover_haptic(); + + ImVec4 bg = selected ? t.control_active : t.card; + if (held) + bg = t.control_active; + else if (hovered) + bg = t.control_hovered; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); + if (selected) + draw->AddRectFilled(bb.Min, {bb.Min.x + metrics::combo_padding.x * 0.25f, bb.Max.y}, t.col(t.accent), t.rounding, ImDrawFlags_RoundCornersLeft); + + const float tx = bb.Min.x + metrics::combo_padding.x; + const ImU32 name_col = t.col(selected ? t.accent : t.text); + const ImVec2 nts = ImGui::CalcTextSize(item.name); + + if (item.description and item.description[0]) + { + const float desc_size = ImGui::GetStyle().FontSizeBase * metrics::font_description; + ImGui::PushFont(nullptr, desc_size); + const ImVec2 dts = ImGui::CalcTextSize(item.description); + const float total = nts.y + metrics::label_line_gap + dts.y; + const float y = bb.Min.y + (row_h - total) * 0.5f; + draw->AddText({tx, y + nts.y + metrics::label_line_gap}, t.col(t.text_muted), item.description); + ImGui::PopFont(); + draw->AddText({tx, y}, name_col, item.name); + } + else + { + draw->AddText({tx, bb.Min.y + (row_h - nts.y) * 0.5f}, name_col, item.name); + } + + return pressed; +} +} // namespace + +void set_popup_center(const ImVec2 & center) +{ + popup_center = center; +} + +bool combo(const char * id, const char * title, const std::vector & items, int * selected, float width, const int * default_value) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems or items.empty()) + return false; + + const ImGuiStyle & style = ImGui::GetStyle(); + const theme & t = current(); + const ImGuiID gid = window->GetID(id); + + // closed box, same height as the slider so setting rows line up + ImVec2 size = ImGui::CalcItemSize({width, 0}, ImGui::CalcItemWidth(), ImGui::GetFrameHeight() * metrics::control_height); + if (default_value) + size.x -= reset_slot_width(); + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + size); + ImGui::ItemSize(bb, style.FramePadding.y); + if (not ImGui::ItemAdd(bb, gid)) + return false; + + bool hovered, held; + const bool clicked = ImGui::ButtonBehavior(bb, gid, &hovered, &held); + hover_haptic(); + + ImVec4 box = t.control; + if (held) + box = t.control_active; + else if (hovered) + box = t.control_hovered; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(box), t.rounding); + if (t.border_size > 0) + draw->AddRect(bb.Min, bb.Max, t.col(t.border), t.rounding, 0, t.border_size); + + const int sel = ImClamp(*selected, 0, int(items.size()) - 1); + + // preview, left aligned and clipped to the box + const char * preview = items[sel].name; + const ImVec2 ts = ImGui::CalcTextSize(preview); + const float pad_x = metrics::combo_padding.x; + draw->PushClipRect(bb.Min, bb.Max, true); + draw->AddText({bb.Min.x + pad_x, bb.Min.y + (size.y - ts.y) * 0.5f}, t.col(t.text), preview); + draw->PopClipRect(); + + // chevron on the right + const float cx = bb.Max.x - pad_x - metrics::combo_chevron * 0.5f; + const float cy = bb.Min.y + size.y * 0.5f; + const float r = metrics::combo_chevron * 0.5f; + draw->AddTriangleFilled({cx - r, cy - r * 0.4f}, {cx + r, cy - r * 0.4f}, {cx, cy + r * 0.6f}, t.col(t.text_muted)); + + char popup_id[64]; + std::snprintf(popup_id, sizeof(popup_id), "##combo_%08X", gid); + if (clicked) + ImGui::OpenPopup(popup_id); + + ImGui::SetNextWindowPos(popup_center, ImGuiCond_Always, {0.5f, 0.5f}); + ImGui::SetNextWindowSize({ImMax(size.x, metrics::combo_modal_min_width), 0}); + + ImGui::PushStyleColor(ImGuiCol_PopupBg, t.card); + ImGui::PushStyleColor(ImGuiCol_Border, t.border); + ImGui::PushStyleColor(ImGuiCol_Text, t.text); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, t.card_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, metrics::card_padding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, t.border_size > 0 ? t.border_size : 1); + + bool changed = false; + if (ImGui::BeginPopupModal(popup_id, nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) + { + if (title and title[0]) + { + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); + ImGui::TextUnformatted(title); + ImGui::PopStyleColor(); + ImGui::Dummy({0, style.ItemSpacing.y}); + } + + for (int i = 0; i < int(items.size()); ++i) + { + if (combo_row(items[i], i == sel)) + { + *selected = i; + changed = true; + ImGui::CloseCurrentPopup(); + } + } + + // tapping outside the list dismisses without changing the selection. + // AllowWhenBlockedByActiveItem is required: pressing a row sets it as the active + // item, which would otherwise make IsWindowHovered return false on the press + // frame and close the modal before the row's release registers the selection. + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + ImGui::CloseCurrentPopup(); + + ImGui::EndPopup(); + } + + ImGui::PopStyleVar(3); + ImGui::PopStyleColor(3); + + if (default_value and reset_slot(id, *selected != *default_value)) + { + *selected = *default_value; + changed = true; + } + + return changed; +} + +void chip(const char * label, chip_style style, bool dot) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return; + + const theme & t = current(); + + // foreground (text/dot/icon) and the pill fill + ImVec4 fg = t.text; + ImVec4 bg = t.control; + switch (style) + { + case chip_style::neutral: + break; + case chip_style::muted: + fg = t.text_muted; + break; + case chip_style::accent: + fg = t.accent; + bg = {t.accent.x, t.accent.y, t.accent.z, 0.16f}; + break; + case chip_style::success: + fg = t.success; + bg = {t.success.x, t.success.y, t.success.z, 0.16f}; + break; + case chip_style::warning: + fg = t.warning; + bg = {t.warning.x, t.warning.y, t.warning.z, 0.16f}; + break; + case chip_style::danger: + fg = t.danger; + bg = {t.danger.x, t.danger.y, t.danger.z, 0.16f}; + break; + } + + const ImVec2 ts = ImGui::CalcTextSize(label); + const ImVec2 pad = metrics::chip_padding; + const float dot_r = ts.y * 0.26f; + const float dot_gap = dot ? dot_r * 2 + pad.x * 0.55f : 0; + const ImVec2 size = {ts.x + pad.x * 2 + dot_gap, ts.y + pad.y * 2}; + + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + size); + ImGui::ItemSize(bb); + if (not ImGui::ItemAdd(bb, 0)) + return; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), size.y * 0.5f); + + float tx = bb.Min.x + pad.x; + if (dot) + { + draw->AddCircleFilled({tx + dot_r, bb.Min.y + size.y * 0.5f}, dot_r, t.col(fg)); + tx += dot_r * 2 + pad.x * 0.55f; + } + draw->AddText({tx, bb.Min.y + pad.y}, t.col(fg), label); +} + +static int input_text_resize(ImGuiInputTextCallbackData * data) +{ + if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) + { + std::string & s = *static_cast(data->UserData); + s.resize(data->BufTextLen); + data->Buf = s.data(); + } + return 0; +} + +// Common frame styling for the input widgets, control height. Returns the count of +// style colors / vars pushed so the caller can pop them. +static void push_input_style(float height) +{ + const theme & t = current(); + ImGui::PushStyleColor(ImGuiCol_FrameBg, t.control); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, t.control_hovered); + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, t.control_active); + ImGui::PushStyleColor(ImGuiCol_Text, t.text); + ImGui::PushStyleColor(ImGuiCol_TextDisabled, t.text_muted); + ImGui::PushStyleColor(ImGuiCol_Border, t.border); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, t.rounding); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, t.border_size); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {metrics::input_padding_x, (height - ImGui::GetFontSize()) * 0.5f}); +} + +static void pop_input_style() +{ + ImGui::PopStyleVar(3); + ImGui::PopStyleColor(6); +} + +bool input_text(const char * id, std::string & text, const char * hint, float width) +{ + push_input_style(ImGui::GetFrameHeight() * metrics::control_height); + const bool changed = ImGui::InputTextEx(id, hint, text.data(), int(text.size()) + 1, {width, 0}, ImGuiInputTextFlags_CallbackResize, input_text_resize, &text); + pop_input_style(); + hover_haptic(); + return changed; +} + +bool input_int(const char * id, int * v, int step, int v_min, int v_max, float width) +{ + const ImGuiStyle & style = ImGui::GetStyle(); + const float side = ImGui::GetFrameHeight() * metrics::control_height; + const float gap = style.ItemSpacing.x; + const float total = width > 0 ? width : ImGui::CalcItemWidth(); + const float field_w = total - 2 * (side + gap); + + ImGui::PushID(id); + + push_input_style(side); + ImGui::SetNextItemWidth(field_w); + bool changed = ImGui::InputInt("##field", v, 0, 0, ImGuiInputTextFlags_CharsDecimal); // step 0 hides native buttons + pop_input_style(); + hover_haptic(); + + ImGui::SameLine(0, gap); + if (icon_button(ICON_FA_MINUS, {side, side})) + { + *v -= step; + changed = true; + } + ImGui::SameLine(0, gap); + if (icon_button(ICON_FA_PLUS, {side, side})) + { + *v += step; + changed = true; + } + + if (v_min != v_max) + *v = ImClamp(*v, v_min, v_max); + + ImGui::PopID(); + return changed; +} + +bool begin_modal(const char * id, const char * title, float width) +{ + const theme & t = current(); + const ImGuiStyle & style = ImGui::GetStyle(); + + ImGui::SetNextWindowPos(popup_center, ImGuiCond_Always, {0.5f, 0.5f}); + if (width > 0) + ImGui::SetNextWindowSize({width, 0}); + + ImGui::PushStyleColor(ImGuiCol_PopupBg, t.card); + ImGui::PushStyleColor(ImGuiCol_Border, t.border); + ImGui::PushStyleColor(ImGuiCol_Text, t.text); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, t.card_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, metrics::card_padding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, t.border_size > 0 ? t.border_size : 1); + + ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; + if (width <= 0) + flags |= ImGuiWindowFlags_AlwaysAutoResize; + + const bool open = ImGui::BeginPopupModal(id, nullptr, flags); + if (open) + { + if (title and title[0]) + { + ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_modal_title); + ImGui::TextUnformatted(title); + ImGui::PopFont(); + ImGui::Dummy({0, style.ItemSpacing.y}); + } + } + else + { + ImGui::PopStyleVar(3); + ImGui::PopStyleColor(3); + } + return open; +} + +void end_modal() +{ + ImGui::EndPopup(); + ImGui::PopStyleVar(3); + ImGui::PopStyleColor(3); +} + +} // namespace wivrn::ui diff --git a/client/render/ui_widgets.h b/client/render/ui_widgets.h new file mode 100644 index 00000000..687163c9 --- /dev/null +++ b/client/render/ui_widgets.h @@ -0,0 +1,121 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include + +// Themed, reusable UI widgets matching the WiVRn dashboard design. +// All widgets read colors and metrics from wivrn::ui::current(). +namespace wivrn::ui +{ + +enum class button_style +{ + primary, // accent fill + secondary, // control fill + danger, // destructive + ghost, // transparent until hovered +}; + +// Page title with an optional muted subtitle +void page_header(const char * title, const char * subtitle = nullptr); + +// Rounded panel, pair with end_card. Returns false when fully clipped +bool begin_card(const char * id, const ImVec2 & size = {0, 0}); +void end_card(); + +// Full-width divider between rows of a card +void row_separator(); + +// Bold title + wrapped muted description in a left column, +// leaving control_width on the right for a right-aligned control +void setting_label(const char * title, const char * description, float control_width); + +bool button(const char * label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); +// tooltip, if given, is shown while the button is hovered +bool icon_button(const char * icon, const ImVec2 & size = {0, 0}, bool active = false, const char * tooltip = nullptr); + +bool toggle(const char * id, bool * v, const bool * default_value = nullptr); + +// Value controls below take an optional default_value. When given and the current +// value differs from it, a reset icon button is drawn in a trailing slot; tapping it +// restores the default. When the value matches (or no default is given) the slot is +// left empty so the control's right edge stays put. + +// Filled bar slider with the value centered on the rail +bool slider_int(const char * id, int * v, int v_min, int v_max, const char * format, const ImVec2 & size = {0, 0}, const int * default_value = nullptr); + +// Pill group, *selected is the index of the active option +bool segmented(const char * id, const std::vector & options, int * selected, const ImVec2 & size = {0, 0}, const int * default_value = nullptr); + +// One option of a combo: a label and an optional muted description +struct combo_item +{ + const char * name; + const char * description = nullptr; +}; + +// Combo box whose options open in a modal list centred on the popup layer, +// instead of an inline dropdown. *selected is the chosen index, title labels +// the modal. Returns true when the selection changes. +bool combo(const char * id, const char * title, const std::vector & items, int * selected, float width = 0, const int * default_value = nullptr); + +// Centre (in imgui display coords) where combo modals open. Set once per frame +// from the lobby's popup layer before any combo() is drawn. +void set_popup_center(const ImVec2 & center); + +// Hook the widgets call after submitting an interactive item so it can fire a hover +// haptic (e.g. imgui_context::vibrate_on_hover). Install once from the lobby. +void set_hover_haptic(std::function hook); + +// Hook a widget calls to show a tooltip for the last submitted item (e.g. +// imgui_context::tooltip). Only called while the item is hovered. Install once. +void set_tooltip_hook(std::function hook); + +// Small status badge. The label may include a leading icon glyph; pass dot=true for +// a leading status dot in the style colour. Non-interactive. +enum class chip_style +{ + neutral, // control fill, normal text + muted, // control fill, muted text + accent, + success, + warning, + danger, +}; +void chip(const char * label, chip_style style = chip_style::neutral, bool dot = false); + +// Themed single-line text field, control height. hint is optional placeholder text. +// Returns true while the text is being edited. +bool input_text(const char * id, std::string & text, const char * hint = nullptr, float width = 0); + +// Number field with - / + stepper buttons. Returns true when the value changes. +bool input_int(const char * id, int * v, int step = 1, int v_min = 0, int v_max = 0, float width = 0); + +// Centered modal dialog on the popup layer, themed like a card with a title. Open it +// with ImGui::OpenPopup(id); call ImGui::CloseCurrentPopup() to dismiss. Pair with +// end_modal only when this returns true, exactly like ImGui::BeginPopupModal. +bool begin_modal(const char * id, const char * title, float width = 0); +void end_modal(); + +} // namespace wivrn::ui diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index bfdd3ca9..70551b19 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -121,6 +121,7 @@ class lobby : public scene_impl settings, post_processing, customize, + components, #if WIVRN_CLIENT_DEBUG_MENU debug, #endif @@ -227,6 +228,7 @@ class lobby : public scene_impl void gui_settings(); void gui_post_processing(); void gui_customize(XrTime predicted_display_time); + void gui_components(); void gui_debug_node_hierarchy(entt::entity root = entt::null); void gui_debug(); void gui_about(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 64f04ace..609b40b1 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -28,6 +28,8 @@ #include "gui_common.h" #include "imgui.h" #include "lobby.h" +#include "render/ui_theme.h" +#include "render/ui_widgets.h" #include "scenes/stream.h" // IWYU pragma: keep #include "utils/async.h" #include "utils/i18n.h" @@ -1749,6 +1751,20 @@ std::vector> scenes::lobby::draw_gui(XrTi update_file_picker(); ImGuiStyle & style = ImGui::GetStyle(); + style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base; + + // base text colour follows the theme so plain ImGui text is legible on light themes + style.Colors[ImGuiCol_Text] = wivrn::ui::current().text; + style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted; + + // combo modals open centred on the popup layer + const auto & ui_popup_layer = imgui_ctx->layers()[1]; + const glm::vec2 ui_popup_center = ui_popup_layer.vp_origin + ui_popup_layer.vp_size / 2; + wivrn::ui::set_popup_center({ui_popup_center.x, ui_popup_center.y}); + + // let the themed widgets fire the hover haptic and show tooltips + wivrn::ui::set_hover_haptic([this] { imgui_ctx->vibrate_on_hover(); }); + wivrn::ui::set_tooltip_hook([this](const char * text) { imgui_ctx->tooltip(text); }); const float TabWidth = 300; @@ -1759,7 +1775,9 @@ std::vector> scenes::lobby::draw_gui(XrTi } ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 30); - ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32(8, 8, 8, 224)); + // window background follows the theme, with a user-controlled opacity + const wivrn::ui::theme & th = wivrn::ui::current(); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4{th.background.x, th.background.y, th.background.z, th.background_alpha}); ImGui::SetNextWindowPos(imgui_ctx->layers()[0].vp_center(), ImGuiCond_Always, {0.5, 0.5}); @@ -1823,6 +1841,10 @@ std::vector> scenes::lobby::draw_gui(XrTi gui_customize(predicted_display_time); break; + case tab::components: + gui_components(); + break; + #if WIVRN_CLIENT_DEBUG_MENU case tab::debug: gui_debug(); @@ -1872,6 +1894,9 @@ std::vector> scenes::lobby::draw_gui(XrTi RadioButtonWithoutCheckBox(ICON_FA_PANORAMA " " + _("Customize"), current_tab, tab::customize, {TabWidth, 0}); imgui_ctx->vibrate_on_hover(); + RadioButtonWithoutCheckBox(ICON_FA_PALETTE " Components", current_tab, tab::components, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); + #if WIVRN_CLIENT_DEBUG_MENU RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), current_tab, tab::debug, {TabWidth, 0}); imgui_ctx->vibrate_on_hover(); diff --git a/client/scenes/lobby_gui_components.cpp b/client/scenes/lobby_gui_components.cpp new file mode 100644 index 00000000..ad157ff1 --- /dev/null +++ b/client/scenes/lobby_gui_components.cpp @@ -0,0 +1,324 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define IMGUI_DEFINE_MATH_OPERATORS + +#include "lobby.h" + +#include "render/ui_theme.h" +#include "render/ui_widgets.h" + +#include "imgui.h" + +#include "IconsFontAwesome6.h" + +namespace ui = wivrn::ui; + +// Card title shown above the rows +static void card_title(const char * title) +{ + ImGui::PushStyleColor(ImGuiCol_Text, ui::current().text_muted); + ImGui::TextUnformatted(title); + ImGui::PopStyleColor(); + ImGui::Dummy({0, 4}); +} + +void scenes::lobby::gui_components() +{ + ui::theme & theme = ui::current(); + + ui::page_header("Components", "Live preview of the WiVRn UI kit"); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + const float control_w = 480; + + // Theme + ui::begin_card("##theme"); + { + card_title("THEME"); + + // Accent + ImGui::TextUnformatted("Accent color"); + ImGui::Dummy({0, 2}); + for (const auto & swatch: ui::accent_swatches()) + { + const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z; + const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop); + if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f})) + ui::set_accent(swatch); + ImGui::SameLine(); + } + ImGui::NewLine(); + + ui::row_separator(); + + // Preset + static int preset = 1; // dark_default + const auto preset_list = ui::presets(); + std::vector preset_items; + for (const auto & p: preset_list) + preset_items.push_back({p.name.c_str()}); + + static const int preset_default = 1; + ui::setting_label("Preset", "Surface and background palette", control_w); + if (ui::combo("##preset", "Theme preset", preset_items, &preset, control_w, &preset_default)) + { + const ImVec4 keep_accent = theme.accent; + const ImVec4 keep_hover = theme.accent_hovered; + const ImVec4 keep_active = theme.accent_active; + ui::set_theme(preset_list[preset]); + theme.accent = keep_accent; + theme.accent_hovered = keep_hover; + theme.accent_active = keep_active; + } + + ui::row_separator(); + + // Rounding + static const int rounding_default = 8; + int rounding = int(theme.rounding); + ui::setting_label("Rounding", "Corner radius of controls", control_w); + if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default)) + theme.rounding = float(rounding); + + ui::row_separator(); + + static const int card_rounding_default = 14; + int card_rounding = int(theme.card_rounding); + ui::setting_label("Card rounding", "Corner radius of panels", control_w); + if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default)) + theme.card_rounding = float(card_rounding); + + ui::row_separator(); + + // Text size, applied globally via style.FontScaleMain next frame. 100% is the + // design default; the value is a user multiplier on metrics::font_base. + static const int font_scale_default = 100; + int font_scale = int(theme.font_scale * 100); + ui::setting_label("Text size", "Global font scale", control_w); + if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default)) + theme.font_scale = float(font_scale) / 100.f; + + ui::row_separator(); + + // Panel transparency + static const int opacity_default = 88; + int opacity = int(theme.background_alpha * 100); + ui::setting_label("Panel opacity", "Opacity of the main panel background", control_w); + if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) + theme.background_alpha = float(opacity) / 100.f; + + ui::end_card(); + } + + // Buttons + ui::begin_card("##buttons"); + { + card_title("BUTTONS"); + + ui::button("Primary", ui::button_style::primary); + ImGui::SameLine(); + ui::button("Secondary", ui::button_style::secondary); + ImGui::SameLine(); + ui::button(ICON_FA_POWER_OFF " Disconnect", ui::button_style::danger); + ImGui::SameLine(); + ui::button("Ghost", ui::button_style::ghost); + + ui::row_separator(); + + card_title("ICON BUTTONS"); + static bool mic = true; + if (ui::icon_button(ICON_FA_MICROPHONE, {}, mic, mic ? "Mute microphone" : "Unmute microphone")) + mic = not mic; + ImGui::SameLine(); + ui::icon_button(ICON_FA_EYE_SLASH, {}, false, "Toggle passthrough"); + ImGui::SameLine(); + ui::icon_button(ICON_FA_HAND, {}, false, "Hand tracking"); + ImGui::SameLine(); + ui::icon_button(ICON_FA_ARROW_ROTATE_LEFT, {}, false, "Recenter"); + + ui::end_card(); + } + + // Toggles + ui::begin_card("##toggles"); + { + card_title("TOGGLES"); + + // room for the toggle plus a trailing reset slot + const float toggle_w = ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect; + const float toggle_row_w = toggle_w + ImGui::GetFrameHeight() * ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.x; + + static const bool spacewarp_default = false; + static bool spacewarp = true; + ui::setting_label("Application SpaceWarp", "Synthesises in-between frames so motion stays smooth", toggle_row_w); + ui::toggle("##spacewarp", &spacewarp, &spacewarp_default); + + ui::row_separator(); + + static const bool high_power_default = true; + static bool high_power = true; + ui::setting_label("High power mode", "Higher sustained clocks for steadier frames", toggle_row_w); + ui::toggle("##high_power", &high_power, &high_power_default); + + ui::end_card(); + } + + // Sliders + ui::begin_card("##sliders"); + { + card_title("SLIDERS"); + + static const int resolution_default = 100; + static int resolution = 145; + ui::setting_label("Render resolution", "Pixels rendered per eye", control_w); + ui::slider_int("##resolution", &resolution, 50, 350, "%d%%", {control_w, 0}, &resolution_default); + + ui::row_separator(); + + static const int bitrate_default = 100; + static int bitrate = 165; + ui::setting_label("Bitrate", "Video data rate", control_w); + ui::slider_int("##bitrate", &bitrate, 10, 500, "%d Mbit/s", {control_w, 0}, &bitrate_default); + + ui::end_card(); + } + + // Segmented control + ui::begin_card("##segmented"); + { + card_title("SEGMENTED CONTROL"); + + static const int refresh_default = 0; + static int refresh = 2; + static const std::vector rates = {"Auto", "72", "80", "90", "120"}; + ui::setting_label("Refresh rate", "Frames per second shown in the headset", control_w); + ui::segmented("##refresh", rates, &refresh, {control_w, 0}, &refresh_default); + + ui::end_card(); + } + + // Combo + ui::begin_card("##combo"); + { + card_title("COMBO"); + + static const std::vector codecs = { + {"Automatic", "Picks the best codec your PC supports"}, + {"H.264", "Lowest latency, widest support"}, + {"HEVC (H.265)", "Better quality per bit"}, + {"AV1", "Best efficiency, newest GPUs only"}, + }; + static const int codec_default = 0; + static int selected = 2; + + ui::setting_label("Video codec", "How video is compressed and sent to the headset", control_w); + ui::combo("##codec", "Video codec", codecs, &selected, control_w, &codec_default); + + ui::end_card(); + } + + // Chips + ui::begin_card("##chips"); + { + card_title("CHIPS"); + + ui::chip(ICON_FA_BOLT " Auto", ui::chip_style::accent); + ImGui::SameLine(); + ui::chip(ICON_FA_BATTERY_HALF " 38%", ui::chip_style::success); + ImGui::SameLine(); + ui::chip("Connected", ui::chip_style::success, true); + ImGui::SameLine(); + ui::chip("Not connected", ui::chip_style::muted, true); + ImGui::SameLine(); + ui::chip("Unavailable", ui::chip_style::muted); + ImGui::SameLine(); + ui::chip("Beta", ui::chip_style::warning); + + ui::end_card(); + } + + // Text & number inputs + ui::begin_card("##inputs"); + { + card_title("INPUTS"); + + static std::string name, address; + static int port = 9757; + + ui::setting_label("Name", "Friendly label for the server", control_w); + ui::input_text("##name", name, "My gaming PC", control_w); + + ui::row_separator(); + + ui::setting_label("Address", "Hostname or IP of the PC", control_w); + ui::input_text("##address", address, "192.168.1.10 or host.local", control_w); + + ui::row_separator(); + + ui::setting_label("Port", "TCP/UDP port the server listens on", control_w); + ui::input_int("##port", &port, 1, 1, 65535, control_w); + + ui::end_card(); + } + + // Dialog + ui::begin_card("##dialog"); + { + card_title("DIALOG"); + + if (ui::button("Add server")) + ImGui::OpenPopup("##add_server_demo"); + + static std::string d_name, d_address; + static int d_port = 9757; + if (ui::begin_modal("##add_server_demo", "Add server", 620)) + { + const float w = ImGui::GetContentRegionAvail().x; + ImGui::TextUnformatted("Name"); + ui::input_text("##d_name", d_name, "My gaming PC", w); + ImGui::Dummy({0, 4}); + ImGui::TextUnformatted("Address"); + ui::input_text("##d_address", d_address, "192.168.1.10 or host.local", w); + ImGui::Dummy({0, 4}); + ImGui::TextUnformatted("Port"); + ui::input_int("##d_port", &d_port, 1, 1, 65535, w); + + ImGui::Dummy({0, 12}); + + // right-aligned footer + const float gap = ImGui::GetStyle().ItemSpacing.x; + const float cancel_w = ImGui::CalcTextSize("Cancel").x + ui::metrics::button_padding.x * 2; + const float save_w = ImGui::CalcTextSize("Save").x + ui::metrics::button_padding.x * 2; + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - cancel_w - save_w - gap); + + if (ui::button("Cancel", ui::button_style::secondary)) + ImGui::CloseCurrentPopup(); + ImGui::SameLine(); + if (ui::button("Save", ui::button_style::primary)) + ImGui::CloseCurrentPopup(); + + ui::end_modal(); + } + + ui::end_card(); + } + + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing +} From 45710151aa4b58332df267f430374231faf4acb0 Mon Sep 17 00:00:00 2001 From: ahsanswr Date: Sat, 13 Jun 2026 14:14:44 +0500 Subject: [PATCH 005/147] Add more components --- client/render/ui_widgets.cpp | 53 ++++++++++++++++++++++++++ client/render/ui_widgets.h | 7 ++++ client/scenes/lobby_gui_components.cpp | 35 +++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/client/render/ui_widgets.cpp b/client/render/ui_widgets.cpp index f45b4d60..19c5f6da 100644 --- a/client/render/ui_widgets.cpp +++ b/client/render/ui_widgets.cpp @@ -736,6 +736,59 @@ void chip(const char * label, chip_style style, bool dot) draw->AddText({tx, bb.Min.y + pad.y}, t.col(fg), label); } +void nav_section(const char * label) +{ + const theme & t = current(); + const ImGuiStyle & style = ImGui::GetStyle(); + + ImGui::Dummy({0, style.ItemSpacing.y * 0.5f}); + ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); + ImGui::TextUnformatted(label); + ImGui::PopStyleColor(); + ImGui::PopFont(); + ImGui::Dummy({0, 2}); +} + +bool nav_item(const char * icon, const char * label, bool selected) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + const theme & t = current(); + const ImGuiStyle & style = ImGui::GetStyle(); + + const float h = ImGui::GetFrameHeight() * metrics::control_height; + const float w = ImGui::GetContentRegionAvail().x; + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + ImVec2(w, h)); + ImGui::ItemSize(bb, style.FramePadding.y); + const ImGuiID gid = window->GetID(label); + if (not ImGui::ItemAdd(bb, gid)) + return false; + + bool hovered, held; + const bool pressed = ImGui::ButtonBehavior(bb, gid, &hovered, &held); + hover_haptic(); + + ImDrawList * draw = window->DrawList; + const ImVec4 bg = selected ? t.control : (hovered ? t.control_hovered : ImVec4{0, 0, 0, 0}); + if (bg.w > 0) + draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); + + const float pad = metrics::combo_padding.x; + const float icon_w = ImGui::GetFontSize() * 1.5f; // icon column + + const ImVec2 its = ImGui::CalcTextSize(icon); + draw->AddText({bb.Min.x + pad + (icon_w - its.x) * 0.5f, bb.Min.y + (h - its.y) * 0.5f}, t.col(selected ? t.accent : t.text_muted), icon); + + const ImVec2 ls = ImGui::CalcTextSize(label); + draw->AddText({bb.Min.x + pad + icon_w + pad * 0.5f, bb.Min.y + (h - ls.y) * 0.5f}, t.col(t.text), label); + + return pressed; +} + static int input_text_resize(ImGuiInputTextCallbackData * data) { if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) diff --git a/client/render/ui_widgets.h b/client/render/ui_widgets.h index 687163c9..d10f527d 100644 --- a/client/render/ui_widgets.h +++ b/client/render/ui_widgets.h @@ -105,6 +105,13 @@ enum class chip_style }; void chip(const char * label, chip_style style = chip_style::neutral, bool dot = false); +// Muted sidebar group header (e.g. "SETTINGS") +void nav_section(const char * label); + +// Sidebar entry: icon + label across the full width, highlighted when selected. +// Returns true when clicked. +bool nav_item(const char * icon, const char * label, bool selected); + // Themed single-line text field, control height. hint is optional placeholder text. // Returns true while the text is being edited. bool input_text(const char * id, std::string & text, const char * hint = nullptr, float width = 0); diff --git a/client/scenes/lobby_gui_components.cpp b/client/scenes/lobby_gui_components.cpp index ad157ff1..809f5368 100644 --- a/client/scenes/lobby_gui_components.cpp +++ b/client/scenes/lobby_gui_components.cpp @@ -234,6 +234,41 @@ void scenes::lobby::gui_components() ui::end_card(); } + // Navigation (sidebar styling) + ui::begin_card("##nav"); + { + card_title("NAVIGATION"); + + static int nav = 2; + int row = 0; + + if (ui::nav_item(ICON_FA_COMPUTER, "Computers", nav == row)) + nav = row; + ++row; + + ui::nav_section("SETTINGS"); + for (const auto & [icon, label]: { + std::pair{ICON_FA_GAUGE_HIGH, "Performance"}, + std::pair{ICON_FA_TOWER_BROADCAST, "Streaming"}, + std::pair{ICON_FA_CROP, "Field of view"}, + std::pair{ICON_FA_VOLUME_HIGH, "Audio"}, + std::pair{ICON_FA_LOCATION_CROSSHAIRS, "Tracking"}, + std::pair{ICON_FA_GEARS, "System"}, + }) + { + if (ui::nav_item(icon, label, nav == row)) + nav = row; + ++row; + } + + ui::nav_section("PERSONALIZE"); + if (ui::nav_item(ICON_FA_IMAGE, "Customize", nav == row)) + nav = row; + ++row; + + ui::end_card(); + } + // Chips ui::begin_card("##chips"); { From a5b1b6dbeba7a52f0291f3ce63b3bc5794991fa2 Mon Sep 17 00:00:00 2001 From: ahsanswr Date: Sat, 13 Jun 2026 17:36:19 +0500 Subject: [PATCH 006/147] Overhaul settings UI --- client/configuration.cpp | 180 ++-- client/render/imgui_impl.cpp | 13 +- client/render/ui_theme.h | 12 +- client/render/ui_widgets.cpp | 290 +++++- client/render/ui_widgets.h | 101 +- client/scenes/gui_common.cpp | 88 +- client/scenes/gui_common.h | 2 + client/scenes/lobby.h | 17 +- client/scenes/lobby_gui.cpp | 1313 +++++++----------------- client/scenes/lobby_gui_components.cpp | 4 + client/scenes/lobby_gui_customize.cpp | 426 +++----- client/scenes/lobby_gui_settings.cpp | 582 +++++++++++ 12 files changed, 1548 insertions(+), 1480 deletions(-) create mode 100644 client/scenes/lobby_gui_settings.cpp diff --git a/client/configuration.cpp b/client/configuration.cpp index 99fea686..e1db4d05 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -25,6 +25,10 @@ #include #include +#include +#include +#include +#include #ifdef __ANDROID__ #include "android/permissions.h" @@ -33,6 +37,99 @@ // If no refresh rate is configured, don't select a too high one static const float max_default_rate = 100; +namespace +{ +// Plain scalar settings whose JSON load/save is purely mechanical (key <-> member). +// Settings needing validation, optionals, enums, nested objects or maps are handled +// explicitly in the constructor and save() below. +using config_member = std::variant< + bool configuration::*, + float configuration::*, + uint32_t configuration::*, + std::string configuration::*>; + +struct config_field +{ + const char * key; + config_member member; +}; + +const std::vector & scalar_fields() +{ + static const std::vector fields = { + {"resolution_scale", &configuration::resolution_scale}, + {"bitrate_bps", &configuration::bitrate_bps}, + {"enable_stream_gui", &configuration::enable_stream_gui}, + {"passthrough_enabled", &configuration::passthrough_enabled}, + {"mic_unprocessed_audio", &configuration::mic_unprocessed_audio}, + {"forward_keyboard", &configuration::forward_keyboard}, + {"forward_mouse", &configuration::forward_mouse}, + {"forward_gamepad", &configuration::forward_gamepad}, + {"virtual_keyboard_layout", &configuration::virtual_keyboard_layout}, + {"override_foveation_enable", &configuration::override_foveation_enable}, + {"override_foveation_pitch", &configuration::override_foveation_pitch}, + {"override_foveation_distance", &configuration::override_foveation_distance}, + {"first_run", &configuration::first_run}, + {"locale", &configuration::locale}, + {"environment_model", &configuration::environment_model}, + {"high_power_mode", &configuration::high_power_mode}, + {"fps_divider", &configuration::fps_divider}, + {"extended_config", &configuration::extended_config}, + }; + return fields; +} + +void load_field(simdjson::dom::element root, configuration & c, const config_field & f) +{ + auto val = root[f.key]; + std::visit([&](auto mp) { + using T = std::remove_cvref_t; + if constexpr (std::is_same_v) + { + if (val.is_bool()) + c.*mp = val.get_bool(); + } + else if constexpr (std::is_same_v) + { + if (val.is_string()) + c.*mp = std::string(std::string_view(val.get_string().value())); + } + else if constexpr (std::is_same_v) + { + if (val.is_uint64()) + c.*mp = uint32_t(uint64_t(val.get_uint64())); + else if (val.is_int64() and int64_t(val.get_int64()) >= 0) + c.*mp = uint32_t(int64_t(val.get_int64())); + } + else // float + { + if (val.is_double()) + c.*mp = float(double(val.get_double())); + else if (val.is_int64()) + c.*mp = float(int64_t(val.get_int64())); + else if (val.is_uint64()) + c.*mp = float(uint64_t(val.get_uint64())); + } + }, + f.member); +} + +void save_field(std::ostream & json, const configuration & c, const config_field & f) +{ + std::visit([&](auto mp) { + using T = std::remove_cvref_t; + json << ",\"" << f.key << "\":"; + if constexpr (std::is_same_v) + json << std::boolalpha << (c.*mp); + else if constexpr (std::is_same_v) + json << json_string(c.*mp); + else + json << (c.*mp); + }, + f.member); +} +} // namespace + bool configuration::check_feature(feature f) const { { @@ -134,6 +231,11 @@ configuration::configuration(xr::system & system, xr::session & session) servers.emplace(data.service.txt["cookie"], data); } + // plain scalar settings + for (const auto & f: scalar_fields()) + load_field(root, *this, f); + + // settings that need more than a mechanical key <-> member mapping if (auto val = root["preferred_refresh_rate"]; val.is_double()) { float f = val.get_double(); @@ -144,9 +246,6 @@ configuration::configuration(xr::system & system, xr::session & session) if (auto val = root["minimum_refresh_rate"]; val.is_double()) minimum_refresh_rate = val.get_double(); - if (auto val = root["resolution_scale"]; val.is_double()) - resolution_scale = val.get_double(); - if (auto val = root["stream_scale"]; val.is_double()) stream_scale = val.get_double(); @@ -165,30 +264,9 @@ configuration::configuration(xr::system & system, xr::session & session) if (auto val = root["bit_depth"]; val.is_uint64()) bit_depth = val.get_uint64(); - if (auto val = root["bitrate_bps"]; val.is_number()) - bitrate_bps = val.get_uint64(); - - if (auto val = root["enable_stream_gui"]; val.is_bool()) - enable_stream_gui = val.get_bool(); - if (auto val = root["openxr_post_processing"]; val.is_object()) parse_openxr_post_processing_options(val.get_object()); - if (auto val = root["passthrough_enabled"]; val.is_bool()) - passthrough_enabled = val.get_bool(); - - if (auto val = root["mic_unprocessed_audio"]; val.is_bool()) - mic_unprocessed_audio = val.get_bool(); - - if (auto val = root["forward_keyboard"]; val.is_bool()) - forward_keyboard = val.get_bool(); - - if (auto val = root["forward_mouse"]; val.is_bool()) - forward_mouse = val.get_bool(); - - if (auto val = root["forward_gamepad"]; val.is_bool()) - forward_gamepad = val.get_bool(); - if (auto val = root["body_parts"]; val.is_object()) { for (const auto & [b, name]: magic_enum::enum_entries()) @@ -208,9 +286,6 @@ configuration::configuration(xr::system & system, xr::session & session) } } - if (auto val = root["virtual_keyboard_layout"]; val.is_string()) - virtual_keyboard_layout = val.get_string().value(); - for (const auto & [i, name]: magic_enum::enum_entries()) { if (auto val = root[name]; val.is_bool()) @@ -219,33 +294,6 @@ configuration::configuration(xr::system & system, xr::session & session) if (system.passthrough_supported() == xr::passthrough_type::none) passthrough_enabled = false; - - if (auto val = root["override_foveation_enable"]; val.is_bool()) - override_foveation_enable = val.get_bool(); - - if (auto val = root["override_foveation_pitch"]; val.is_double()) - override_foveation_pitch = val.get_double(); - - if (auto val = root["override_foveation_distance"]; val.is_double()) - override_foveation_distance = val.get_double(); - - if (auto val = root["first_run"]; val.is_bool()) - first_run = val.get_bool(); - - if (auto val = root["locale"]; val.is_string()) - locale = val.get_string().value(); - - if (auto val = root["environment_model"]; val.is_string()) - environment_model = (std::string_view)val.get_string(); - - if (auto val = root["high_power_mode"]; val.is_bool()) - high_power_mode = val.get_bool(); - - if (auto val = root["fps_divider"]; val.is_uint64()) - fps_divider = (uint32_t)val.get_uint64(); - - if (auto val = root["extended_config"]; val.is_bool()) - extended_config = val.get_bool(); } catch (std::exception & e) { @@ -305,23 +353,22 @@ void configuration::save() std::ofstream json(application::get_config_path() / "client.json"); json << "{\"servers\":[" << servers_str << "]"; + + // plain scalar settings + for (const auto & f: scalar_fields()) + save_field(json, *this, f); + + // settings with non-mechanical encoding json << ",\"preferred_refresh_rate\":" << preferred_refresh_rate; if (minimum_refresh_rate) json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate; - json << ",\"resolution_scale\":" << resolution_scale; if (stream_scale) json << ",\"stream_scale\":" << *stream_scale; if (codec) json << ",\"codec\":" << json_string(magic_enum::enum_name(*codec)); json << ",\"bit_depth\":" << (uint64_t)bit_depth; - json << ",\"bitrate_bps\":" << bitrate_bps; json << ",\"openxr_post_processing\":"; write_openxr_post_processing(json, openxr_post_processing); - json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled; - json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio; - json << ",\"forward_keyboard\":" << std::boolalpha << forward_keyboard; - json << ",\"forward_mouse\":" << std::boolalpha << forward_mouse; - json << ",\"forward_gamepad\":" << std::boolalpha << forward_gamepad; std::stringstream body_part_ss; for (const auto & [b, name]: magic_enum::enum_entries()) @@ -337,19 +384,8 @@ void configuration::save() json << ",\"body_parts\":{" << body_parts_str << "}"; } - json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui; for (auto & [key, value]: features) json << "," << key << ":" << std::boolalpha << value; - json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout); - json << ",\"override_foveation_enable\":" << std::boolalpha << override_foveation_enable; - json << ",\"override_foveation_pitch\":" << override_foveation_pitch; - json << ",\"override_foveation_distance\":" << override_foveation_distance; - json << ",\"first_run\":" << std::boolalpha << first_run; - json << ",\"locale\":" << json_string(locale); - json << ",\"environment_model\":" << json_string(environment_model); - json << ",\"high_power_mode\":" << std::boolalpha << high_power_mode; - json << ",\"fps_divider\":" << fps_divider; - json << ",\"extended_config\":" << std::boolalpha << extended_config; json << "}"; } diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index f78f5ca5..2b7fd3a2 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -1329,20 +1329,15 @@ void ScrollWhenDragging() static int active_id; static ImVec2 cumulated_delta; - // Suppress drag-scroll while a popup is open and for the frame one closes: in VR - // the ray snaps from the popup layer back to this window when the popup dismisses, - // which can synthesise a spurious click (see the focused-controller handling) that - // would otherwise start a scroll right after picking a combo value. + // Don't start a drag while a popup is open or just closed: in VR the ray snaps back + // and can synthesise a click that would scroll right after picking a combo value. static bool popup_was_open; const bool popup_open = ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel); bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true); bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true); - // Begin a drag-scroll only when the press lands on this window or one of its - // child panels and no widget grabbed it. IsWindowHovered(ChildWindows) lets the - // drag work over card child windows (ItemHoverable would fail there), and the - // g.ActiveId guard keeps manipulating a control (slider, toggle, combo...) from - // scrolling the page. Controls must claim the active id on press for this to hold. + // Start only over this window or a child panel with no active widget. ChildWindows + // lets it work over cards; the ActiveId guard keeps controls from scrolling the page. const bool over = ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows); if (active_id == 0 and g.ActiveId == 0 and not popup_open and not popup_was_open and over and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any)) { diff --git a/client/render/ui_theme.h b/client/render/ui_theme.h index 814576a7..41558af4 100644 --- a/client/render/ui_theme.h +++ b/client/render/ui_theme.h @@ -63,9 +63,13 @@ struct theme float font_scale; // global text size multiplier float background_alpha; // opacity of the main panel background, 0..1 + // Convert to packed color, applying the current global alpha so widgets drawn + // through the draw list dim with ImGui::BeginDisabled() (and any pushed alpha). ImU32 col(const ImVec4 & c) const { - return ImGui::ColorConvertFloat4ToU32(c); + ImVec4 v = c; + v.w *= ImGui::GetStyle().Alpha; + return ImGui::ColorConvertFloat4ToU32(v); } // Push colors and metrics into the global ImGui style @@ -100,11 +104,15 @@ constexpr float combo_chevron = 12; // chevron size in the closed box constexpr float combo_modal_min_width = 460; // popup never narrower than this constexpr ImVec2 combo_padding = {16, 0}; // horizontal inner padding of box and rows +constexpr float list_row_box = 52; // leading icon/thumbnail size in a list row +constexpr float list_row_pad = 16; // inner padding of a list row, both axes constexpr ImVec2 chip_padding = {12, 6}; // inner padding of a chip/badge constexpr float input_padding_x = 14; // horizontal text padding inside inputs constexpr float font_modal_title = 1.2; // modal heading, x base font size -constexpr float label_line_gap = 5; // title to description +constexpr float label_line_gap = 5; // title to description +constexpr float label_bottom_pad = 6; // breathing room below the description +constexpr float nav_section_gap = 18; // space above a sidebar section header } // namespace metrics // Theme in effect, call current().apply() after mutating diff --git a/client/render/ui_widgets.cpp b/client/render/ui_widgets.cpp index 19c5f6da..3a7a5647 100644 --- a/client/render/ui_widgets.cpp +++ b/client/render/ui_widgets.cpp @@ -59,36 +59,32 @@ static void hover_haptic() hover_haptic_hook(); } -// Show a tooltip for the last submitted item; caller ensures it is hovered. -static void show_tooltip(const char * text) +// Show a tooltip for the last item; caller ensures it is hovered +static void show_tooltip(const std::string & text) { - if (text and text[0] and tooltip_hook) - tooltip_hook(text); + if (not text.empty() and tooltip_hook) + tooltip_hook(text.c_str()); } -void page_header(const char * title, const char * subtitle) +void page_header(const std::string & title, const std::string & subtitle) { const theme & t = current(); ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * metrics::font_title); - ImGui::TextUnformatted(title); + ImGui::TextUnformatted(title.c_str()); ImGui::PopFont(); - if (subtitle and subtitle[0]) + if (not subtitle.empty()) { ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); - ImGui::TextUnformatted(subtitle); + ImGui::TextUnformatted(subtitle.c_str()); ImGui::PopStyleColor(); } ImGui::Dummy({0, ImGui::GetStyle().ItemSpacing.y}); } -// A card is purely a visual rounded panel, NOT a child window: its content is -// laid out directly in the parent window so the page stays a single scroll -// surface (drag-to-scroll and clicks behave uniformly everywhere). The panel is -// drawn behind the upcoming content using the height measured last frame, then -// the full extent is reserved so layout and scrolling account for it. -// Always pair begin_card with end_card. +// A card is a visual rounded panel, not a child window, so the page stays one scroll +// surface. Drawn behind the content using last frame's height; pair with end_card. namespace { struct card_frame @@ -161,7 +157,7 @@ void row_separator() ImGui::PopStyleColor(); } -void setting_label(const char * title, const char * description, float control_width) +float setting_label(const std::string & title, const std::string & description, float control_width) { const theme & t = current(); const ImGuiStyle & style = ImGui::GetStyle(); @@ -174,31 +170,31 @@ void setting_label(const char * title, const char * description, float control_w ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {style.ItemSpacing.x, metrics::label_line_gap}); ImGui::PushTextWrapPos(start.x + text_w); - ImGui::TextUnformatted(title); - if (description and description[0]) + ImGui::TextUnformatted(title.c_str()); + if (not description.empty()) { - ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * metrics::font_description); + ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); - ImGui::TextUnformatted(description); + ImGui::TextUnformatted(description.c_str()); ImGui::PopStyleColor(); ImGui::PopFont(); } ImGui::PopTextWrapPos(); ImGui::PopStyleVar(); - // right-aligned control slot, vertically centered against the label block. - // Controls are control_height x frame height, so centre against that. + // right-aligned control slot, vertically centered against the label block const float label_h = ImGui::GetCursorPos().y - start.y; const float ctrl_h = ImGui::GetFrameHeight() * metrics::control_height; const float ctrl_y = start.y + ImMax(0.f, (label_h - ctrl_h) * 0.5f); ImGui::SetCursorPos({start.x + avail - control_width, ctrl_y}); + return start.y + label_h; } -bool button(const char * label, button_style s, const ImVec2 & size) +bool button(const std::string & label, button_style s, const ImVec2 & size) { const theme & t = current(); - // default to the shared control height; width still auto-fits the label + // control height by default, width auto-fits the label const float h = size.y > 0 ? size.y : ImGui::GetFrameHeight() * metrics::control_height; switch (s) @@ -231,14 +227,14 @@ bool button(const char * label, button_style s, const ImVec2 & size) ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, t.rounding); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, metrics::button_padding); - const bool pressed = ImGui::Button(label, {size.x, h}); + const bool pressed = ImGui::Button(label.c_str(), {size.x, h}); ImGui::PopStyleVar(2); ImGui::PopStyleColor(4); hover_haptic(); return pressed; } -bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const char * tooltip) +bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const std::string & tooltip) { ImGuiWindow * window = ImGui::GetCurrentWindow(); if (window->SkipItems) @@ -274,9 +270,7 @@ bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const ImDrawList * draw = window->DrawList; draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); - // glyph drawn manually so it scales with the button. Centre on the glyph's real - // ink box (X0..X1, Y0..Y1) rather than CalcTextSize, which returns the advance - // width and line height and leaves the glyph up-and-left of true centre. + // centre the glyph on its ink box, not CalcTextSize (which includes bearing/leading) const float glyph_size = size.y * metrics::icon_button_glyph; ImGui::PushFont(nullptr, glyph_size); const ImU32 col = t.col(active ? t.on_accent : t.text); @@ -298,15 +292,13 @@ bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const } // Horizontal space a trailing reset slot consumes, gap included -static float reset_slot_width() +float reset_slot_width() { return ImGui::GetFrameHeight() * metrics::control_height + ImGui::GetStyle().ItemSpacing.x; } -// Trailing reset affordance placed on the same row as a value control, right after -// it (the control should have shrunk its width by reset_slot_width() to make room). -// Draws a reset icon button when show is true, or an empty slot when false so the -// right edge stays put. Returns true when the user taps reset. +// Trailing reset button on a value control's row; empty slot when show is false so the +// right edge stays put. Returns true when tapped. static bool reset_slot(const char * id, bool show) { const float side = ImGui::GetFrameHeight() * metrics::control_height; @@ -567,7 +559,7 @@ void set_popup_center(const ImVec2 & center) popup_center = center; } -bool combo(const char * id, const char * title, const std::vector & items, int * selected, float width, const int * default_value) +bool combo(const char * id, const std::string & title, const std::vector & items, int * selected, float width, const int * default_value) { ImGuiWindow * window = ImGui::GetCurrentWindow(); if (window->SkipItems or items.empty()) @@ -636,10 +628,10 @@ bool combo(const char * id, const char * title, const std::vector & bool changed = false; if (ImGui::BeginPopupModal(popup_id, nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) { - if (title and title[0]) + if (not title.empty()) { ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); - ImGui::TextUnformatted(title); + ImGui::TextUnformatted(title.c_str()); ImGui::PopStyleColor(); ImGui::Dummy({0, style.ItemSpacing.y}); } @@ -654,10 +646,7 @@ bool combo(const char * id, const char * title, const std::vector & } } - // tapping outside the list dismisses without changing the selection. - // AllowWhenBlockedByActiveItem is required: pressing a row sets it as the active - // item, which would otherwise make IsWindowHovered return false on the press - // frame and close the modal before the row's release registers the selection. + // click outside dismisses; AllowWhenBlockedByActiveItem so pressing a row still counts as inside if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) ImGui::CloseCurrentPopup(); @@ -676,7 +665,7 @@ bool combo(const char * id, const char * title, const std::vector & return changed; } -void chip(const char * label, chip_style style, bool dot) +void chip(const std::string & label, chip_style style, bool dot, float height) { ImGuiWindow * window = ImGui::GetCurrentWindow(); if (window->SkipItems) @@ -712,11 +701,11 @@ void chip(const char * label, chip_style style, bool dot) break; } - const ImVec2 ts = ImGui::CalcTextSize(label); + const ImVec2 ts = ImGui::CalcTextSize(label.c_str()); const ImVec2 pad = metrics::chip_padding; const float dot_r = ts.y * 0.26f; const float dot_gap = dot ? dot_r * 2 + pad.x * 0.55f : 0; - const ImVec2 size = {ts.x + pad.x * 2 + dot_gap, ts.y + pad.y * 2}; + const ImVec2 size = {ts.x + pad.x * 2 + dot_gap, height > 0 ? height : ts.y + pad.y * 2}; const ImVec2 pos = window->DC.CursorPos; const ImRect bb(pos, pos + size); @@ -733,24 +722,26 @@ void chip(const char * label, chip_style style, bool dot) draw->AddCircleFilled({tx + dot_r, bb.Min.y + size.y * 0.5f}, dot_r, t.col(fg)); tx += dot_r * 2 + pad.x * 0.55f; } - draw->AddText({tx, bb.Min.y + pad.y}, t.col(fg), label); + draw->AddText({tx, bb.Min.y + (size.y - ts.y) * 0.5f}, t.col(fg), label.c_str()); } -void nav_section(const char * label) +void nav_section(const std::string & label) { const theme & t = current(); const ImGuiStyle & style = ImGui::GetStyle(); - ImGui::Dummy({0, style.ItemSpacing.y * 0.5f}); + ImGui::Dummy({0, metrics::nav_section_gap}); // gap above the section + ImGui::Indent(metrics::combo_padding.x); // align with the nav_item icons ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); - ImGui::TextUnformatted(label); + ImGui::TextUnformatted(label.c_str()); ImGui::PopStyleColor(); ImGui::PopFont(); - ImGui::Dummy({0, 2}); + ImGui::Unindent(metrics::combo_padding.x); + ImGui::Dummy({0, 4}); } -bool nav_item(const char * icon, const char * label, bool selected) +bool nav_item(const char * icon, const std::string & label, bool selected) { ImGuiWindow * window = ImGui::GetCurrentWindow(); if (window->SkipItems) @@ -764,7 +755,7 @@ bool nav_item(const char * icon, const char * label, bool selected) const ImVec2 pos = window->DC.CursorPos; const ImRect bb(pos, pos + ImVec2(w, h)); ImGui::ItemSize(bb, style.FramePadding.y); - const ImGuiID gid = window->GetID(label); + const ImGuiID gid = window->GetID(label.c_str()); if (not ImGui::ItemAdd(bb, gid)) return false; @@ -783,8 +774,8 @@ bool nav_item(const char * icon, const char * label, bool selected) const ImVec2 its = ImGui::CalcTextSize(icon); draw->AddText({bb.Min.x + pad + (icon_w - its.x) * 0.5f, bb.Min.y + (h - its.y) * 0.5f}, t.col(selected ? t.accent : t.text_muted), icon); - const ImVec2 ls = ImGui::CalcTextSize(label); - draw->AddText({bb.Min.x + pad + icon_w + pad * 0.5f, bb.Min.y + (h - ls.y) * 0.5f}, t.col(t.text), label); + const ImVec2 ls = ImGui::CalcTextSize(label.c_str()); + draw->AddText({bb.Min.x + pad + icon_w + pad * 0.5f, bb.Min.y + (h - ls.y) * 0.5f}, t.col(t.text), label.c_str()); return pressed; } @@ -867,7 +858,7 @@ bool input_int(const char * id, int * v, int step, int v_min, int v_max, float w return changed; } -bool begin_modal(const char * id, const char * title, float width) +bool begin_modal(const char * id, const std::string & title, float width) { const theme & t = current(); const ImGuiStyle & style = ImGui::GetStyle(); @@ -890,10 +881,10 @@ bool begin_modal(const char * id, const char * title, float width) const bool open = ImGui::BeginPopupModal(id, nullptr, flags); if (open) { - if (title and title[0]) + if (not title.empty()) { ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_modal_title); - ImGui::TextUnformatted(title); + ImGui::TextUnformatted(title.c_str()); ImGui::PopFont(); ImGui::Dummy({0, style.ItemSpacing.y}); } @@ -913,4 +904,193 @@ void end_modal() ImGui::PopStyleColor(3); } +int confirm_modal(const char * id, const std::string & title, const std::string & message, const std::string & confirm_label, const std::string & cancel_label, bool danger) +{ + int result = 0; + if (begin_modal(id, title, 520)) + { + const theme & t = current(); + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); + ImGui::TextWrapped("%s", message.c_str()); + ImGui::PopStyleColor(); + ImGui::Dummy({0, 12}); + + const float gap = ImGui::GetStyle().ItemSpacing.x; + const float cancel_w = ImGui::CalcTextSize(cancel_label.c_str()).x + metrics::button_padding.x * 2; + const float confirm_w = ImGui::CalcTextSize(confirm_label.c_str()).x + metrics::button_padding.x * 2; + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - cancel_w - confirm_w - gap); + if (button(cancel_label, button_style::secondary, {cancel_w, 0})) + { + result = -1; + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (button(confirm_label, danger ? button_style::danger : button_style::primary, {confirm_w, 0})) + { + result = 1; + ImGui::CloseCurrentPopup(); + } + end_modal(); + } + return result; +} + +namespace +{ +std::vector list_row_after; // cursor to restore at end_list_row +} + +list_row_result begin_list_row(const char * id, const char * icon, ImTextureID image, const std::string & title, const std::string & subtitle, bool selected, float trailing_width, float height) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + const theme & t = current(); + const ImGuiStyle & style = ImGui::GetStyle(); + + // measure title + (possibly multi-line) subtitle so the row can auto-size + const float pad = metrics::list_row_pad; + const float box = metrics::list_row_box; + const ImVec2 ts = ImGui::CalcTextSize(title.c_str()); + ImVec2 sub_sz{0, 0}; + if (not subtitle.empty()) + { + ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); + sub_sz = ImGui::CalcTextSize(subtitle.c_str()); + ImGui::PopFont(); + } + const float text_h = ts.y + (subtitle.empty() ? 0 : metrics::label_line_gap + sub_sz.y); + const float row_h = height > 0 ? height : ImMax(box, text_h) + 2 * pad; + const ImVec2 p0 = window->DC.CursorPos; + const float avail = ImGui::GetContentRegionAvail().x; + + // the click area excludes the trailing controls so they receive their own clicks + ImGui::SetNextItemAllowOverlap(); + const bool clicked = ImGui::InvisibleButton(id, {ImMax(avail - trailing_width, 1.f), row_h}); + const bool hovered = ImGui::IsItemHovered(); + hover_haptic(); + list_row_after.push_back(window->DC.CursorPos); + + ImDrawList * draw = window->DrawList; + const ImRect bb(p0, p0 + ImVec2(avail, row_h)); + if (selected) + draw->AddRectFilled(bb.Min, bb.Max, t.col({t.accent.x, t.accent.y, t.accent.z, 0.16f}), t.card_rounding); + else if (hovered) + draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.card_rounding); + + // leading thumbnail or icon box + const ImVec2 box_min = {p0.x + pad, p0.y + (row_h - box) * 0.5f}; + const ImVec2 box_max = box_min + ImVec2(box, box); + if (image) + draw->AddImageRounded(image, box_min, box_max, {0, 0}, {1, 1}, IM_COL32_WHITE, t.rounding); + else + { + draw->AddRectFilled(box_min, box_max, t.col(selected ? t.accent : t.control), t.rounding); + if (icon and icon[0]) + { + const ImVec2 is = ImGui::CalcTextSize(icon); + draw->AddText(box_min + (ImVec2(box, box) - is) * 0.5f, t.col(selected ? t.on_accent : t.text_muted), icon); + } + } + + // title + subtitle + const float tx = box_max.x + pad; + const float total = subtitle.empty() ? ts.y : ts.y + metrics::label_line_gap + sub_sz.y; + const float ty = p0.y + (row_h - total) * 0.5f; + draw->AddText({tx, ty}, t.col(t.text), title.c_str()); + if (not subtitle.empty()) + { + ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); + draw->AddText({tx, ty + ts.y + metrics::label_line_gap}, t.col(t.text_muted), subtitle.c_str()); + ImGui::PopFont(); + } + + // trailing controls right-align against the inner padding + return {bb.Min, {bb.Max.x - pad, bb.Max.y}, clicked}; +} + +void end_list_row() +{ + ImGui::GetCurrentWindow()->DC.CursorPos = list_row_after.back(); + list_row_after.pop_back(); +} + +int action_menu(const char * id, const char * icon, const std::vector & items) +{ + const theme & t = current(); + + if (icon_button(icon, {}, false)) + ImGui::OpenPopup(id); + + int chosen = -1; + + const float pad = metrics::combo_padding.x; + const float icon_w = ImGui::GetFontSize() * 1.5f; + float content_w = 0; + for (const auto & it: items) + content_w = ImMax(content_w, icon_w + pad + ImGui::CalcTextSize(it.label).x + pad * 2 + ImGui::GetFontSize()); + + // centred modal on the popup layer, like combo() + ImGui::SetNextWindowPos(popup_center, ImGuiCond_Always, {0.5f, 0.5f}); + ImGui::SetNextWindowSize({ImMax(content_w, metrics::combo_modal_min_width), 0}); + + ImGui::PushStyleColor(ImGuiCol_PopupBg, t.card); + ImGui::PushStyleColor(ImGuiCol_Border, t.border); + ImGui::PushStyleColor(ImGuiCol_Text, t.text); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, t.card_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, metrics::card_padding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, t.border_size > 0 ? t.border_size : 1); + + if (ImGui::BeginPopupModal(id, nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGuiWindow * window = ImGui::GetCurrentWindow(); + const float row_h = ImGui::GetFrameHeight() * metrics::control_height; + + for (int i = 0; i < int(items.size()); ++i) + { + const action_item & it = items[i]; + ImGui::PushID(i); + const float row_w = ImGui::GetContentRegionAvail().x; + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + ImVec2(row_w, row_h)); + ImGui::ItemSize(bb, 0); + const ImGuiID gid = window->GetID("##row"); + if (ImGui::ItemAdd(bb, gid)) + { + bool hovered, held; + if (ImGui::ButtonBehavior(bb, gid, &hovered, &held)) + { + chosen = i; + ImGui::CloseCurrentPopup(); + } + hover_haptic(); + + ImDrawList * draw = window->DrawList; + if (hovered) + draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control_hovered), t.rounding); + + const ImU32 fg = t.col(it.danger ? t.danger : t.text); + const ImVec2 its = ImGui::CalcTextSize(it.icon); + draw->AddText({bb.Min.x + pad + (icon_w - its.x) * 0.5f, bb.Min.y + (row_h - its.y) * 0.5f}, fg, it.icon); + const ImVec2 ls = ImGui::CalcTextSize(it.label); + draw->AddText({bb.Min.x + pad + icon_w, bb.Min.y + (row_h - ls.y) * 0.5f}, fg, it.label); + if (it.checked) + { + const ImVec2 cs = ImGui::CalcTextSize(ICON_FA_CHECK); + draw->AddText({bb.Max.x - pad - cs.x, bb.Min.y + (row_h - cs.y) * 0.5f}, t.col(t.accent), ICON_FA_CHECK); + } + } + ImGui::PopID(); + } + + // click outside dismisses; AllowWhenBlockedByActiveItem so pressing a row still counts as inside + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + ImGui::CloseCurrentPopup(); + + ImGui::EndPopup(); + } + + ImGui::PopStyleVar(3); + ImGui::PopStyleColor(3); + return chosen; +} + } // namespace wivrn::ui diff --git a/client/render/ui_widgets.h b/client/render/ui_widgets.h index d10f527d..3684948f 100644 --- a/client/render/ui_widgets.h +++ b/client/render/ui_widgets.h @@ -24,8 +24,8 @@ #include #include -// Themed, reusable UI widgets matching the WiVRn dashboard design. -// All widgets read colors and metrics from wivrn::ui::current(). +// Themed, reusable UI widgets. Colors and metrics come from wivrn::ui::current(). +// Display text is taken by const std::string &; ids and icon glyphs stay const char *. namespace wivrn::ui { @@ -38,62 +38,54 @@ enum class button_style }; // Page title with an optional muted subtitle -void page_header(const char * title, const char * subtitle = nullptr); +void page_header(const std::string & title, const std::string & subtitle = {}); -// Rounded panel, pair with end_card. Returns false when fully clipped +// Rounded panel, pair with end_card bool begin_card(const char * id, const ImVec2 & size = {0, 0}); void end_card(); // Full-width divider between rows of a card void row_separator(); -// Bold title + wrapped muted description in a left column, -// leaving control_width on the right for a right-aligned control -void setting_label(const char * title, const char * description, float control_width); +// Title and wrapped muted description on the left, control_width reserved on the right. +// Returns the window-local y of the label bottom, so the caller can keep the row tall +// enough for a multi-line label. +float setting_label(const std::string & title, const std::string & description, float control_width); -bool button(const char * label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); -// tooltip, if given, is shown while the button is hovered -bool icon_button(const char * icon, const ImVec2 & size = {0, 0}, bool active = false, const char * tooltip = nullptr); +bool button(const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); +// tooltip, if not empty, is shown while hovered +bool icon_button(const char * icon, const ImVec2 & size = {0, 0}, bool active = false, const std::string & tooltip = {}); bool toggle(const char * id, bool * v, const bool * default_value = nullptr); -// Value controls below take an optional default_value. When given and the current -// value differs from it, a reset icon button is drawn in a trailing slot; tapping it -// restores the default. When the value matches (or no default is given) the slot is -// left empty so the control's right edge stays put. +// Width a trailing reset slot consumes (gap + square), for laying out toggles +float reset_slot_width(); -// Filled bar slider with the value centered on the rail +// The value controls below draw a reset button when the value differs from default_value bool slider_int(const char * id, int * v, int v_min, int v_max, const char * format, const ImVec2 & size = {0, 0}, const int * default_value = nullptr); // Pill group, *selected is the index of the active option bool segmented(const char * id, const std::vector & options, int * selected, const ImVec2 & size = {0, 0}, const int * default_value = nullptr); -// One option of a combo: a label and an optional muted description struct combo_item { const char * name; const char * description = nullptr; }; -// Combo box whose options open in a modal list centred on the popup layer, -// instead of an inline dropdown. *selected is the chosen index, title labels -// the modal. Returns true when the selection changes. -bool combo(const char * id, const char * title, const std::vector & items, int * selected, float width = 0, const int * default_value = nullptr); +// Combo box whose options open in a modal list on the popup layer. *selected is the +// chosen index, title labels the modal. Returns true when the selection changes. +bool combo(const char * id, const std::string & title, const std::vector & items, int * selected, float width = 0, const int * default_value = nullptr); -// Centre (in imgui display coords) where combo modals open. Set once per frame -// from the lobby's popup layer before any combo() is drawn. +// Centre (display coords) where combo and begin_modal popups open. Set once per frame. void set_popup_center(const ImVec2 & center); -// Hook the widgets call after submitting an interactive item so it can fire a hover -// haptic (e.g. imgui_context::vibrate_on_hover). Install once from the lobby. +// Hook fired after an interactive item, for a hover haptic. Install once. void set_hover_haptic(std::function hook); -// Hook a widget calls to show a tooltip for the last submitted item (e.g. -// imgui_context::tooltip). Only called while the item is hovered. Install once. +// Hook to show a tooltip for the last item. Install once. void set_tooltip_hook(std::function hook); -// Small status badge. The label may include a leading icon glyph; pass dot=true for -// a leading status dot in the style colour. Non-interactive. enum class chip_style { neutral, // control fill, normal text @@ -103,26 +95,53 @@ enum class chip_style warning, danger, }; -void chip(const char * label, chip_style style = chip_style::neutral, bool dot = false); +// Status badge. label may include a leading icon glyph; dot draws a status dot. +// height overrides the pill height (default sizes to the text + padding) +void chip(const std::string & label, chip_style style = chip_style::neutral, bool dot = false, float height = 0); -// Muted sidebar group header (e.g. "SETTINGS") -void nav_section(const char * label); +// Muted sidebar group header +void nav_section(const std::string & label); -// Sidebar entry: icon + label across the full width, highlighted when selected. -// Returns true when clicked. -bool nav_item(const char * icon, const char * label, bool selected); +// Sidebar entry: icon + label, highlighted when selected. Returns true when clicked +bool nav_item(const char * icon, const std::string & label, bool selected); -// Themed single-line text field, control height. hint is optional placeholder text. -// Returns true while the text is being edited. +// Single-line text field at control height; hint is optional placeholder text bool input_text(const char * id, std::string & text, const char * hint = nullptr, float width = 0); -// Number field with - / + stepper buttons. Returns true when the value changes. +// Number field with - / + stepper buttons. Returns true when the value changes bool input_int(const char * id, int * v, int step = 1, int v_min = 0, int v_max = 0, float width = 0); -// Centered modal dialog on the popup layer, themed like a card with a title. Open it -// with ImGui::OpenPopup(id); call ImGui::CloseCurrentPopup() to dismiss. Pair with -// end_modal only when this returns true, exactly like ImGui::BeginPopupModal. -bool begin_modal(const char * id, const char * title, float width = 0); +// Centred modal on the popup layer. Open with ImGui::OpenPopup(id), dismiss with +// ImGui::CloseCurrentPopup(); pair with end_modal only when this returns true. +bool begin_modal(const char * id, const std::string & title, float width = 0); void end_modal(); +struct action_item +{ + const char * icon; + const char * label; + bool danger = false; + bool checked = false; +}; + +// Overflow button: an icon button opening a popup of actions. Returns the picked index, or -1 +int action_menu(const char * id, const char * icon, const std::vector & items); + +struct list_row_result +{ + ImVec2 min, max; // row rect (screen) for right-aligning trailing controls + bool clicked; // the row body was clicked +}; + +// List row: leading thumbnail (image, if non-zero) or icon box, title and muted subtitle. +// trailing_width reserves space on the right for trailing controls and excludes it from +// the row's click area. Place controls right-aligned at .max with SetCursorScreenPos, +// then call end_list_row(). +list_row_result begin_list_row(const char * id, const char * icon, ImTextureID image, const std::string & title, const std::string & subtitle, bool selected = false, float trailing_width = 0, float height = 0); +void end_list_row(); + +// Confirmation dialog (open with ImGui::OpenPopup(id)). Returns 1 if confirmed, -1 if +// cancelled or dismissed, 0 otherwise. danger styles the confirm button as destructive. +int confirm_modal(const char * id, const std::string & title, const std::string & message, const std::string & confirm_label, const std::string & cancel_label, bool danger = false); + } // namespace wivrn::ui diff --git a/client/scenes/gui_common.cpp b/client/scenes/gui_common.cpp index 20d13112..1318f0c4 100644 --- a/client/scenes/gui_common.cpp +++ b/client/scenes/gui_common.cpp @@ -23,6 +23,8 @@ #include "configuration.h" #include "constants.h" #include "render/imgui_impl.h" +#include "render/ui_theme.h" +#include "render/ui_widgets.h" #include "utils/i18n.h" #include "wivrn_packets.h" @@ -35,6 +37,10 @@ namespace wivrn::gui { +float toggle_width() +{ + return ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect; +} std::string rate_label(float rate, uint32_t divider) { @@ -130,71 +136,49 @@ bool body_tracking_parts( return false; const std::array body_parts{ - std::make_pair(from_headset::body_part_mask::chest, _C("virtual body tracker selection", "Chest")), - std::make_pair(from_headset::body_part_mask::left_elbow, _C("virtual body tracker selection", "Left elbow")), - std::make_pair(from_headset::body_part_mask::right_elbow, _C("virtual body tracker selection", "Right elbow")), - std::make_pair(from_headset::body_part_mask::hip, _C("virtual body tracker selection", "Hip")), - std::make_pair(from_headset::body_part_mask::left_knee, _C("virtual body tracker selection", "Left knee")), - std::make_pair(from_headset::body_part_mask::right_knee, _C("virtual body tracker selection", "Right knee")), - std::make_pair(from_headset::body_part_mask::left_foot, _C("virtual body tracker selection", "Left foot")), - std::make_pair(from_headset::body_part_mask::right_foot, _C("virtual body tracker selection", "Right foot")), + std::make_tuple(from_headset::body_part_mask::chest, "##chest", _C("virtual body tracker selection", "Chest")), + std::make_tuple(from_headset::body_part_mask::left_elbow, "##left_elbow", _C("virtual body tracker selection", "Left elbow")), + std::make_tuple(from_headset::body_part_mask::right_elbow, "##right_elbow", _C("virtual body tracker selection", "Right elbow")), + std::make_tuple(from_headset::body_part_mask::hip, "##hip", _C("virtual body tracker selection", "Hip")), + std::make_tuple(from_headset::body_part_mask::left_knee, "##left_knee", _C("virtual body tracker selection", "Left knee")), + std::make_tuple(from_headset::body_part_mask::right_knee, "##right_knee", _C("virtual body tracker selection", "Right knee")), + std::make_tuple(from_headset::body_part_mask::left_foot, "##left_foot", _C("virtual body tracker selection", "Left foot")), + std::make_tuple(from_headset::body_part_mask::right_foot, "##right_foot", _C("virtual body tracker selection", "Right foot")), }; bool changed = false; - bool button_pressed = ImGui::ArrowButton("##OpenBodyPartMenu", ImGuiDir_Down); - ImGui::SameLine(0.f, ImGui::GetStyle().ItemInnerSpacing.x); - ImGui::Text("%s", _S("Virtual body trackers")); - if (button_pressed) - ImGui::OpenPopup("body part menu"); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + ui::begin_card("##body_tracking_parts"); - const auto & popup_layer = imgui_ctx.layers()[1]; - const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2; - ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size); - - if (ImGui::BeginPopupModal("body part menu", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) + for (const auto & [bit, id, name]: body_parts) { - const float height = ImGui::GetFrameHeight(); - const ImVec2 size(height, height); + if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip) + continue; - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f)); - ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - size.x); - if (ImGui::Button("X", size)) - ImGui::CloseCurrentPopup(); - imgui_ctx.vibrate_on_hover(); - ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive + const auto underlying = std::to_underlying(bit); + bool enabled = config.body_part_mask & underlying; - for (const auto & [bit, name]: body_parts) + const float label_bottom = ui::setting_label(name, "", toggle_width()); + if (ui::toggle(id, &enabled)) { - if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip) - continue; + if (enabled) + config.body_part_mask |= underlying; + else + config.body_part_mask &= ~underlying; - const auto underlying = std::to_underlying(bit); - bool enabled = config.body_part_mask & underlying; - if (ImGui::Checkbox(name.c_str(), &enabled)) - { - if (enabled) - { - config.body_part_mask |= underlying; - } - else - { - config.body_part_mask &= ~underlying; - } - config.save(); - changed = true; - imgui_ctx.vibrate_on_hover(); - } + config.save(); + changed = true; } - ImGui::EndPopup(); + // keep the row tall enough for a multi-line description and add breathing room + // below. Reserve with Dummy (SetCursorPos would not grow the content size). + const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad; + ImGui::Dummy({0, pad}); } - ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize + + ui::end_card(); + ImGui::PopStyleVar(); return changed; } diff --git a/client/scenes/gui_common.h b/client/scenes/gui_common.h index f6e21975..7216cf2e 100644 --- a/client/scenes/gui_common.h +++ b/client/scenes/gui_common.h @@ -50,5 +50,7 @@ bool post_processing( imgui_context & imgui_ctx, configuration & config); +float toggle_width(); + } // namespace gui } // namespace wivrn diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 70551b19..afe7eafd 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -118,11 +118,16 @@ class lobby : public scene_impl { first_run, server_list, - settings, + performance, + streaming, post_processing, + audio, + devices, + tracking, + system, customize, - components, #if WIVRN_CLIENT_DEBUG_MENU + components, debug, #endif about, @@ -218,14 +223,18 @@ class lobby : public scene_impl std::pair debug_primitive_to_highlight = {entt::null, 0}; #endif - void draw_features_status(XrTime predicted_display_time); void gui_connecting(locked_notifiable & request); void gui_enter_pin(locked_notifiable & request); void gui_connected(XrTime predicted_display_time); void gui_disconnected(); void gui_server_list(); void gui_new_server(); - void gui_settings(); + void gui_performance(); + void gui_streaming(); + void gui_audio(); + void gui_devices(); + void gui_tracking(); + void gui_system(); void gui_post_processing(); void gui_customize(XrTime predicted_display_time); void gui_components(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 609b40b1..85110564 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -284,79 +284,58 @@ void scenes::lobby::gui_disconnected() void scenes::lobby::gui_new_server() { - using constants::style::button_size; + namespace ui = wivrn::ui; - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20}); - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, {10, 10}); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); - ImGui::Dummy({1000, 1}); - - if (ImGui::BeginTable("table", 2)) - { - ImGui::TableSetupColumn("Field name", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableSetupColumn("Field value", ImGuiTableColumnFlags_WidthStretch); - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - // Make sure the label is vertically centered wrt the text input - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y); - ImGui::Text("%s", _S("Name")); - - ImGui::TableNextColumn(); - if (ImGui::IsWindowAppearing()) - ImGui::SetKeyboardFocusHere(); - InputText("##Name", add_server_window_prettyname, {ImGui::GetContentRegionAvail().x, 0}, 0); - imgui_ctx->vibrate_on_hover(); - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y); - ImGui::Text("%s", _S("Address")); - - ImGui::TableNextColumn(); - InputText("##Hostname", add_server_window_hostname, {ImGui::GetContentRegionAvail().x, 0}, 0); - imgui_ctx->vibrate_on_hover(); - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y); - ImGui::Text("%s", _S("Port")); - - ImGui::TableNextColumn(); - ImGui::InputInt("##Port", &add_server_window_port, 1, 1, ImGuiInputTextFlags_CharsDecimal); - imgui_ctx->vibrate_on_hover(); - - ImGui::EndTable(); - } - ImGui::Checkbox(_S("TCP only"), &add_server_tcp_only); - imgui_ctx->vibrate_on_hover(); - - auto top_left = ImGui::GetWindowContentRegionMin(); - auto bottom_right = ImGui::GetWindowContentRegionMax(); - - ImGui::SetCursorPosX(top_left.x); - if (ImGui::Button(_S("Cancel"), button_size)) - { - current_tab = tab::server_list; + auto reset = [&] { add_server_window_prettyname = ""; add_server_window_hostname = ""; add_server_window_port = wivrn::default_port; add_server_tcp_only = false; add_server_cookie = ""; + }; + + const float w = ImGui::GetContentRegionAvail().x; + + ImGui::TextUnformatted(_S("Name")); + if (ImGui::IsWindowAppearing()) + ImGui::SetKeyboardFocusHere(); + ui::input_text("##name", add_server_window_prettyname, _S("My gaming PC"), w); + ImGui::Dummy({0, 6}); + + ImGui::TextUnformatted(_S("Address")); + ui::input_text("##hostname", add_server_window_hostname, _S("192.168.1.10 or host.local"), w); + ImGui::Dummy({0, 6}); + + ImGui::TextUnformatted(_S("Port")); + ui::input_int("##port", &add_server_window_port, 1, 1, 65535, w); + ImGui::Dummy({0, 6}); + + ImGui::TextUnformatted(_S("TCP only")); + ImGui::SameLine(); + ui::toggle("##tcp", &add_server_tcp_only); + + ImGui::Dummy({0, 12}); + + const float gap = ImGui::GetStyle().ItemSpacing.x; + const std::string cancel_l = _("Cancel"); + const std::string save_l = _("Save"); + const float cancel_w = ImGui::CalcTextSize(cancel_l.c_str()).x + ui::metrics::button_padding.x * 2; + const float save_w = ImGui::CalcTextSize(save_l.c_str()).x + ui::metrics::button_padding.x * 2; + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - cancel_w - save_w - gap); + + if (ui::button(cancel_l, ui::button_style::secondary, {cancel_w, 0})) + { + reset(); ImGui::CloseCurrentPopup(); } - imgui_ctx->vibrate_on_hover(); - - ImGui::SameLine(bottom_right.x - button_size.x); - - if (ImGui::Button(_S("Save"), button_size)) + ImGui::SameLine(); + ImGui::BeginDisabled(add_server_window_hostname.empty()); + if (ui::button(save_l, ui::button_style::primary, {save_w, 0})) { - current_tab = tab::server_list; configuration::server_data data{ .manual = true, .service = { - .name = add_server_window_prettyname, + .name = add_server_window_prettyname.empty() ? add_server_window_hostname : add_server_window_prettyname, .hostname = add_server_window_hostname, .port = add_server_window_port, .tcp_only = add_server_tcp_only, @@ -366,149 +345,145 @@ void scenes::lobby::gui_new_server() auto & config = application::get_config(); if (add_server_cookie != "") config.servers.erase(add_server_cookie); - config.servers.emplace("manual-" + data.service.name, data); config.save(); - add_server_window_prettyname = ""; - add_server_window_hostname = ""; - add_server_window_port = wivrn::default_port; - add_server_tcp_only = false; - add_server_cookie = ""; + reset(); ImGui::CloseCurrentPopup(); } - imgui_ctx->vibrate_on_hover(); - - ImGui::PopStyleVar(4); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_ItemSpacing, ImGuiStyleVar_CellPadding, ImGuiStyleVar_FramePadding + ImGui::EndDisabled(); } void scenes::lobby::gui_server_list() { - using constants::style::button_size; - using constants::style::icon_button_size; - + namespace ui = wivrn::ui; auto & config = application::get_config(); - // Build an index of the cookies sorted by server name + const auto & t = ui::current(); + + // header with an Add server button on the right + const ImVec2 hstart = ImGui::GetCursorPos(); + const float header_avail = ImGui::GetContentRegionAvail().x; + ui::page_header(_S("Computers"), _S("Pick a PC running the WiVRn server to stream from.")); + const ImVec2 hend = ImGui::GetCursorPos(); + + const std::string add_label = std::string(ICON_FA_PLUS " ") + _("Add server"); + const float add_w = ImGui::CalcTextSize(add_label.c_str()).x + ui::metrics::button_padding.x * 2; + ImGui::SetCursorPos({hstart.x + header_avail - add_w, hstart.y}); + if (ui::button(add_label, ui::button_style::primary)) + { + add_server_cookie = ""; + add_server_window_prettyname = ""; + add_server_window_hostname = ""; + add_server_window_port = wivrn::default_port; + add_server_tcp_only = false; + ImGui::OpenPopup("add or edit server"); + } + ImGui::SetCursorPos(hend); + std::multimap sorted_cookies; for (auto && [cookie, data]: config.servers) - { sorted_cookies.emplace(data.service.name, cookie); - } - - const float list_item_height = 100; - auto & style = ImGui::GetStyle(); std::string cookie_to_remove; - if (sorted_cookies.empty()) + // deferred: the action menu runs inside the per-row id stack, but the popup is + // opened below in this scope so OpenPopup and begin_modal hash to the same id + bool open_add_edit = false; + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + ui::begin_card("##servers"); { - ImGui::PushFont(nullptr, constants::gui::font_size_large); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.5)); - CenterTextHV(_("Start a WiVRn server on your\nlocal network")); - ImGui::PopStyleColor(); - ImGui::PopFont(); - } - - auto pos = ImGui::GetCursorPos(); - - ImGui::PushStyleColor(ImGuiCol_Header, 0); - ImGui::PushStyleColor(ImGuiCol_HeaderHovered, 0); - ImGui::PushStyleColor(ImGuiCol_HeaderActive, 0); - for (const auto & [name, cookie]: sorted_cookies) - { - configuration::server_data & data = config.servers.at(cookie); - // bool is_selected = (cookie == selected_item); - - ImGui::SetCursorPos(pos); - - // ImGui::SetNextItemAllowOverlap(); - - // TODO custom widget - // if (ImGui::Selectable(("##" + cookie).c_str(), is_selected, ImGuiSelectableFlags_None, ImVec2(0, list_item_height))) - // selected_item = cookie; - - if (data.manual) - ImGui::SetCursorPos(ImVec2(pos.x, pos.y + 25)); // FIXME compute the position correctly - else - ImGui::SetCursorPos(ImVec2(pos.x, pos.y)); - ImGui::Text("%s", name.c_str()); - - if (!data.manual) + if (sorted_cookies.empty()) { - ImGui::SetCursorPos(ImVec2(pos.x, pos.y + 50)); - std::string label = _("Autoconnect") + "##" + cookie; - if (ImGui::Checkbox(label.c_str(), &data.autoconnect)) - config.save(); - imgui_ctx->vibrate_on_hover(); + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); + ImGui::TextUnformatted(_S("Start a WiVRn server on your local network.")); + ImGui::PopStyleColor(); } - ImVec2 button_position(ImGui::GetWindowContentRegionMax().x, pos.y + (list_item_height - button_size.y) / 2); - - button_position.x -= button_size.x + style.WindowPadding.x; - ImGui::SetCursorPos(button_position); - - bool enable_connect_button = (data.visible and data.compatible) or data.manual; - ImGui::BeginDisabled(!enable_connect_button); - if (enable_connect_button) + bool first = true; + for (const auto & [name, cookie]: sorted_cookies) { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.8f, 0.3f, 0.40f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.8f, 0.3f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 1.0f, 0.2f, 1.00f)); - } - else - { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.3f, 0.40f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.4f, 0.3f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 1.00f)); - } + configuration::server_data & data = config.servers.at(cookie); + ImGui::PushID(cookie.c_str()); + if (not first) + ui::row_separator(); + first = false; - if (ImGui::Button((_("Connect") + "##" + cookie).c_str(), button_size)) - { - connect(data); - ImGui::OpenPopup("connecting"); - } - imgui_ctx->vibrate_on_hover(); + const bool available = (data.visible and data.compatible) or data.manual; + const float gap = ImGui::GetStyle().ItemSpacing.x; + const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height; + const std::string sub = fmt::format("{} : {}", data.service.hostname, data.service.port); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) - { - if (!data.compatible && !data.manual) - imgui_ctx->tooltip(_("Incompatible server version")); - else if (!data.visible && !data.manual) - imgui_ctx->tooltip(_("Server not available")); - } + // trailing controls: [Auto chip] [Connect] [menu], measured up front so the + // row body click area can exclude them + const std::string c_label = available ? std::string(ICON_FA_PLAY " ") + _("Connect") : _("Unavailable"); + const float cw = ImGui::CalcTextSize(c_label.c_str()).x + ui::metrics::button_padding.x * 2; + const std::string chip_label = std::string(ICON_FA_BOLT " ") + _("Auto"); + const ImVec2 chip_ts = ImGui::CalcTextSize(chip_label.c_str()); + const float chip_w = chip_ts.x + ui::metrics::chip_padding.x * 2; + float trailing = bh + gap + cw + (data.autoconnect ? gap + chip_w : 0) + ui::metrics::list_row_pad; - ImGui::PopStyleColor(3); - ImGui::EndDisabled(); + const auto row = ui::begin_list_row("##row", ICON_FA_SERVER, 0, name, sub, false, trailing); + const float row_h = row.max.y - row.min.y; + float x = row.max.x; - if (data.manual) - { - button_position.x -= icon_button_size.x + style.WindowPadding.x + 10; - ImGui::SetCursorPos(button_position); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f)); - - if (ImGui::Button((ICON_FA_TRASH_CAN "##remove-" + cookie).c_str(), icon_button_size)) - cookie_to_remove = cookie; - imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleColor(3); - - button_position.x -= icon_button_size.x + style.WindowPadding.x + 10; - ImGui::SetCursorPos(button_position); - if (ImGui::Button((ICON_FA_PENCIL "##edit-" + cookie).c_str(), icon_button_size)) + // overflow menu + const std::string auto_l = _("Autoconnect"); + const std::string edit_l = _("Edit server"); + const std::string del_l = _("Delete server"); + std::vector actions; + actions.push_back({ICON_FA_BOLT, auto_l.c_str(), false, data.autoconnect}); + if (data.manual) { - add_server_cookie = cookie; - add_server_window_prettyname = data.service.name; - add_server_window_hostname = data.service.hostname; - add_server_window_port = data.service.port; - add_server_tcp_only = data.service.tcp_only; - ImGui::OpenPopup("add or edit server"); + actions.push_back({ICON_FA_PEN, edit_l.c_str(), false, false}); + actions.push_back({ICON_FA_TRASH, del_l.c_str(), true, false}); } - imgui_ctx->vibrate_on_hover(); + ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f}); + switch (ui::action_menu("##menu", ICON_FA_ELLIPSIS_VERTICAL, actions)) + { + case 0: + data.autoconnect = not data.autoconnect; + config.save(); + break; + case 1: + add_server_cookie = cookie; + add_server_window_prettyname = data.service.name; + add_server_window_hostname = data.service.hostname; + add_server_window_port = data.service.port; + add_server_tcp_only = data.service.tcp_only; + open_add_edit = true; + break; + case 2: + cookie_to_remove = cookie; + break; + } + x -= bh + gap; + + // connect / unavailable + ImGui::SetCursorScreenPos({x - cw, row.min.y + (row_h - bh) * 0.5f}); + ImGui::BeginDisabled(not available); + if (ui::button(c_label, available ? ui::button_style::primary : ui::button_style::secondary, {cw, 0})) + { + connect(data); + ImGui::OpenPopup("connecting"); + } + ImGui::EndDisabled(); + x -= cw + gap; + + // Auto chip + if (data.autoconnect) + { + const float chip_h = chip_ts.y + ui::metrics::chip_padding.y * 2; + ImGui::SetCursorScreenPos({x - chip_w, row.min.y + (row_h - chip_h) * 0.5f}); + ui::chip(chip_label, ui::chip_style::accent); + } + + ui::end_list_row(); + ImGui::PopID(); } - pos.y += 120; + ui::end_card(); } - ImGui::PopStyleColor(3); + ImGui::PopStyleVar(); if (cookie_to_remove != "") { @@ -516,6 +491,9 @@ void scenes::lobby::gui_server_list() config.save(); } + if (open_add_edit) + ImGui::OpenPopup("add or edit server"); + // Check if we need to report errors after a disconnect if (next_scene and next_scene->current_state() == scenes::stream::state::shutdown and not ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) ImGui::OpenPopup("disconnected"); @@ -547,362 +525,14 @@ void scenes::lobby::gui_server_list() ImGui::EndPopup(); } - ImGui::SetNextWindowSize({800, 0}); - ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f)); - if (ImGui::BeginPopupModal("add or edit server", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) + if (wivrn::ui::begin_modal("add or edit server", add_server_cookie.empty() ? _("Add server") : _("Edit server"), 620)) { gui_new_server(); - ImGui::EndPopup(); + wivrn::ui::end_modal(); } ImGui::PopStyleVar(3); } -void scenes::lobby::gui_settings() -{ - auto & config = application::get_config(); - ImGuiStyle & style = ImGui::GetStyle(); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20)); - - { - auto language_name = [&](const std::locale & loc = std::locale()) { - return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc); - }; - std::vector> languages; - for (const auto & msg_info: get_locales()) - { - std::string code = msg_info.language; - if (not msg_info.country.empty()) - code += "_" + msg_info.country; - std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet(msg_info)); - languages.emplace_back(language_name(loc), loc, std::move(code)); - } - std::ranges::sort(languages, [](auto & l, auto & r) { - return una::casesens::collate_utf8(std::get<0>(l), std::get<0>(r)) < 0; - }); - if (ImGui::BeginCombo(_S("Language"), config.locale.empty() ? _S("System language") : language_name().c_str())) - { - if (ImGui::Selectable(_S("System language"), config.locale.empty(), ImGuiSelectableFlags_SelectOnRelease)) - { - config.locale.clear(); - config.save(); - application::instance().load_locale(); - } - for (const auto & [lang, locale, code]: languages) - { - if (ImGui::Selectable(lang.c_str(), code == config.locale, ImGuiSelectableFlags_SelectOnRelease)) - { - config.locale = code; - config.save(); - application::instance().load_locale(); - } - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); - } - - gui::refresh_rate(instance, session, *imgui_ctx, config); - - // Render resolution - { - const auto current = config.resolution_scale; - const auto width = stream_view.recommendedImageRectWidth; - const auto height = stream_view.recommendedImageRectHeight; - auto intScale = int(current * 10); - const auto slider = ImGui::SliderInt( - _("Render resolution").append("##resolution_scale").c_str(), - &intScale, - 5, - config.extended_config ? 35 : 15, - fmt::format(_F("{}%% - {}x{} per eye"), intScale * 10, int(width * current), int(height * current)).c_str()); - if (slider) - { - config.resolution_scale = intScale * 0.1; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - if (width * config.resolution_scale > stream_view.maxImageRectWidth or height * config.resolution_scale > stream_view.maxImageRectHeight) - { - ImGui::TextColored(constants::style::warn, ICON_FA_TRIANGLE_EXCLAMATION); - ImGui::SameLine(); - ImGui::Text("%s", fmt::format(_F("Resolution larger than {}x{} may not be supported by the headset"), stream_view.maxImageRectWidth, stream_view.maxImageRectHeight).c_str()); - } - if (intScale > 15) - { - ImGui::TextColored(constants::style::warn, ICON_FA_TRIANGLE_EXCLAMATION); - ImGui::SameLine(); - ImGui::Text("%s", fmt::format(_cF("resolution is higher than recommended", "Recommended maximum is {}%"), 150).c_str()); - } - } - - // foveation - { - const int step = 5; - const auto current = config.get_stream_scale(); - int intval = round((1 - current) * 100 / step); - const auto slider = ImGui::SliderInt( - _("Foveated encoding").append("##stream_scale").c_str(), - &intval, - 0, - 100 / step, - fmt::format(_F("{}%%"), intval * step).c_str()); - if (slider) - { - // clamp out of the slider to have the 50% value centered - intval = std::clamp(intval, - config.extended_config ? 0 : 30 / step, - 80 / step); - config.set_stream_scale(1 - intval * step * 0.01); - config.save(); - } - if (ImGui::IsItemHovered()) - { - if (config.check_feature(feature::eye_gaze)) - imgui_ctx->tooltip(_("Higher values focus image quality where you look at,\n" - "improving latency, power efficiency and quality.")); - else - imgui_ctx->tooltip(_("Higher values focus image quality at the center,\n" - "improving latency, power efficiency and quality.")); - } - imgui_ctx->vibrate_on_hover(); - if (intval < 30 / step) - { - ImGui::TextColored(constants::style::warn, ICON_FA_TRIANGLE_EXCLAMATION); - ImGui::SameLine(); - ImGui::Text("%s", fmt::format(_cF("foveation is lower than recommended", "Recommended minimum is {}%"), 30).c_str()); - } - } - - { - auto codec_name = [](const std::optional codec) { - if (not codec) - return _C("Codec", "Automatic"); - switch (*codec) - { - case wivrn::h264: - return _C("Codec", "H.264"); - case wivrn::h265: - return _C("Codec", "H.265"); - case wivrn::av1: - return _C("Codec", "AV1"); - case wivrn::raw: - break; - } - assert(false); - __builtin_unreachable(); - }; - - if (ImGui::BeginCombo(_S("Codec"), codec_name(config.codec).c_str())) - { - if (ImGui::Selectable(codec_name({}).c_str(), not config.codec)) - { - config.codec = std::nullopt; - config.save(); - } - for (auto codec: decoder::supported_codecs()) - { - // don't show raw in GUI - if (codec == wivrn::raw) - continue; - - if (ImGui::Selectable(codec_name(codec).c_str(), config.codec == codec)) - { - config.codec = codec; - config.save(); - } - } - - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); - - if (config.codec == wivrn::video_codec::av1 or config.codec == wivrn::video_codec::h265) - { - ImGui::SameLine(0.f, 10.f); - bool ten_bit = config.bit_depth == 10; - if (ImGui::Checkbox(_S("10-bit"), &ten_bit)) - { - config.bit_depth = ten_bit ? 10 : 8; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - } - } - - // Bitrate - { - const int step = 5; - const int mb = 1'000'000; - const auto current = config.bitrate_bps; - auto val = int(current / mb / step); - const auto slider = ImGui::SliderInt( - _("Bitrate").append("##bitrate").c_str(), - &val, - 1, - config.max_bitrate() / mb / step, - fmt::format(_F("{}Mbit/s"), val * step).c_str()); - if (slider) - { - config.bitrate_bps = val * mb * step; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - if (config.bitrate_bps > config.max_bitrate(false)) - { - ImGui::TextColored(constants::style::warn, ICON_FA_TRIANGLE_EXCLAMATION); - ImGui::SameLine(); - ImGui::Text("%s", fmt::format(_cF("bitrate value is higher than recommended", "Recommended maximum is {}Mbit/s"), config.max_bitrate(false) / mb).c_str()); - } - } - - if (instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME)) - { - if (ImGui::Checkbox(_S("High power mode"), &config.high_power_mode)) - config.save(); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Increase power usage to allow higher resolution and refresh rate")); - imgui_ctx->vibrate_on_hover(); - } - - { - bool enabled = config.check_feature(feature::microphone); - if (ImGui::Checkbox(_S("Enable microphone"), &enabled)) - { - config.set_feature(feature::microphone, enabled); - } - imgui_ctx->vibrate_on_hover(); - } - { - ImGui::BeginDisabled(not config.check_feature(feature::microphone)); - ImGui::Indent(); - if (ImGui::Checkbox(_S("Unprocessed Microphone Audio"), &config.mic_unprocessed_audio)) - { - config.save(); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Force disable audio filters, such as noise cancellation")); - ImGui::Unindent(); - ImGui::EndDisabled(); - } - { - // Virtual devices: a keyboard, mouse or gamepad connected to the headset is - // replicated on the server through uinput. The gamepad is also exposed through - // OpenXR, whether or not it is mirrored to a virtual device. - ImGui::Text("%s", _S("Virtual devices")); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Input devices connected to the headset are replicated as virtual devices on the PC.\nThe server must allow forwarded input devices; this is not available when the server runs as Flatpak.\nA gamepad is also usable without a virtual device by applications that read it through OpenXR.")); - ImGui::Indent(); - if (ImGui::Checkbox(_S("Keyboard"), &config.forward_keyboard)) - config.save(); - imgui_ctx->vibrate_on_hover(); - if (ImGui::Checkbox(_S("Mouse"), &config.forward_mouse)) - config.save(); - imgui_ctx->vibrate_on_hover(); - if (ImGui::Checkbox(_S("Gamepad"), &config.forward_gamepad)) - config.save(); - imgui_ctx->vibrate_on_hover(); - ImGui::Unindent(); - - if (server_hid_forwarding == false and (config.forward_keyboard or config.forward_mouse or config.forward_gamepad)) - { - ImGui::TextColored(constants::style::warn, ICON_FA_TRIANGLE_EXCLAMATION); - ImGui::SameLine(); - ImGui::Text("%s", _S("The server does not allow forwarded input devices")); - } - } - if (system.hand_tracking_supported()) - { - bool enabled = config.check_feature(feature::hand_tracking); - if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) - { - config.set_feature(feature::hand_tracking, enabled); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)) - imgui_ctx->tooltip(_("This feature is not supported by your headset")); - } - if (application::get_eye_gaze_supported()) - { - bool enabled = config.check_feature(feature::eye_gaze); - if (ImGui::Checkbox(_S("Enable eye tracking"), &enabled)) - { - config.set_feature(feature::eye_gaze, enabled); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)) - imgui_ctx->tooltip(_("This feature is not supported by your headset")); - } - if (system.face_tracker_supported() != xr::face_tracker_type::none) - { - bool enabled = config.check_feature(feature::face_tracking); - if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) - { - config.set_feature(feature::face_tracking, enabled); - } - if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)) - imgui_ctx->tooltip(_("This feature is not supported by your headset")); - imgui_ctx->vibrate_on_hover(); - } - - if (auto body_tracker = system.body_tracker_supported(); body_tracker != xr::body_tracker_type::none) - { - bool enabled = config.check_feature(feature::body_tracking); - if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) - { - config.set_feature(feature::body_tracking, enabled); - } - if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) - { - if (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled) - { - imgui_ctx->tooltip(_("This feature is not supported by your headset")); - } - else - { - if (body_tracker == xr::body_tracker_type::fb or body_tracker == xr::body_tracker_type::meta) - imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); - } - } - - imgui_ctx->vibrate_on_hover(); - - { - ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); - ImGui::Indent(); - { - gui::body_tracking_parts(system, *imgui_ctx, config); - } - ImGui::Unindent(); - ImGui::EndDisabled(); - } - } - - { - ImGui::Checkbox(_S("Enable in-stream window"), &config.enable_stream_gui); - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks.")); - } - - { - ImGui::Checkbox(_S("Extended configuration values"), &config.extended_config); - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Allows unsafe configuration values, use at your own risk.")); - } - - ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing -} - -void scenes::lobby::gui_post_processing() -{ - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20)); - gui::post_processing(*imgui_ctx, application::get_config()); - ImGui::PopStyleVar(); -} - #if WIVRN_CLIENT_DEBUG_MENU void scenes::lobby::gui_debug_node_hierarchy(entt::entity root) { @@ -1278,400 +908,6 @@ void scenes::lobby::gui_licenses() ImGui::TextUnformatted((const char *)license->data(), (const char *)license->data() + license->size()); } -static auto face_weights() -{ - using weights = decltype(wivrn::from_headset::tracking::fb_face2{}.weights); - using item = std::pair>; - std::vector res; - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_SMILE, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_TIRED, face); - } - { - weights face{}; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1; - res.emplace_back(ICON_FA_FACE_SURPRISE, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB] = 1; - res.emplace_back(ICON_FA_FACE_SMILE_WINK, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_SMILE_WINK, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_SMILE_BEAM, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB] = 1; - face[XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_SAD_CRY, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB] = 1; - face[XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_ROLLING_EYES, face); - } - - { - weights face{}; - res.emplace_back(ICON_FA_FACE_MEH, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB] = 1; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1; - res.emplace_back(ICON_FA_FACE_LAUGH_WINK, face); - } - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB] = 1; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1; - res.emplace_back(ICON_FA_FACE_LAUGH_WINK, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1; - res.emplace_back(ICON_FA_FACE_LAUGH_SQUINT, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1; - res.emplace_back(ICON_FA_FACE_LAUGH, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_GRIN_WIDE, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB] = 1; - face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1; - res.emplace_back(ICON_FA_FACE_GRIN_TONGUE_WINK, face); - } - { - weights face{}; - face[XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB] = 1; - face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1; - res.emplace_back(ICON_FA_FACE_GRIN_TONGUE_WINK, face); - } - { - weights face{}; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1; - res.emplace_back(ICON_FA_FACE_GRIN_TONGUE_SQUINT, face); - } - { - weights face{}; - face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1; - res.emplace_back(ICON_FA_FACE_GRIN_TONGUE, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 0.5; - res.emplace_back(ICON_FA_FACE_GRIN, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB] = 0.5; - face[XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB] = 0.5; - res.emplace_back(ICON_FA_FACE_GRIMACE, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1; - face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 0.5; - res.emplace_back(ICON_FA_FACE_FROWN_OPEN, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_FROWN, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB] = 1; - face[XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB] = 0.5; - face[XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB] = 0.5; - res.emplace_back(ICON_FA_FACE_FLUSHED, face); - } - - { - weights face{}; - face[XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB] = 1; - face[XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB] = 1; - res.emplace_back(ICON_FA_FACE_ANGRY, face); - } - - return res; -} - -static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker) -{ - static const auto w = face_weights(); - wivrn::from_headset::tracking::fb_face2 expression; - const char * result = nullptr; - std::visit(utils::overloaded{ - [](std::monostate &) {}, - [&](xr::android_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; }, - [&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; }, - [&](auto & ft) { - ft.get_weights(predicted_display_time, expression); - }, - }, - face_tracker); - - if (result) - return result; - - if (not expression.is_valid) - return ICON_FA_FACE_MEH; - - return std::ranges::min_element(w, std::ranges::less(), [&](const auto & p) { - float res = 0; - for (size_t i = 0; i < XR_FACE_EXPRESSION2_COUNT_FB; ++i) - { - float d = expression.weights[i] - p.second[i]; - res += d * d; - } - return res; - }) - ->first; -} - -void scenes::lobby::draw_features_status(XrTime predicted_display_time) -{ - const float win_width = ImGui::GetContentRegionAvail().x; - float text_width = 0; - auto & config = application::get_config(); - - struct item - { - feature f; - std::string tooltip_enabled; - std::string tooltip_disabled; - const char * icon_enabled; - const char * icon_disabled = ICON_FA_SLASH; - bool enabled; - float w; - }; - std::vector items; - - items.push_back({ - .f = feature::microphone, - .tooltip_enabled = _("Microphone is enabled"), - .tooltip_disabled = _("Microphone is disabled"), - .icon_enabled = ICON_FA_MICROPHONE, - .icon_disabled = ICON_FA_MICROPHONE_SLASH, - }); - - if (system.hand_tracking_supported()) - { - items.push_back({ - .f = feature::hand_tracking, - .tooltip_enabled = _("Hand tracking is enabled"), - .tooltip_disabled = _("Hand tracking is disabled"), - .icon_enabled = ICON_FA_HAND, - }); - } - - if (application::get_eye_gaze_supported()) - { - items.push_back({ - .f = feature::eye_gaze, - .tooltip_enabled = _("Eye tracking is enabled"), - .tooltip_disabled = _("Eye tracking is disabled"), - .icon_enabled = ICON_FA_EYE, - .icon_disabled = ICON_FA_EYE_SLASH, - }); - } - - if (not std::holds_alternative(face_tracker)) - { - items.push_back({ - .f = feature::face_tracking, - .tooltip_enabled = _("Face tracking is enabled"), - .tooltip_disabled = _("Face tracking is disabled"), - .icon_enabled = get_face_icon(predicted_display_time, face_tracker), - .icon_disabled = ICON_FA_FACE_MEH_BLANK, - }); - } - else if (system.face_tracker_supported() != xr::face_tracker_type::none and config.check_feature(feature::face_tracking)) - { - face_tracker = xr::make_face_tracker(instance, system, session); - } - - if (system.body_tracker_supported() != xr::body_tracker_type::none) - { - items.push_back({ - .f = feature::body_tracking, - .tooltip_enabled = _("Body tracking is enabled"), - .tooltip_disabled = _("Body tracking is disabled"), - .icon_enabled = ICON_FA_PERSON, - }); - } - - // Get statuses - for (auto & i: items) - { - i.enabled = config.check_feature(i.f); - i.w = ImGui::CalcTextSize(i.enabled ? i.icon_enabled : i.icon_disabled).x; - text_width += i.w; - } - const ImGuiStyle & style = ImGui::GetStyle(); - text_width += items.size() * style.FramePadding.x * 2; - - // New server button - if (ImGui::Button(_S("Add server")) && !ImGui::IsPopupOpen("add or edit server")) - ImGui::OpenPopup("add or edit server"); - imgui_ctx->vibrate_on_hover(); - ImGui::SameLine(); - - // Enabled features - ImGui::SetCursorPosX((win_width - text_width) / 2); - for (auto & i: items) - { - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, i.w / 2); - ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32_BLACK_TRANS); - ImGui::PushStyleColor(ImGuiCol_Text, i.enabled ? ImGui::GetColorU32(ImGuiCol_Text) : IM_COL32(255, 0, 0, 255)); - if (&i != &items.front()) - ImGui::SameLine(); - auto pos = ImGui::GetCursorPos(); - if (ImGui::Button(fmt::format("{}##{}", i.enabled ? i.icon_enabled : i.icon_disabled, i.icon_enabled).c_str())) - { - // button doesn't alter the bool - config.set_feature(i.f, not i.enabled); - } - - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(i.enabled ? i.tooltip_enabled : i.tooltip_disabled); - - if (i.icon_disabled == std::string_view(ICON_FA_SLASH) and not i.enabled) - { - auto save = ImGui::GetCurrentWindow()->DC; - ImGui::SetCursorPos(pos + ImGui::GetStyle().FramePadding); - ImGui::Text("%s", i.icon_enabled); - ImGui::GetCurrentWindow()->DC = save; - } - ImGui::PopStyleColor(2); - ImGui::PopStyleVar(); - } - - float PrevLineSize = ImGui::GetCurrentWindow()->DC.PrevLineSize.y; - float PrevLineTextBaseOffset = ImGui::GetCurrentWindow()->DC.PrevLineTextBaseOffset; - -#ifdef __ANDROID__ - // Battery status - auto status = get_battery_status(); - - const char * battery_icon = nullptr; - if (status.charge) - { - int icon_nr; - - if (status.charging) - { - if (*status.charge > 0.995) - icon_nr = 5; - else - icon_nr = instance.now() / 500'000'000 % 5; - } - else - icon_nr = std::round((*status.charge) * 4); - - switch (icon_nr) - { - case 0: - battery_icon = ICON_FA_BATTERY_EMPTY; - break; - case 1: - battery_icon = ICON_FA_BATTERY_QUARTER; - break; - case 2: - battery_icon = ICON_FA_BATTERY_HALF; - break; - case 3: - battery_icon = ICON_FA_BATTERY_THREE_QUARTERS; - break; - case 4: - battery_icon = ICON_FA_BATTERY_FULL; - break; - case 5: - battery_icon = ICON_FA_PLUG; - } - - ImGui::SameLine(); - - // Always use the longest width for layout - float max_battery_width = ImGui::CalcTextSize(ICON_FA_BATTERY_FULL "100%").x; - ImVec4 battery_color = ImGui::GetStyleColorVec4(ImGuiCol_Text); - - if (*status.charge < 0.2) - battery_color = ImVec4(1, 0, 0, 1); - - ImGui::SetCursorPosX(win_width - max_battery_width - style.WindowPadding.x); - ImGui::TextColored(battery_color, "%s %d%%", battery_icon, (int)std::round(*status.charge * 100)); - } -#endif - - ImGui::Dummy({0, 15}); -} - void scenes::lobby::gui_keyboard() { keyboard.display(*imgui_ctx); @@ -1808,11 +1044,148 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0}); ImGui::SetNextWindowSize({1400, 900}); ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); - ImGui::SetCursorPos({TabWidth + 20, 0}); + + auto & config = application::get_config(); + const float TopBarH = 72; + + // Top bar: logo on the left, status controls on the right + ImGui::SetCursorPos({0, 0}); + ImGui::PushStyleColor(ImGuiCol_ChildBg, wivrn::ui::current().background); + ImGui::BeginChild("TopBar", {ImGui::GetWindowSize().x, TopBarH}, 0, ImGuiWindowFlags_NoScrollbar); + { + const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height; + const float gap = 8; + + // logo + ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * 1.3f); + ImGui::SetCursorPos({24, (TopBarH - ImGui::GetFontSize()) * 0.5f}); + ImGui::PushStyleColor(ImGuiCol_Text, wivrn::ui::current().accent); + ImGui::TextUnformatted(ICON_FA_EYE); + ImGui::PopStyleColor(); + ImGui::SameLine(0, 10); + ImGui::TextUnformatted("WiVRn"); + ImGui::PopFont(); + + // right cluster: feature toggles + battery + connection status + const std::string conn = _("Not connected"); + const ImVec2 cts = ImGui::CalcTextSize(conn.c_str()); + const float dot_r = cts.y * 0.26f; + const float chip_w = cts.x + wivrn::ui::metrics::chip_padding.x * 2.5f + dot_r * 2; + + // feature toggles available on this headset (mic + passthrough are always shown) + const bool has_hand = system.hand_tracking_supported(); + const bool has_eye = application::get_eye_gaze_supported(); + const bool has_face = system.face_tracker_supported() != xr::face_tracker_type::none; + const bool has_body = system.body_tracker_supported() != xr::body_tracker_type::none; + const int n_toggles = 2 + has_hand + has_eye + has_face + has_body; + +#ifdef __ANDROID__ + const auto battery = get_battery_status(); + std::string battery_label; + wivrn::ui::chip_style battery_style = wivrn::ui::chip_style::neutral; + if (battery.charge) + { + const char * battery_icon = ICON_FA_BATTERY_FULL; + int icon_nr; + if (battery.charging) + icon_nr = *battery.charge > 0.995 ? 5 : instance.now() / 500'000'000 % 5; + else + icon_nr = std::round((*battery.charge) * 4); + switch (icon_nr) + { + case 0: + battery_icon = ICON_FA_BATTERY_EMPTY; + break; + case 1: + battery_icon = ICON_FA_BATTERY_QUARTER; + break; + case 2: + battery_icon = ICON_FA_BATTERY_HALF; + break; + case 3: + battery_icon = ICON_FA_BATTERY_THREE_QUARTERS; + break; + case 4: + battery_icon = ICON_FA_BATTERY_FULL; + break; + case 5: + battery_icon = ICON_FA_PLUG; + break; + } + battery_label = fmt::format("{} {}%", battery_icon, (int)std::round(*battery.charge * 100)); + if (*battery.charge < 0.2) + battery_style = wivrn::ui::chip_style::danger; + } + const float battery_w = battery_label.empty() ? 0 : gap + ImGui::CalcTextSize(battery_label.c_str()).x + wivrn::ui::metrics::chip_padding.x * 2; +#else + const float battery_w = 0; +#endif + const float cluster_w = n_toggles * side + n_toggles * gap + battery_w + chip_w; + ImGui::SetCursorPos({ImGui::GetWindowSize().x - 24 - cluster_w, (TopBarH - side) * 0.5f}); + + bool mic = config.check_feature(feature::microphone); + if (wivrn::ui::icon_button(ICON_FA_MICROPHONE, {side, side}, mic, _S("Microphone"))) + config.set_feature(feature::microphone, not mic); + ImGui::SameLine(0, gap); + if (wivrn::ui::icon_button(ICON_FA_EYE_SLASH, {side, side}, config.passthrough_enabled, _S("Passthrough"))) + { + config.passthrough_enabled = not config.passthrough_enabled; + setup_passthrough(); + config.save(); + } + if (has_hand) + { + ImGui::SameLine(0, gap); + bool hand = config.check_feature(feature::hand_tracking); + if (wivrn::ui::icon_button(ICON_FA_HAND, {side, side}, hand, _S("Hand tracking"))) + config.set_feature(feature::hand_tracking, not hand); + } + if (has_eye) + { + ImGui::SameLine(0, gap); + bool eye = config.check_feature(feature::eye_gaze); + if (wivrn::ui::icon_button(ICON_FA_EYE, {side, side}, eye, _S("Eye tracking"))) + config.set_feature(feature::eye_gaze, not eye); + } + if (has_face) + { + ImGui::SameLine(0, gap); + bool face = config.check_feature(feature::face_tracking); + if (wivrn::ui::icon_button(ICON_FA_FACE_SMILE, {side, side}, face, _S("Face tracking"))) + config.set_feature(feature::face_tracking, not face); + } + if (has_body) + { + ImGui::SameLine(0, gap); + bool body = config.check_feature(feature::body_tracking); + if (wivrn::ui::icon_button(ICON_FA_PERSON, {side, side}, body, _S("Body tracking"))) + config.set_feature(feature::body_tracking, not body); + } + +#ifdef __ANDROID__ + // battery status, as a pill like the connection chip + if (not battery_label.empty()) + { + ImGui::SameLine(0, gap); + ImGui::SetCursorPosY((TopBarH - side) * 0.5f); + wivrn::ui::chip(battery_label, battery_style, false, side); + } +#endif + + ImGui::SameLine(0, gap); + ImGui::SetCursorPosY((TopBarH - side) * 0.5f); + wivrn::ui::chip(conn.c_str(), wivrn::ui::chip_style::muted, true, side); + } + ImGui::EndChild(); + ImGui::PopStyleColor(); + + // content area, with an equal margin on both sides of the panel + const float content_margin = 20; + ImGui::SetCursorPos({TabWidth + content_margin, TopBarH}); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 20}); - ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0), 0); + ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX() - content_margin, 0), 0); ImGui::SetCursorPosY(20); switch (current_tab) @@ -1822,15 +1195,31 @@ std::vector> scenes::lobby::draw_gui(XrTi __builtin_unreachable(); case tab::server_list: - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); - draw_features_status(predicted_display_time); - ImGui::PopStyleVar(); - gui_server_list(); break; - case tab::settings: - gui_settings(); + case tab::performance: + gui_performance(); + break; + + case tab::streaming: + gui_streaming(); + break; + + case tab::audio: + gui_audio(); + break; + + case tab::devices: + gui_devices(); + break; + + case tab::tracking: + gui_tracking(); + break; + + case tab::system: + gui_system(); break; case tab::post_processing: @@ -1841,11 +1230,11 @@ std::vector> scenes::lobby::draw_gui(XrTi gui_customize(predicted_display_time); break; +#if WIVRN_CLIENT_DEBUG_MENU case tab::components: gui_components(); break; -#if WIVRN_CLIENT_DEBUG_MENU case tab::debug: gui_debug(); break; @@ -1876,44 +1265,56 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::EndChild(); ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding - ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 255)); - ImGui::SetCursorPos(style.WindowPadding); + ImGui::PushStyleColor(ImGuiCol_ChildBg, wivrn::ui::current().card); + ImGui::SetCursorPos({0, TopBarH}); { - ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y}); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16}); + ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetWindowSize().y - TopBarH}, ImGuiChildFlags_AlwaysUseWindowPadding); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10)); - RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), current_tab, tab::server_list, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 4}); - RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), current_tab, tab::settings, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + if (wivrn::ui::nav_item(ICON_FA_COMPUTER, _S("Computers"), current_tab == tab::server_list)) + current_tab = tab::server_list; - RadioButtonWithoutCheckBox(ICON_FA_WAND_MAGIC_SPARKLES " " + _("Post-processing"), current_tab, tab::post_processing, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); - - RadioButtonWithoutCheckBox(ICON_FA_PANORAMA " " + _("Customize"), current_tab, tab::customize, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); - - RadioButtonWithoutCheckBox(ICON_FA_PALETTE " Components", current_tab, tab::components, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + wivrn::ui::nav_section(_S("SETTINGS")); + if (wivrn::ui::nav_item(ICON_FA_GAUGE_HIGH, _S("Performance"), current_tab == tab::performance)) + current_tab = tab::performance; + if (wivrn::ui::nav_item(ICON_FA_TOWER_BROADCAST, _S("Streaming"), current_tab == tab::streaming)) + current_tab = tab::streaming; + if (wivrn::ui::nav_item(ICON_FA_WAND_MAGIC_SPARKLES, _S("Post-processing"), current_tab == tab::post_processing)) + current_tab = tab::post_processing; + if (wivrn::ui::nav_item(ICON_FA_VOLUME_HIGH, _S("Audio"), current_tab == tab::audio)) + current_tab = tab::audio; + if (wivrn::ui::nav_item(ICON_FA_KEYBOARD, _S("Devices"), current_tab == tab::devices)) + current_tab = tab::devices; + if (wivrn::ui::nav_item(ICON_FA_LOCATION_CROSSHAIRS, _S("Tracking"), current_tab == tab::tracking)) + current_tab = tab::tracking; + if (wivrn::ui::nav_item(ICON_FA_GEARS, _S("System"), current_tab == tab::system)) + current_tab = tab::system; + wivrn::ui::nav_section(_S("PERSONALIZE")); + if (wivrn::ui::nav_item(ICON_FA_IMAGE, _S("Customize"), current_tab == tab::customize)) + current_tab = tab::customize; #if WIVRN_CLIENT_DEBUG_MENU - RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), current_tab, tab::debug, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + if (wivrn::ui::nav_item(ICON_FA_PALETTE, "Components", current_tab == tab::components)) + current_tab = tab::components; + if (wivrn::ui::nav_item(ICON_FA_BUG_SLASH, _S("Debug"), current_tab == tab::debug)) + current_tab = tab::debug; #endif - ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * ImGui::GetCurrentContext()->FontSize - 6 * style.FramePadding.y - 2 * style.ItemSpacing.y - style.WindowPadding.y); - RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), current_tab, tab::about, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + // pinned to the bottom + const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y; + ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * item_h - ImGui::GetStyle().WindowPadding.y); + if (wivrn::ui::nav_item(ICON_FA_CIRCLE_INFO, _S("About"), current_tab == tab::about)) + current_tab = tab::about; + if (wivrn::ui::nav_item(ICON_FA_SCALE_BALANCED, _S("Licenses"), current_tab == tab::licenses)) + current_tab = tab::licenses; + if (wivrn::ui::nav_item(ICON_FA_DOOR_OPEN, _S("Exit"), current_tab == tab::exit)) + current_tab = tab::exit; - RadioButtonWithoutCheckBox(ICON_FA_SCALE_BALANCED " " + _("Licenses"), current_tab, tab::licenses, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); - - RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), current_tab, tab::exit, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); - - ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing ImGui::EndChild(); + ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding (Tabs) } ImGui::PopStyleColor(); // ImGuiCol_ChildBg ImGui::End(); diff --git a/client/scenes/lobby_gui_components.cpp b/client/scenes/lobby_gui_components.cpp index 809f5368..ddb7e2fb 100644 --- a/client/scenes/lobby_gui_components.cpp +++ b/client/scenes/lobby_gui_components.cpp @@ -21,6 +21,8 @@ #include "lobby.h" +#if WIVRN_CLIENT_DEBUG_MENU + #include "render/ui_theme.h" #include "render/ui_widgets.h" @@ -357,3 +359,5 @@ void scenes::lobby::gui_components() ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing } + +#endif // WIVRN_CLIENT_DEBUG_MENU diff --git a/client/scenes/lobby_gui_customize.cpp b/client/scenes/lobby_gui_customize.cpp index 5d59d2f5..a42935c8 100644 --- a/client/scenes/lobby_gui_customize.cpp +++ b/client/scenes/lobby_gui_customize.cpp @@ -28,6 +28,8 @@ #include "imspinner.h" #include "render/image_writer.h" #include "render/scene_renderer.h" +#include "render/ui_theme.h" +#include "render/ui_widgets.h" #include "utils/files.h" #include "utils/i18n.h" #include "utils/json_string.h" @@ -337,278 +339,141 @@ void scenes::lobby::download_environment_list() scenes::lobby::environment_item_action scenes::lobby::environment_item(environment_model & model, bool download_screenshot) { + namespace ui = wivrn::ui; environment_item_action action = environment_item_action::none; - ImGuiWindow * window = ImGui::GetCurrentWindow(); - const ImGuiStyle & style = ImGui::GetStyle(); - bool local = std::ranges::contains(local_environments, model.name, &environment_model::name); + const bool local = std::ranges::contains(local_environments, model.name, &environment_model::name); - static std::unordered_map expanded_height; - - float width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x - 2 * ImGui::GetCurrentWindow()->WindowPadding.x; - ImVec2 screenshot_size{256, 256}; - ImVec2 default_selectable_size{ - width, - screenshot_size.y + 2 * style.FramePadding.y // Screenshot size including padding - // + style.ItemSpacing.y // Spacing - // + ImGui::GetFontSize() + 2 * style.FramePadding.y // Progress bar height - }; - ImVec2 selectable_size = default_selectable_size; - - bool expanded = false; - if (auto iter = expanded_height.find(model.gltf_url); iter != expanded_height.end()) + // lazily load the screenshot texture + if (model.screenshot == 0) { - selectable_size.y = std::max(selectable_size.y, iter->second); - expanded = true; - } - - ImTextureID screenshot = model.screenshot; - if (ImRect{window->DC.CursorPos, window->DC.CursorPos + selectable_size}.Overlaps(window->ClipRect)) - { - if (screenshot == 0) + if (download_screenshot) { - if (download_screenshot) + if (model.screenshot_url != "" and not try_get_download_handle(model.screenshot_url)) { - if (model.screenshot_url != "" and not try_get_download_handle(model.screenshot_url)) - { - spdlog::info("Downloading {}", model.screenshot_url); - - download(model.screenshot_url, - [this, url = model.screenshot_url](libcurl::curl_handle & handle) { - try - { - auto png = handle.get_response_bytes(); - auto screenshot = imgui_ctx->load_texture(png); - - for (auto & model: downloadable_environments) - { - if (model.screenshot_url == url) - { - model.screenshot = screenshot; - model.screenshot_png = std::vector{png.begin(), png.end()}; - } - } - } - catch (std::exception & e) - { - spdlog::warn("Cannot load image from {}: {}", handle.get_url(), e.what()); - for (auto & model: downloadable_environments) - { - if (model.screenshot_url == url) - { - model.screenshot_url = ""; - model.screenshot = default_environment_screenshot; - } - } - } - }); - } + spdlog::info("Downloading {}", model.screenshot_url); + download(model.screenshot_url, [this, url = model.screenshot_url](libcurl::curl_handle & handle) { + try + { + auto png = handle.get_response_bytes(); + auto tex = imgui_ctx->load_texture(png); + for (auto & m: downloadable_environments) + if (m.screenshot_url == url) + { + m.screenshot = tex; + m.screenshot_png = std::vector{png.begin(), png.end()}; + } + } + catch (std::exception & e) + { + spdlog::warn("Cannot load image from {}: {}", handle.get_url(), e.what()); + for (auto & m: downloadable_environments) + if (m.screenshot_url == url) + { + m.screenshot_url = ""; + m.screenshot = default_environment_screenshot; + } + } + }); } - else if (model.local_screenshot_path != "" and std::filesystem::exists(model.local_screenshot_path)) + } + else if (model.local_screenshot_path != "" and std::filesystem::exists(model.local_screenshot_path)) + { + try { - try - { - spdlog::info("Loading {}", model.local_screenshot_path.native()); - screenshot = model.screenshot = imgui_ctx->load_texture(utils::mapped_file{model.local_screenshot_path}); - } - catch (std::exception & e) - { - spdlog::warn("Cannot load screenshot {}: {}", model.local_screenshot_path.native(), e.what()); - std::error_code ec; - std::filesystem::remove(model.local_screenshot_path, ec); // Ignore errors - model.local_screenshot_path = ""; // Avoid subsequent loading errors - model.screenshot = default_environment_screenshot; - } + model.screenshot = imgui_ctx->load_texture(utils::mapped_file{model.local_screenshot_path}); + } + catch (std::exception & e) + { + spdlog::warn("Cannot load screenshot {}: {}", model.local_screenshot_path.native(), e.what()); + std::error_code ec; + std::filesystem::remove(model.local_screenshot_path, ec); + model.local_screenshot_path = ""; + model.screenshot = default_environment_screenshot; } } } - auto backup_cursor = ImGui::GetCursorScreenPos(); const auto & config = application::get_config(); - bool selected = (config.passthrough_enabled and model.local_gltf_path == "") or - (not config.passthrough_enabled and config.environment_model == model.local_gltf_path); + const bool selected = (config.passthrough_enabled and model.local_gltf_path == "") or + (not config.passthrough_enabled and config.environment_model == model.local_gltf_path); - ImGui::SetNextItemAllowOverlap(); - // Use ImGuiSelectableFlags_AllowDoubleClick to have ImGuiButtonFlags_PressedOnClickRelease in ImGui::Selectable - if (ImGui::Selectable(("##" + model.gltf_url).c_str(), &selected, ImGuiSelectableFlags_AllowDoubleClick, selectable_size)) - { - if (local) - action = environment_item_action::use_model; - else - action = environment_item_action::download_model; - } - imgui_ctx->vibrate_on_hover(); - auto end_cursor = ImGui::GetCursorScreenPos(); - - // Remove the height of the progress bar if a transfer is in progress - float text_clip_height = selectable_size.y + style.FramePadding.y; - if (auto handle = try_get_download_handle(model.gltf_url); handle and handle->get_state() == libcurl::state::transferring) - text_clip_height -= ImGui::GetFontSize() + 2 * style.FramePadding.y + style.ItemSpacing.y; - - // Display the screenshot - ImGui::SetCursorScreenPos(backup_cursor + ImVec2(style.FramePadding.x, 0)); - ImGui::Image(screenshot ? screenshot : default_environment_screenshot, screenshot_size); - - ImGui::PushClipRect(backup_cursor, backup_cursor + ImVec2(selectable_size.x, text_clip_height), true); - float indent = screenshot_size.x + style.FramePadding.x + 2 * style.ImageBorderSize + style.ItemSpacing.x; - - // Display the text - std::pair text_name; - std::pair text_author; - std::pair text_description; - std::pair text_filesize; - - text_name.first = model.builtin ? _(model.name.c_str()) : model.name; + // subtitle: author / description / size, one per line + std::string subtitle; + auto add_line = [&](const std::string & s) { + if (s.empty()) + return; + if (not subtitle.empty()) + subtitle += "\n"; + subtitle += s; + }; if (model.author != "") - text_author.first = fmt::format(_F("Author: {}"), model.author); + add_line(fmt::format(_F("Author: {}"), model.author)); if (model.description != "") - text_description.first = model.description; + add_line(model.builtin ? std::string(_(model.description.c_str())) : model.description); if (not model.builtin) - text_filesize.first = fmt::format(_F("Size: {:.1f} MB"), model.size * 1.0e-6); + add_line(fmt::format(_F("Size: {:.1f} MB"), model.size * 1.0e-6)); - const float wrap_width = selectable_size.x - indent - style.FramePadding.x; + const char * icon = model.local_gltf_path == "" ? ICON_FA_VIDEO : (model.builtin ? ICON_FA_TABLE_CELLS : ICON_FA_IMAGE); + const std::string title = model.builtin ? std::string(_(model.name.c_str())) : model.name; - // clang-format off - text_name.second = ImGui::CalcTextSize(text_name.first.data(), text_name.first.data() + text_name.first.size(), false, wrap_width); - text_author.second = ImGui::CalcTextSize(text_author.first.data(), text_author.first.data() + text_author.first.size(), false, wrap_width); - text_description.second = ImGui::CalcTextSize(text_description.first.data(), text_description.first.data() + text_description.first.size(), false, wrap_width); - text_filesize.second = ImGui::CalcTextSize(text_filesize.first.data(), text_filesize.first.data() + text_filesize.first.size(), false, wrap_width); - // clang-format on + ImGui::PushID(model.gltf_url.c_str()); + const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height; + auto handle = try_get_download_handle(model.gltf_url); + const bool transferring = handle and handle->get_state() == libcurl::state::transferring; - ImGui::SetCursorScreenPos(backup_cursor); + // measure the trailing control so the row body click area can exclude it + const std::string active_l = std::string(ICON_FA_CHECK " ") + _("Active"); + const ImVec2 active_ts = ImGui::CalcTextSize(active_l.c_str()); + const float active_w = active_ts.x + ui::metrics::chip_padding.x * 2; + float trailing = 0; + if (selected) + trailing = active_w + ui::metrics::list_row_pad; + else if (transferring or (local and not model.builtin)) + trailing = bh + ui::metrics::list_row_pad; - ImVec2 text_pos = backup_cursor + ImVec2(indent, 0); - float text_height = 0; + const auto row = ui::begin_list_row("##env", icon, model.screenshot, title, subtitle, selected, trailing); + const float row_h = row.max.y - row.min.y; + if (row.clicked and not selected) + action = local ? environment_item_action::use_model : environment_item_action::download_model; - ImGui::RenderTextWrapped(text_pos, text_name.first.data(), text_name.first.data() + text_name.first.size(), wrap_width); - text_height += text_name.second.y + style.ItemSpacing.y; + const float x = row.max.x; - if (text_author.first != "") + if (selected) { - ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_author.first.data(), text_author.first.data() + text_author.first.size(), wrap_width); - text_height += text_author.second.y + style.ItemSpacing.y; + const float ch = active_ts.y + ui::metrics::chip_padding.y * 2; + ImGui::SetCursorScreenPos({x - active_w, row.min.y + (row_h - ch) * 0.5f}); + ui::chip(active_l, ui::chip_style::success); } - - if (text_description.first != "") + else if (transferring) { - ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_description.first.data(), text_description.first.data() + text_description.first.size(), wrap_width); - text_height += text_description.second.y + style.ItemSpacing.y; + ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f}); + if (ui::icon_button(ICON_FA_STOP, {bh, bh}, false, _S("Cancel"))) + handle->cancel(); } - - if (text_filesize.first != "") + else if (local and not model.builtin) { - ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_filesize.first.data(), text_filesize.first.data() + text_filesize.first.size(), wrap_width); - text_height += text_filesize.second.y + style.ItemSpacing.y; - } - - ImGui::PopClipRect(); - - // Display the expand/collapse button - if (text_height > default_selectable_size.y - 2 * style.FramePadding.y) - { - const char * button_text = expanded ? ICON_FA_CHEVRON_UP : ICON_FA_CHEVRON_DOWN; - auto expand_size = ImGui::CalcTextSize(button_text) + style.FramePadding * 2.0f; - float radius = std::max(expand_size.x, expand_size.y) / 2; - - ImGui::SetCursorScreenPos(ImVec2( - backup_cursor.x + selectable_size.x / 2 - radius, - backup_cursor.y + selectable_size.y + style.FramePadding.y - radius)); - - // Triple hash so that the button text is not used to compute the button ID and - // avoid vibrating the controller when the text changes - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, radius); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - if (ImGui::Button((button_text + ("###expand-" + model.gltf_url)).c_str(), ImVec2(radius * 2, radius * 2))) - { - if (expanded) - expanded_height.erase(model.gltf_url); - else - expanded_height[model.gltf_url] = text_height + 2 * style.FramePadding.y; - } - imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleColor(); - ImGui::PopStyleVar(); // ImGuiStyleVar_FrameRounding - } - - // Display the delete button - if (local and not model.builtin) - { - auto delete_size = ImGui::CalcTextSize(ICON_FA_TRASH) + style.FramePadding * 2; - ImGui::SetCursorScreenPos(ImVec2( - backup_cursor.x + width - style.FramePadding.x - delete_size.x, - backup_cursor.y)); - - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f)); - if (ImGui::Button((ICON_FA_TRASH "##delete-" + model.name).c_str())) + ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f}); + if (ui::icon_button(ICON_FA_TRASH, {bh, bh}, false, _S("Delete this model"))) action = environment_item_action::delete_model; - if (ImGui::IsItemHovered()) - imgui_ctx->tooltip(_("Delete this model")); - imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleColor(3); } - // Display the download progress - else if (auto handle = try_get_download_handle(model.gltf_url)) + + // surface download errors the way the original did + if (handle) { - switch (handle->get_state()) + if (handle->get_state() == libcurl::state::error) { - case libcurl::state::transferring: { - ImVec2 cancel_size = ImGui::CalcTextSize(ICON_FA_STOP) + style.FramePadding * 2; - - ImGui::SetCursorScreenPos(ImVec2( - backup_cursor.x + screenshot_size.x + style.FramePadding.x + style.ItemSpacing.x, - backup_cursor.y + selectable_size.y - (ImGui::GetFontSize() + 2 * style.FramePadding.y))); - - float progress_width = width - cancel_size.x - screenshot_size.x - 2 * style.FramePadding.x - 2 * style.ItemSpacing.x; - - if (handle->get_content_length() > 0) - ImGui::ProgressBar(handle->get_progress() / (float)handle->get_content_length(), {progress_width, 0}); - else - ImGui::ProgressBar(-ImGui::GetTime(), {progress_width, 0}); // Indeterminate progress bar - - ImGui::SameLine(); - if (ImGui::Button((ICON_FA_STOP "##" + model.name).c_str())) - handle->cancel(); - - imgui_ctx->vibrate_on_hover(); - break; - } - - case libcurl::state::error: - if (handle->get_curl_code() == CURLE_HTTP_RETURNED_ERROR) - { - spdlog::error("HTTP error {} when downloading {}", handle->get_response_code(), handle->get_url()); - load_environment_status = fmt::format( - _F("HTTP error {} when downloading {}"), - handle->get_response_code(), - handle->get_url()); - } - else - { - spdlog::error("Curl error when downloading {}: {}", handle->get_url(), curl_easy_strerror(handle->get_curl_code())); - load_environment_status = fmt::format( - _F("Curl error when downloading {}\n{}: {}"), - handle->get_url(), - magic_enum::enum_name(handle->get_curl_code()), - curl_easy_strerror(handle->get_curl_code())); - } - - handle->reset(); - break; - - case libcurl::state::cancelled: - handle->reset(); - break; - - case libcurl::state::cancelling: - case libcurl::state::reset: - case libcurl::state::done: - break; + if (handle->get_curl_code() == CURLE_HTTP_RETURNED_ERROR) + load_environment_status = fmt::format(_F("HTTP error {} when downloading {}"), handle->get_response_code(), handle->get_url()); + else + load_environment_status = fmt::format(_F("Curl error when downloading {}\n{}: {}"), handle->get_url(), magic_enum::enum_name(handle->get_curl_code()), curl_easy_strerror(handle->get_curl_code())); + handle->reset(); } + else if (handle->get_state() == libcurl::state::cancelled) + handle->reset(); } - ImGui::SetCursorScreenPos(end_cursor); - ImGui::Dummy({}); + ui::end_list_row(); + ImGui::PopID(); return action; } @@ -640,46 +505,20 @@ void scenes::lobby::environment_list(std::vector & models, bo ImGui::EndDisabled(); } - const auto & popup_layer = imgui_ctx->layers()[1]; - const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2; - ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size); - if (ImGui::BeginPopupModal("confirm delete model", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) + if (environment_to_be_deleted) { - ImGui::Text("%s", fmt::format(_F("Really delete {}?"), environment_to_be_deleted->name).c_str()); - - const auto & style = ImGui::GetStyle(); - auto cancel_text = _("Cancel"); - auto delete_text = _("Delete"); - auto cancel_size = ImGui::CalcTextSize(cancel_text.c_str()) + style.FramePadding * 2.0f; - auto delete_size = ImGui::CalcTextSize(delete_text.c_str()) + style.FramePadding * 2.0f; - - ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - cancel_size.x - style.ItemSpacing.x - delete_size.x); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f)); - if (ImGui::Button(delete_text.c_str())) + const std::string msg = fmt::format(_F("Permanently delete {}?"), environment_to_be_deleted->name); + switch (wivrn::ui::confirm_modal("confirm delete model", _("Delete environment"), msg, _("Delete"), _("Cancel"), true)) { - delete_environment(*environment_to_be_deleted); - environment_to_be_deleted = nullptr; - ImGui::CloseCurrentPopup(); + case 1: + delete_environment(*environment_to_be_deleted); + environment_to_be_deleted = nullptr; + break; + case -1: + environment_to_be_deleted = nullptr; + break; } - imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleColor(3); - - ImGui::SameLine(); - if (ImGui::Button(cancel_text.c_str())) - { - environment_to_be_deleted = nullptr; - ImGui::CloseCurrentPopup(); - } - imgui_ctx->vibrate_on_hover(); - - ImGui::EndPopup(); } - ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize } void scenes::lobby::popup_load_environment(XrTime predicted_display_time) @@ -810,27 +649,36 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time) { auto & config = application::get_config(); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20}); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); + namespace ui = wivrn::ui; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0}); - ImGui::BeginChild("environment list", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, ImGui::GetFontSize() + 80)); + ui::page_header(_S("Customize"), _S("Choose the environment your panels float in.")); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + + ui::begin_card("##environments"); environment_list(local_environments, false); - ScrollWhenDragging(); - ImGui::EndChild(); - ImGui::PopStyleVar(); + ui::end_card(); - if (ImGui::Button(_S("Download more environments"))) + // Get more environments + ui::begin_card("##get_more"); { - download_environment_list(); - ImGui::OpenPopup("download environment model"); + const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height; + const std::string browse = std::string(ICON_FA_UP_RIGHT_FROM_SQUARE " ") + _("Browse"); + const float bw = ImGui::CalcTextSize(browse.c_str()).x + ui::metrics::button_padding.x * 2; + const auto row = ui::begin_list_row("##getmore", ICON_FA_IMAGES, 0, _S("Get more environments"), _S("Download community-made spaces from the WiVRn dashboard on your PC."), false, bw + ui::metrics::list_row_pad); + const float row_h = row.max.y - row.min.y; + ImGui::SetCursorScreenPos({row.max.x - bw, row.min.y + (row_h - bh) * 0.5f}); + if (ui::button(browse, ui::button_style::secondary, {bw, 0})) + { + download_environment_list(); + ImGui::OpenPopup("download environment model"); + } + ui::end_list_row(); + ui::end_card(); } - imgui_ctx->vibrate_on_hover(); - ImGui::SameLine(); - if (ImGui::Button(_S("Open local glTF model"))) + if (ui::button(_S("Open local glTF model"), ui::button_style::secondary)) lobby_file_picker_future = lobby_file_picker.open(); - imgui_ctx->vibrate_on_hover(); const auto & popup_layer = imgui_ctx->layers()[1]; const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2; @@ -952,5 +800,5 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time) // ImGui::SliderFloat("Environment elevation", &lobby_node.position.y, -3, 3, "%.3f"); // imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleVar(2); // ImGuiStyleVar_ItemSpacing, ImGuiStyleVar_FramePadding + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing } diff --git a/client/scenes/lobby_gui_settings.cpp b/client/scenes/lobby_gui_settings.cpp new file mode 100644 index 00000000..d816bb2e --- /dev/null +++ b/client/scenes/lobby_gui_settings.cpp @@ -0,0 +1,582 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// The settings screens are drawn procedurally: each page builds a list of `setting` +// descriptors that reference the existing configuration members, and render_settings() +// renders the matching ui:: widget for each. Gating is done by conditionally adding a +// descriptor; the disabled-but-shown case uses the `enabled` predicate. Descriptors are +// rebuilt every frame, so dynamic options and descriptions just work. + +#define IMGUI_DEFINE_MATH_OPERATORS + +#include "lobby.h" + +#include "application.h" +#include "configuration.h" +#include "decoder/decoder.h" +#include "render/ui_theme.h" +#include "render/ui_widgets.h" +#include "scenes/gui_common.h" +#include "utils/i18n.h" +#include "xr/instance.h" +#include "xr/session.h" +#include "xr/system.h" + +#include "imgui.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ui = wivrn::ui; + +namespace +{ +constexpr float control_w = 480; + +enum class ui_kind +{ + toggle, + slider, + segmented, + combo, +}; + +// One declarative setting. Numeric controls (slider/segmented/combo) use get_int/set_int; +// segmented/combo indices map through `options`. Strings are owned so localized text stays +// valid. `enabled` greys the row out without hiding it. +struct setting +{ + const char * id; // stable imgui id + std::string label; + std::string description; + ui_kind ui = ui_kind::toggle; + + std::function get_bool; + std::function set_bool; + + std::function get_int; + std::function set_int; + int v_min = 0; + int v_max = 0; + std::string fmt; + std::function()> options; + std::string title; // combo modal title + + std::optional default_bool; // reset target for toggles + std::optional default_int; // reset target for slider/segmented/combo + + std::function enabled; +}; + +void render_settings(const char * card_id, const std::vector & list) +{ + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + ui::begin_card(card_id); + + for (const auto & s: list) + { + const bool enabled = s.enabled ? s.enabled() : true; + ImGui::BeginDisabled(not enabled); + + // stable storage for the reset defaults during this call + bool def_b = s.default_bool.value_or(false); + int def_i = s.default_int.value_or(0); + const bool * dpb = s.default_bool ? &def_b : nullptr; + const int * dpi = s.default_int ? &def_i : nullptr; + + const float w = s.ui == ui_kind::toggle ? wivrn::gui::toggle_width() + (s.default_bool ? ui::reset_slot_width() : 0) : control_w; + const float label_bottom = ui::setting_label(s.label, s.description, w); + + switch (s.ui) + { + case ui_kind::toggle: { + bool v = s.get_bool(); + if (ui::toggle(s.id, &v, dpb)) + s.set_bool(v); + break; + } + case ui_kind::slider: { + int v = s.get_int(); + if (ui::slider_int(s.id, &v, s.v_min, s.v_max, s.fmt.c_str(), {control_w, 0}, dpi)) + s.set_int(v); + break; + } + case ui_kind::segmented: { + const auto opts = s.options(); + int v = s.get_int(); + if (ui::segmented(s.id, opts, &v, {control_w, 0}, dpi)) + s.set_int(v); + break; + } + case ui_kind::combo: { + const auto opts = s.options(); + std::vector items; + for (const auto & o: opts) + items.push_back({o.c_str()}); + int v = s.get_int(); + if (ui::combo(s.id, s.title, items, &v, control_w, dpi)) + s.set_int(v); + break; + } + } + + ImGui::EndDisabled(); + + // keep the row tall enough for a multi-line description and add breathing room + // below. Reserve with Dummy (SetCursorPos would not grow the content size). + const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad; + ImGui::Dummy({0, pad}); + } + + ui::end_card(); + ImGui::PopStyleVar(); +} +} // namespace + +void scenes::lobby::gui_performance() +{ + auto & config = application::get_config(); + std::vector list; + + if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME) and not session.get_refresh_rates().empty()) + { + const auto rates = session.get_refresh_rates(); + list.push_back({ + .id = "##refresh", + .label = _("Refresh rate"), + .description = _("Select refresh rate based on measured application performance.\nMay cause flicker when a change happens."), + .ui = ui_kind::segmented, + .get_int = [&config, rates] { + for (size_t i = 0; i < rates.size(); ++i) + if (rates[i] == config.preferred_refresh_rate) + return int(i) + 1; + return 0; }, + .set_int = [this, &config, rates](int v) { + if (v == 0) + { + config.preferred_refresh_rate = 0; + config.fps_divider = 1; + } + else + { + session.set_refresh_rate(rates[v - 1]); + config.preferred_refresh_rate = rates[v - 1]; + } + config.save(); }, + .options = [rates] { + std::vector opts; + opts.push_back(_C("automatic refresh rate", "Auto")); + for (float r: rates) + opts.push_back(fmt::format("{}", int(r))); + return opts; }, + .default_int = 0, + }); + } + + { + const auto width = stream_view.recommendedImageRectWidth; + const auto height = stream_view.recommendedImageRectHeight; + list.push_back({ + .id = "##resolution", + .label = _("Render resolution"), + .description = fmt::format(_cF("render resolution", "Pixels rendered per eye ({}x{}). Lower to gain performance."), int(width * config.resolution_scale), int(height * config.resolution_scale)), + .ui = ui_kind::slider, + .get_int = [&config] { return int(std::lround(config.resolution_scale * 100)); }, + .set_int = [&config](int v) { config.resolution_scale = v / 100.0; config.save(); }, + .v_min = 50, + .v_max = config.extended_config ? 350 : 150, + .fmt = "%d%%", + .default_int = 100, + }); + } + + list.push_back({ + .id = "##foveation", + .label = _("Foveated encoding"), + .description = config.check_feature(feature::eye_gaze) + ? _("Higher values focus image quality where you look at, improving latency, power efficiency and quality.") + : _("Higher values focus image quality at the center, improving latency, power efficiency and quality."), + .ui = ui_kind::slider, + .get_int = [&config] { return int(std::lround((1 - config.get_stream_scale()) * 100)); }, + .set_int = [&config](int v) { + if (not config.extended_config) + v = std::clamp(v, 30, 80); + config.set_stream_scale(1 - v * 0.01); + config.save(); }, + .v_min = 0, + .v_max = 80, + .fmt = "%d%%", + .default_int = int(std::lround((1 - (config.check_feature(feature::eye_gaze) ? 0.3 : 0.5)) * 100)), + }); + + if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)) + { + list.push_back({ + .id = "##spacewarp", + .label = _("Application SpaceWarp"), + .description = _("Renders at half the refresh rate and synthesises in-between frames. Managed automatically while the refresh rate is set to Auto."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.fps_divider == 2; }, + .set_bool = [&config](bool v) { config.fps_divider = v ? 2 : 1; config.save(); }, + .default_bool = false, + .enabled = [&config] { return config.preferred_refresh_rate != 0; }, + }); + } + + if (instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME)) + { + list.push_back({ + .id = "##high_power", + .label = _("High power mode"), + .description = _("Increase power usage to allow higher resolution and refresh rate. Drains battery and runs hot."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.high_power_mode; }, + .set_bool = [&config](bool v) { config.high_power_mode = v; config.save(); }, + .default_bool = true, + }); + } + + ui::page_header(_S("Performance"), _S("Frame rate, resolution and power draw.")); + render_settings("##performance", list); +} + +void scenes::lobby::gui_streaming() +{ + auto & config = application::get_config(); + std::vector list; + + auto codec_name = [](std::optional codec) -> std::string { + if (not codec) + return _C("Codec", "Automatic"); + switch (*codec) + { + case wivrn::h264: + return _C("Codec", "H.264"); + case wivrn::h265: + return _C("Codec", "HEVC (H.265)"); + case wivrn::av1: + return _C("Codec", "AV1"); + case wivrn::raw: + break; + } + return _C("Codec", "Automatic"); + }; + + std::vector codecs; + for (auto c: wivrn::decoder::supported_codecs()) + if (c != wivrn::raw) + codecs.push_back(c); + + list.push_back({ + .id = "##codec", + .label = _("Video codec"), + .description = _("How video is compressed before it is sent to the headset."), + .ui = ui_kind::combo, + .get_int = [&config, codecs] { + if (config.codec) + for (size_t i = 0; i < codecs.size(); ++i) + if (codecs[i] == *config.codec) + return int(i) + 1; + return 0; }, + .set_int = [&config, codecs](int v) { + config.codec = v == 0 ? std::nullopt : std::optional(codecs[v - 1]); + config.save(); }, + .options = [codecs, codec_name] { + std::vector opts; + opts.push_back(codec_name(std::nullopt)); + for (auto c: codecs) + opts.push_back(codec_name(c)); + return opts; }, + .title = _("Video codec"), + .default_int = 0, + }); + + if (config.codec == wivrn::h265 or config.codec == wivrn::av1) + { + list.push_back({ + .id = "##ten_bit", + .label = _("10-bit color"), + .description = _("Higher color precision, supported by HEVC and AV1."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.bit_depth == 10; }, + .set_bool = [&config](bool v) { config.bit_depth = v ? 10 : 8; config.save(); }, + .default_bool = true, + }); + } + + const int mb = 1'000'000; + list.push_back({ + .id = "##bitrate", + .label = _("Bitrate"), + .description = _("Video data rate sent to the headset."), + .ui = ui_kind::slider, + .get_int = [&config] { return int(config.bitrate_bps / mb); }, + .set_int = [&config](int v) { config.bitrate_bps = uint32_t(v) * mb; config.save(); }, + .v_min = 5, + .v_max = int(config.max_bitrate() / mb), + .fmt = "%d Mbit/s", + .default_int = 50, + }); + + list.push_back({ + .id = "##stream_gui", + .label = _("In-stream window"), + .description = _("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.enable_stream_gui; }, + .set_bool = [&config](bool v) { config.enable_stream_gui = v; config.save(); }, + .default_bool = true, + }); + + ui::page_header(_S("Streaming"), _S("How video is encoded and sent to the headset.")); + render_settings("##streaming", list); +} + +void scenes::lobby::gui_post_processing() +{ + auto & config = application::get_config(); + std::vector list; + + if (application::get_openxr_post_processing_supported()) + { + auto flag_name = [](XrCompositionLayerSettingsFlagsFB f) -> std::string { + switch (f) + { + case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB: + case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB: + return _C("openxr_post_processing", "Normal"); + case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB: + case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB: + return _C("openxr_post_processing", "Quality"); + default: + return _C("openxr_post_processing", "Disabled"); + } + }; + + auto flag_combo = [&](const char * id, std::string label, std::string desc, std::array flags, XrCompositionLayerSettingsFlagsFB configuration::openxr_post_processing_settings::* member) { + std::string title = label; + list.push_back({ + .id = id, + .label = std::move(label), + .description = std::move(desc), + .ui = ui_kind::combo, + .get_int = [&config, flags, member] { + for (size_t i = 0; i < flags.size(); ++i) + if (config.openxr_post_processing.*member == flags[i]) + return int(i); + return 0; }, + .set_int = [&config, flags, member](int v) { + config.openxr_post_processing.*member = flags[v]; + config.save(); }, + .options = [flags, flag_name] { + std::vector o; + for (auto f: flags) + o.push_back(flag_name(f)); + return o; }, + .title = std::move(title), + .default_int = 0, + }); + }; + + flag_combo("##supersampling", _("Supersampling"), _("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}, &configuration::openxr_post_processing_settings::super_sampling); + flag_combo("##sharpening", _("Sharpening"), _("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}, &configuration::openxr_post_processing_settings::sharpening); + } + + ui::page_header(_S("Post-processing"), _S("OpenXR layer supersampling and sharpening.")); + render_settings("##post_processing", list); +} + +void scenes::lobby::gui_audio() +{ + auto & config = application::get_config(); + std::vector list; + + list.push_back({ + .id = "##microphone", + .label = _("Microphone"), + .description = _("Stream the headset microphone to the PC."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.check_feature(feature::microphone); }, + .set_bool = [&config](bool v) { config.set_feature(feature::microphone, v); }, + .default_bool = false, + }); + + list.push_back({ + .id = "##unprocessed", + .label = _("Unprocessed audio"), + .description = _("Force disable audio filters, such as noise cancellation."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.mic_unprocessed_audio; }, + .set_bool = [&config](bool v) { config.mic_unprocessed_audio = v; config.save(); }, + .default_bool = false, + .enabled = [&config] { return config.check_feature(feature::microphone); }, + }); + + ui::page_header(_S("Audio"), _S("Microphone streamed to the PC.")); + render_settings("##audio", list); +} + +void scenes::lobby::gui_devices() +{ + auto & config = application::get_config(); + std::vector list; + + list.push_back({ + .id = "##keyboard", + .label = _("Keyboard"), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.forward_keyboard; }, + .set_bool = [&config](bool v) { config.forward_keyboard = v; config.save(); }, + .default_bool = false, + }); + + list.push_back({ + .id = "##mouse", + .label = _("Mouse"), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.forward_mouse; }, + .set_bool = [&config](bool v) { config.forward_mouse = v; config.save(); }, + .default_bool = false, + }); + + list.push_back({ + .id = "##gamepad", + .label = _("Gamepad"), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.forward_gamepad; }, + .set_bool = [&config](bool v) { config.forward_gamepad = v; config.save(); }, + .default_bool = false, + }); + + ui::page_header(_S("Devices"), _S("Forward input devices to the PC.")); + render_settings("##devices", list); + + if (server_hid_forwarding == false and (config.forward_keyboard or config.forward_mouse or config.forward_gamepad)) + ui::chip(_("The server does not allow forwarded input devices"), ui::chip_style::warning); +} + +void scenes::lobby::gui_tracking() +{ + auto & config = application::get_config(); + std::vector list; + + auto feature_toggle = [&](const char * id, std::string label, std::string desc, feature f, bool def) { + list.push_back({ + .id = id, + .label = std::move(label), + .description = std::move(desc), + .ui = ui_kind::toggle, + .get_bool = [&config, f] { return config.check_feature(f); }, + .set_bool = [&config, f](bool v) { config.set_feature(f, v); }, + .default_bool = def, + }); + }; + + if (system.hand_tracking_supported()) + feature_toggle("##hand", _("Hand tracking"), _("Track your hands for input when controllers are down."), feature::hand_tracking, true); + + if (application::get_eye_gaze_supported()) + feature_toggle("##eye", _("Eye tracking"), _("Used by foveated encoding to focus quality where you look."), feature::eye_gaze, false); + + if (system.face_tracker_supported() != xr::face_tracker_type::none) + feature_toggle("##face", _("Face tracking"), _("Stream facial expressions to the PC."), feature::face_tracking, false); + + const auto body_tracker = system.body_tracker_supported(); + if (body_tracker != xr::body_tracker_type::none) + feature_toggle("##body", + _("Body tracking"), + body_tracker == xr::body_tracker_type::fb or body_tracker == xr::body_tracker_type::meta + ? _("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings, otherwise body data will be guessed from controller and headset positions.") + : _("Stream body joint positions to the PC."), + feature::body_tracking, + false); + + ui::page_header(_S("Tracking"), _S("Body and input tracking sent to the PC.")); + render_settings("##tracking", list); + + if (body_tracker != xr::body_tracker_type::none) + wivrn::gui::body_tracking_parts(system, *imgui_ctx, config); +} + +void scenes::lobby::gui_system() +{ + auto & config = application::get_config(); + std::vector list; + + auto language_name = [](const std::locale & loc = std::locale()) { + return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc); + }; + std::vector> languages; + for (const auto & msg_info: get_locales()) + { + std::string code = msg_info.language; + if (not msg_info.country.empty()) + code += "_" + msg_info.country; + std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet(msg_info)); + languages.emplace_back(language_name(loc), loc, std::move(code)); + } + std::ranges::sort(languages, [](auto & l, auto & r) { return std::get<0>(l) < std::get<0>(r); }); + + list.push_back({ + .id = "##language", + .label = _("Language"), + .description = _("Interface language."), + .ui = ui_kind::combo, + .get_int = [&config, languages] { + if (not config.locale.empty()) + for (size_t i = 0; i < languages.size(); ++i) + if (std::get<2>(languages[i]) == config.locale) + return int(i) + 1; + return 0; }, + .set_int = [&config, languages](int v) { + config.locale = v == 0 ? "" : std::get<2>(languages[v - 1]); + config.save(); + application::instance().load_locale(); }, + .options = [languages] { + std::vector opts; + opts.push_back(_C("language", "System language")); + for (const auto & [lang, loc, code]: languages) + opts.push_back(lang); + return opts; }, + .title = _("Language"), + .default_int = 0, + }); + + list.push_back({ + .id = "##extended", + .label = _("Extended configuration"), + .description = _("Allows unsafe configuration values, use at your own risk."), + .ui = ui_kind::toggle, + .get_bool = [&config] { return config.extended_config; }, + .set_bool = [&config](bool v) { config.extended_config = v; config.save(); }, + .default_bool = false, + }); + + ui::page_header(_S("System"), _S("Language and advanced options.")); + render_settings("##system", list); +} From 12834824ab77060fa4128837288f7790f4308ca5 Mon Sep 17 00:00:00 2001 From: ahsanswr Date: Sat, 13 Jun 2026 18:13:11 +0500 Subject: [PATCH 007/147] Fixes and improvements --- client/constants.h | 2 +- client/render/imgui_impl.cpp | 14 +- client/render/ui_theme.cpp | 8 +- client/render/ui_theme.h | 14 +- client/render/ui_widgets.cpp | 174 +++++++++--- client/render/ui_widgets.h | 8 +- client/scenes/lobby.h | 5 +- client/scenes/lobby_gui.cpp | 201 +++++++++----- client/scenes/lobby_gui_components.cpp | 363 ------------------------- client/scenes/lobby_gui_customize.cpp | 2 +- client/scenes/lobby_gui_theme.cpp | 122 +++++++++ 11 files changed, 432 insertions(+), 481 deletions(-) delete mode 100644 client/scenes/lobby_gui_components.cpp create mode 100644 client/scenes/lobby_gui_theme.cpp diff --git a/client/constants.h b/client/constants.h index f35738e0..10d40b93 100644 --- a/client/constants.h +++ b/client/constants.h @@ -143,7 +143,7 @@ constexpr ImVec2 window_padding = {20, 20}; constexpr float window_border_size = 2; constexpr float window_rounding = 10; -constexpr ImVec2 tooltip_padding = {5, 5}; +constexpr ImVec2 tooltip_padding = {16, 12}; constexpr float tooltip_rounding = 0; constexpr glm::vec3 tooltip_distance = {0, 0.004, 0.005}; diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 2b7fd3a2..e963fea8 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -24,6 +24,7 @@ #include "constants.h" #include "image_loader.h" #include "openxr/openxr.h" +#include "ui_theme.h" #include "utils/mapped_file.h" #include "utils/ranges.h" #include "utils/strings.h" @@ -1280,10 +1281,14 @@ void imgui_context::tooltip(std::string_view text) viewport->Pos = ImVec2(tooltip_layer.vp_origin.x, tooltip_layer.vp_origin.y); viewport->Size = ImVec2(tooltip_layer.vp_size.x, tooltip_layer.vp_size.y); - // Draw the tooltip in the tooltip layer + // Draw the tooltip in the tooltip layer, styled to match the active theme // Clamp position to avoid overflowing on the left or the right + const wivrn::ui::theme & t = wivrn::ui::current(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::tooltip_padding); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::tooltip_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, t.card_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, t.border_size); + ImGui::PushStyleColor(ImGuiCol_PopupBg, t.card); + ImGui::PushStyleColor(ImGuiCol_Border, t.border); auto & style = ImGui::GetStyle(); const ImVec2 text_size = ImGui::CalcTextSize(text.data(), text.data() + text.size(), true); @@ -1293,12 +1298,13 @@ void imgui_context::tooltip(std::string_view text) ImGui::SetNextWindowSizeConstraints({0, 0}, viewport->Size); if (ImGui::BeginTooltip()) { - ImGui::PushStyleColor(ImGuiCol_Text, 0xffffffff); + ImGui::PushStyleColor(ImGuiCol_Text, t.col(t.text)); ImGui::TextUnformatted(text.data(), text.data() + text.size()); ImGui::PopStyleColor(); ImGui::EndTooltip(); } - ImGui::PopStyleVar(2); + ImGui::PopStyleColor(2); + ImGui::PopStyleVar(3); viewport->Pos = pos_backup; viewport->Size = size_backup; diff --git a/client/render/ui_theme.cpp b/client/render/ui_theme.cpp index 00a87e00..0250dacf 100644 --- a/client/render/ui_theme.cpp +++ b/client/render/ui_theme.cpp @@ -56,8 +56,8 @@ static theme dark_default() t.rounding = 8; t.card_rounding = 14; t.border_size = 1; - t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base - t.background_alpha = 0.88f; // ~ the previous hardcoded 224/255 + t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base + t.background_alpha = 1.0f; // fully opaque panel by default return t; } @@ -128,7 +128,7 @@ static theme light() { theme t = dark_default(); t.name = "Light"; - t.background = rgb(236, 238, 242); + t.background = rgb(221, 224, 230); t.card = rgb(255, 255, 255); t.card_hovered = rgb(246, 247, 250); t.control = rgb(212, 216, 224); @@ -136,7 +136,7 @@ static theme light() t.control_active = rgb(184, 190, 201); t.text = rgb(22, 24, 30); t.text_muted = rgb(108, 114, 126); - t.border = rgb(205, 209, 217); + t.border = rgb(176, 182, 194); return t; } diff --git a/client/render/ui_theme.h b/client/render/ui_theme.h index 41558af4..d2a15f1c 100644 --- a/client/render/ui_theme.h +++ b/client/render/ui_theme.h @@ -97,18 +97,20 @@ constexpr float slider_grab_width = 14; constexpr float segmented_inset = 3; // gap around the active segment -constexpr float icon_button_glyph = 0.5; // glyph height as a fraction of the button side +constexpr float icon_button_glyph = 0.58; // glyph height as a fraction of the button side +constexpr float button_label_glyph = 1.35; // leading icon size in a labeled button, x base text size constexpr float combo_row_height = 2.2; // x frame height, big touch rows in the modal constexpr float combo_chevron = 12; // chevron size in the closed box constexpr float combo_modal_min_width = 460; // popup never narrower than this constexpr ImVec2 combo_padding = {16, 0}; // horizontal inner padding of box and rows -constexpr float list_row_box = 52; // leading icon/thumbnail size in a list row -constexpr float list_row_pad = 16; // inner padding of a list row, both axes -constexpr ImVec2 chip_padding = {12, 6}; // inner padding of a chip/badge -constexpr float input_padding_x = 14; // horizontal text padding inside inputs -constexpr float font_modal_title = 1.2; // modal heading, x base font size +constexpr float list_row_box = 52; // leading icon/thumbnail size in a list row +constexpr float list_row_pad = 12; // inner padding of a list row, both axes +constexpr ImVec2 chip_padding = {12, 6}; // inner padding of a chip/badge +constexpr float chip_pill_padding_x = 18; // roomier horizontal padding for height-override pill chips (top bar) +constexpr float input_padding_x = 14; // horizontal text padding inside inputs +constexpr float font_modal_title = 1.2; // modal heading, x base font size constexpr float label_line_gap = 5; // title to description constexpr float label_bottom_pad = 6; // breathing room below the description diff --git a/client/render/ui_widgets.cpp b/client/render/ui_widgets.cpp index 3a7a5647..46846c64 100644 --- a/client/render/ui_widgets.cpp +++ b/client/render/ui_widgets.cpp @@ -171,15 +171,25 @@ float setting_label(const std::string & title, const std::string & description, ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {style.ItemSpacing.x, metrics::label_line_gap}); ImGui::PushTextWrapPos(start.x + text_w); ImGui::TextUnformatted(title.c_str()); + ImGui::PopTextWrapPos(); if (not description.empty()) { ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); - ImGui::TextUnformatted(description.c_str()); + // single line, capped at half the row width and ellipsized so it never wraps or crowds the control + const float desc_w = ImMin(text_w, avail * 0.5f); + std::string text = description; + if (ImGui::CalcTextSize(text.c_str()).x > desc_w) + { + const float ell_w = ImGui::CalcTextSize("...").x; + while (not text.empty() and ImGui::CalcTextSize(text.c_str()).x + ell_w > desc_w) + text.pop_back(); + text += "..."; + } + ImGui::TextUnformatted(text.c_str()); ImGui::PopStyleColor(); ImGui::PopFont(); } - ImGui::PopTextWrapPos(); ImGui::PopStyleVar(); // right-aligned control slot, vertically centered against the label block @@ -190,6 +200,30 @@ float setting_label(const std::string & title, const std::string & description, return start.y + label_h; } +namespace +{ +struct button_colors +{ + ImVec4 bg, bg_hovered, bg_active, text; +}; + +button_colors colors_for(button_style s, const theme & t) +{ + switch (s) + { + case button_style::primary: + return {t.accent, t.accent_hovered, t.accent_active, t.on_accent}; + case button_style::secondary: + return {t.control, t.control_hovered, t.control_active, t.text}; + case button_style::danger: + return {t.danger, t.danger_hovered, t.danger, t.on_accent}; + case button_style::ghost: + return {{0, 0, 0, 0}, t.control, t.control_active, t.text}; + } + return {}; +} +} // namespace + bool button(const std::string & label, button_style s, const ImVec2 & size) { const theme & t = current(); @@ -197,33 +231,11 @@ bool button(const std::string & label, button_style s, const ImVec2 & size) // control height by default, width auto-fits the label const float h = size.y > 0 ? size.y : ImGui::GetFrameHeight() * metrics::control_height; - switch (s) - { - case button_style::primary: - ImGui::PushStyleColor(ImGuiCol_Button, t.accent); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.accent_hovered); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.accent_active); - ImGui::PushStyleColor(ImGuiCol_Text, t.on_accent); - break; - case button_style::secondary: - ImGui::PushStyleColor(ImGuiCol_Button, t.control); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.control_hovered); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.control_active); - ImGui::PushStyleColor(ImGuiCol_Text, t.text); - break; - case button_style::danger: - ImGui::PushStyleColor(ImGuiCol_Button, t.danger); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.danger_hovered); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.danger); - ImGui::PushStyleColor(ImGuiCol_Text, t.on_accent); - break; - case button_style::ghost: - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0, 0, 0, 0}); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.control); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.control_active); - ImGui::PushStyleColor(ImGuiCol_Text, t.text); - break; - } + const button_colors c = colors_for(s, t); + ImGui::PushStyleColor(ImGuiCol_Button, c.bg); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, c.bg_hovered); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, c.bg_active); + ImGui::PushStyleColor(ImGuiCol_Text, c.text); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, t.rounding); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, metrics::button_padding); @@ -234,6 +246,69 @@ bool button(const std::string & label, button_style s, const ImVec2 & size) return pressed; } +bool button(const char * icon, const std::string & label, button_style s, const ImVec2 & size) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext & g = *GImGui; + const ImGuiStyle & style = g.Style; + const theme & t = current(); + + const float h = size.y > 0 ? size.y : ImGui::GetFrameHeight() * metrics::control_height; + const float glyph_size = ImGui::GetFontSize() * metrics::button_label_glyph; + const float gap = ImGui::GetFontSize() * 0.4f; + + ImGui::PushFont(nullptr, glyph_size); + const float icon_w = ImGui::CalcTextSize(icon).x; + ImGui::PopFont(); + const ImVec2 label_size = ImGui::CalcTextSize(label.c_str()); + const float content_w = icon_w + gap + label_size.x; + const float w = size.x > 0 ? size.x : content_w + metrics::button_padding.x * 2; + + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + ImVec2{w, h}); + ImGui::ItemSize(bb, style.FramePadding.y); + const ImGuiID id = window->GetID(label.c_str()); + if (not ImGui::ItemAdd(bb, id)) + return false; + + bool hovered, held; + const bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held); + hover_haptic(); + + const button_colors c = colors_for(s, t); + ImVec4 bg = c.bg; + if (held) + bg = c.bg_active; + else if (hovered) + bg = c.bg_hovered; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); + + const ImU32 col = t.col(c.text); + const ImVec2 center = bb.GetCenter(); + float x = center.x - content_w * 0.5f; + + // icon centred vertically on its ink box, like icon_button + ImGui::PushFont(nullptr, glyph_size); + unsigned int codepoint = 0; + ImTextCharFromUtf8(&codepoint, icon, nullptr); + const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint); + if (glyph) + draw->AddText({x, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon); + else + draw->AddText({x, center.y - glyph_size * 0.5f}, col, icon); + ImGui::PopFont(); + + x += icon_w + gap; + draw->AddText({x, center.y - label_size.y * 0.5f}, col, label.c_str()); + + return pressed; +} + bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const std::string & tooltip) { ImGuiWindow * window = ImGui::GetCurrentWindow(); @@ -404,7 +479,11 @@ bool slider_int(const char * id, int * v, int v_min, int v_max, const char * for ImDrawList * draw = window->DrawList; draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.rounding); if (fraction > 0) - draw->AddRectFilled(bb.Min, {fill_x, bb.Max.y}, t.col(t.accent_active), t.rounding, ImDrawFlags_RoundCornersLeft); + { + // round the right corners too once the fill reaches the box edge, else they stay sharp over the rounded background + const ImDrawFlags fill_flags = fill_x >= bb.Max.x - t.rounding ? ImDrawFlags_RoundCornersAll : ImDrawFlags_RoundCornersLeft; + draw->AddRectFilled(bb.Min, {fill_x, bb.Max.y}, t.col(t.accent_active), t.rounding, fill_flags); + } // bright grab at the fill edge const float grab_w = metrics::slider_grab_width; const float gx = ImClamp(fill_x, bb.Min.x + grab_w * 0.5f, bb.Max.x - grab_w * 0.5f); @@ -498,6 +577,8 @@ namespace { // Where combo modals open, in imgui display coords. Set each frame by the lobby. ImVec2 popup_center = {0, 0}; +// Height of the popup layer; caps tall combo lists so they scroll. 0 = unbounded. +float popup_available_height = 0; // One selectable option inside the combo modal. A tall, full-width touch target // with the name (accent when selected) and an optional muted description. @@ -554,9 +635,10 @@ bool combo_row(const combo_item & item, bool selected) } } // namespace -void set_popup_center(const ImVec2 & center) +void set_popup_center(const ImVec2 & center, float available_height) { popup_center = center; + popup_available_height = available_height; } bool combo(const char * id, const std::string & title, const std::vector & items, int * selected, float width, const int * default_value) @@ -636,15 +718,33 @@ bool combo(const char * id, const std::string & title, const std::vector 0) + { + const float title_h = title.empty() ? 0 : ImGui::GetTextLineHeight() + style.ItemSpacing.y; + const float max_list = popup_available_height * 0.9f - 2 * metrics::card_padding.y - title_h; + list_h = ImMin(list_h, ImMax(max_list, row_h)); + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0}); + ImGui::BeginChild("##list", {0, list_h}); for (int i = 0; i < int(items.size()); ++i) { - if (combo_row(items[i], i == sel)) + const bool is_sel = i == sel; + if (combo_row(items[i], is_sel)) { *selected = i; changed = true; ImGui::CloseCurrentPopup(); } + if (is_sel and ImGui::IsWindowAppearing()) + ImGui::SetScrollHereY(0.5f); // reveal the current value when opening } + ImGui::EndChild(); + ImGui::PopStyleVar(); // click outside dismisses; AllowWhenBlockedByActiveItem so pressing a row still counts as inside if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) @@ -703,9 +803,11 @@ void chip(const std::string & label, chip_style style, bool dot, float height) const ImVec2 ts = ImGui::CalcTextSize(label.c_str()); const ImVec2 pad = metrics::chip_padding; + // tall pill chips (height override, e.g. the top bar) get roomier sides + const float pad_x = height > 0 ? metrics::chip_pill_padding_x : pad.x; const float dot_r = ts.y * 0.26f; - const float dot_gap = dot ? dot_r * 2 + pad.x * 0.55f : 0; - const ImVec2 size = {ts.x + pad.x * 2 + dot_gap, height > 0 ? height : ts.y + pad.y * 2}; + const float dot_gap = dot ? dot_r * 2 + pad_x * 0.55f : 0; + const ImVec2 size = {ts.x + pad_x * 2 + dot_gap, height > 0 ? height : ts.y + pad.y * 2}; const ImVec2 pos = window->DC.CursorPos; const ImRect bb(pos, pos + size); @@ -716,11 +818,11 @@ void chip(const std::string & label, chip_style style, bool dot, float height) ImDrawList * draw = window->DrawList; draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), size.y * 0.5f); - float tx = bb.Min.x + pad.x; + float tx = bb.Min.x + pad_x; if (dot) { draw->AddCircleFilled({tx + dot_r, bb.Min.y + size.y * 0.5f}, dot_r, t.col(fg)); - tx += dot_r * 2 + pad.x * 0.55f; + tx += dot_r * 2 + pad_x * 0.55f; } draw->AddText({tx, bb.Min.y + (size.y - ts.y) * 0.5f}, t.col(fg), label.c_str()); } diff --git a/client/render/ui_widgets.h b/client/render/ui_widgets.h index 3684948f..2abb0fb4 100644 --- a/client/render/ui_widgets.h +++ b/client/render/ui_widgets.h @@ -53,6 +53,8 @@ void row_separator(); float setting_label(const std::string & title, const std::string & description, float control_width); bool button(const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); +// Same, with a larger leading icon glyph drawn before the label +bool button(const char * icon, const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); // tooltip, if not empty, is shown while hovered bool icon_button(const char * icon, const ImVec2 & size = {0, 0}, bool active = false, const std::string & tooltip = {}); @@ -77,8 +79,10 @@ struct combo_item // chosen index, title labels the modal. Returns true when the selection changes. bool combo(const char * id, const std::string & title, const std::vector & items, int * selected, float width = 0, const int * default_value = nullptr); -// Centre (display coords) where combo and begin_modal popups open. Set once per frame. -void set_popup_center(const ImVec2 & center); +// Centre (display coords) where combo and begin_modal popups open, plus the height +// available on the popup layer so tall combo lists cap and scroll instead of being +// clipped. available_height of 0 leaves the list unbounded. Set once per frame. +void set_popup_center(const ImVec2 & center, float available_height = 0); // Hook fired after an interactive item, for a hover haptic. Install once. void set_hover_haptic(std::function hook); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index afe7eafd..82aa1eca 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -56,6 +56,7 @@ class lobby : public scene_impl int add_server_window_port = wivrn::default_port; bool add_server_tcp_only = false; std::string add_server_cookie; + std::string delete_server_cookie; // server pending a delete confirmation utils::future, std::string> async_session; std::optional async_error; @@ -126,8 +127,8 @@ class lobby : public scene_impl tracking, system, customize, + theme, #if WIVRN_CLIENT_DEBUG_MENU - components, debug, #endif about, @@ -237,7 +238,7 @@ class lobby : public scene_impl void gui_system(); void gui_post_processing(); void gui_customize(XrTime predicted_display_time); - void gui_components(); + void gui_theme(); void gui_debug_node_hierarchy(entt::entity root = entt::null); void gui_debug(); void gui_about(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 85110564..ec15275d 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -366,10 +366,14 @@ void scenes::lobby::gui_server_list() ui::page_header(_S("Computers"), _S("Pick a PC running the WiVRn server to stream from.")); const ImVec2 hend = ImGui::GetCursorPos(); - const std::string add_label = std::string(ICON_FA_PLUS " ") + _("Add server"); - const float add_w = ImGui::CalcTextSize(add_label.c_str()).x + ui::metrics::button_padding.x * 2; + const std::string add_label = _("Add server"); + const float font = ImGui::GetFontSize(); + ImGui::PushFont(nullptr, font * ui::metrics::button_label_glyph); + const float glyph_w = ImGui::CalcTextSize(ICON_FA_PLUS).x; + ImGui::PopFont(); + const float add_w = glyph_w + font * 0.4f + ImGui::CalcTextSize(add_label.c_str()).x + ui::metrics::button_padding.x * 2; ImGui::SetCursorPos({hstart.x + header_avail - add_w, hstart.y}); - if (ui::button(add_label, ui::button_style::primary)) + if (ui::button(ICON_FA_PLUS, add_label, ui::button_style::primary)) { add_server_cookie = ""; add_server_window_prettyname = ""; @@ -384,10 +388,10 @@ void scenes::lobby::gui_server_list() for (auto && [cookie, data]: config.servers) sorted_cookies.emplace(data.service.name, cookie); - std::string cookie_to_remove; - // deferred: the action menu runs inside the per-row id stack, but the popup is + // deferred: the action menu runs inside the per-row id stack, but the popups are // opened below in this scope so OpenPopup and begin_modal hash to the same id bool open_add_edit = false; + bool open_delete = false; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); ui::begin_card("##servers"); @@ -408,14 +412,22 @@ void scenes::lobby::gui_server_list() ui::row_separator(); first = false; - const bool available = (data.visible and data.compatible) or data.manual; + // Connect button reflects the real reachability state so a momentary + // discovery delay doesn't read as a hard failure: + // - reachable: manual server, or one discovered with a matching protocol + // - incompatible: discovered and resolved, but the protocol version differs + // - searching: not seen on the network yet (or still resolving its records) + const bool reachable = (data.visible and data.compatible) or data.manual; + const bool incompatible = data.visible and data.service.txt.contains("protocol") and not data.compatible; const float gap = ImGui::GetStyle().ItemSpacing.x; const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height; const std::string sub = fmt::format("{} : {}", data.service.hostname, data.service.port); // trailing controls: [Auto chip] [Connect] [menu], measured up front so the // row body click area can exclude them - const std::string c_label = available ? std::string(ICON_FA_PLAY " ") + _("Connect") : _("Unavailable"); + const char * c_icon = reachable ? ICON_FA_PLAY : (incompatible ? ICON_FA_TRIANGLE_EXCLAMATION : ICON_FA_MAGNIFYING_GLASS); + const std::string c_label = std::string(c_icon) + " " + (reachable ? _("Connect") : (incompatible ? _("Incompatible") : _("Searching…"))); + const std::string c_tooltip = reachable ? std::string{} : (incompatible ? _("Incompatible server version") : _("Looking for this server on your network")); const float cw = ImGui::CalcTextSize(c_label.c_str()).x + ui::metrics::button_padding.x * 2; const std::string chip_label = std::string(ICON_FA_BOLT " ") + _("Auto"); const ImVec2 chip_ts = ImGui::CalcTextSize(chip_label.c_str()); @@ -453,19 +465,22 @@ void scenes::lobby::gui_server_list() open_add_edit = true; break; case 2: - cookie_to_remove = cookie; + delete_server_cookie = cookie; + open_delete = true; break; } x -= bh + gap; - // connect / unavailable + // connect / searching / incompatible ImGui::SetCursorScreenPos({x - cw, row.min.y + (row_h - bh) * 0.5f}); - ImGui::BeginDisabled(not available); - if (ui::button(c_label, available ? ui::button_style::primary : ui::button_style::secondary, {cw, 0})) + ImGui::BeginDisabled(not reachable); + if (ui::button(c_label, reachable ? ui::button_style::primary : ui::button_style::secondary, {cw, 0})) { connect(data); ImGui::OpenPopup("connecting"); } + if (not c_tooltip.empty() and ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + imgui_ctx->tooltip(c_tooltip); ImGui::EndDisabled(); x -= cw + gap; @@ -485,15 +500,12 @@ void scenes::lobby::gui_server_list() } ImGui::PopStyleVar(); - if (cookie_to_remove != "") - { - config.servers.erase(cookie_to_remove); - config.save(); - } - if (open_add_edit) ImGui::OpenPopup("add or edit server"); + if (open_delete) + ImGui::OpenPopup("delete server"); + // Check if we need to report errors after a disconnect if (next_scene and next_scene->current_state() == scenes::stream::state::shutdown and not ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) ImGui::OpenPopup("disconnected"); @@ -530,6 +542,25 @@ void scenes::lobby::gui_server_list() gui_new_server(); wivrn::ui::end_modal(); } + + if (not delete_server_cookie.empty()) + { + std::string name; + if (auto it = config.servers.find(delete_server_cookie); it != config.servers.end()) + name = it->second.service.name; + + switch (wivrn::ui::confirm_modal("delete server", _("Delete server"), fmt::format(_F("Remove \"{}\" from your saved computers?"), name), _("Delete"), _("Cancel"), true)) + { + case 1: + config.servers.erase(delete_server_cookie); + config.save(); + delete_server_cookie = ""; + break; + case -1: + delete_server_cookie = ""; + break; + } + } ImGui::PopStyleVar(3); } @@ -866,46 +897,69 @@ void scenes::lobby::gui_first_run() void scenes::lobby::gui_licenses() { - ImGui::PushFont(nullptr, constants::gui::font_size_large); - ImGui::Text("%s", _("Licenses").c_str()); - ImGui::PopFont(); + namespace ui = wivrn::ui; + const auto & t = ui::current(); - const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"}; - if (not license) + ui::page_header(_S("Licenses"), _S("Open-source components bundled with WiVRn.")); + + // Components shipping a license file, probed once + static const std::vector components = [] { + std::vector v; + for (const char * c: {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"}) + { + try + { + utils::mapped_file probe(std::filesystem::path("assets://licenses") / c); + v.emplace_back(c); + } + catch (...) + { + spdlog::debug("No license file for {}", c); + } + } + return v; + }(); + + if (components.empty()) + return; + + if (selected_item.empty()) + selected_item = components.front(); + + int selected = 0; + for (size_t i = 0; i < components.size(); ++i) + if (components[i] == selected_item) + selected = int(i); + + std::vector items; + for (const auto & c: components) + items.push_back({c.c_str()}); + + const float control_w = 480; + if (ui::combo("##component", _("Component"), items, &selected, control_w) or not license) { - selected_item = *components.begin(); + selected_item = components[selected]; try { license = std::make_unique(std::filesystem::path("assets://licenses") / selected_item); } catch (...) { + license.reset(); spdlog::warn("No license file for {}", selected_item); } } - if (ImGui::BeginCombo("##component", selected_item.c_str())) - { - for (const auto & component: components) - { - try - { - auto current = std::make_unique(std::filesystem::path("assets://licenses") / component); - if (ImGui::Selectable(component, component == selected_item, ImGuiSelectableFlags_SelectOnRelease)) - { - selected_item = component; - license = std::move(current); - } - } - catch (...) - { - spdlog::debug("No license file for {}", component); - } - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); + if (license) + { + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + ui::begin_card("##license_text"); + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); ImGui::TextUnformatted((const char *)license->data(), (const char *)license->data() + license->size()); + ImGui::PopStyleColor(); + ui::end_card(); + ImGui::PopStyleVar(); + } } void scenes::lobby::gui_keyboard() @@ -989,6 +1043,15 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGuiStyle & style = ImGui::GetStyle(); style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base; + // rounding follows the theme so every window/popup gets rounded corners + // (theme::apply() is never called; the widgets theme colours themselves but nothing sets rounding) + style.WindowRounding = wivrn::ui::current().card_rounding; + style.ChildRounding = wivrn::ui::current().card_rounding; + style.PopupRounding = wivrn::ui::current().card_rounding; + style.FrameRounding = wivrn::ui::current().rounding; + style.GrabRounding = wivrn::ui::current().rounding; + style.TabRounding = wivrn::ui::current().rounding; + // base text colour follows the theme so plain ImGui text is legible on light themes style.Colors[ImGuiCol_Text] = wivrn::ui::current().text; style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted; @@ -996,7 +1059,7 @@ std::vector> scenes::lobby::draw_gui(XrTi // combo modals open centred on the popup layer const auto & ui_popup_layer = imgui_ctx->layers()[1]; const glm::vec2 ui_popup_center = ui_popup_layer.vp_origin + ui_popup_layer.vp_size / 2; - wivrn::ui::set_popup_center({ui_popup_center.x, ui_popup_center.y}); + wivrn::ui::set_popup_center({ui_popup_center.x, ui_popup_center.y}, float(ui_popup_layer.vp_size.y)); // let the themed widgets fire the hover haptic and show tooltips wivrn::ui::set_hover_haptic([this] { imgui_ctx->vibrate_on_hover(); }); @@ -1048,21 +1111,23 @@ std::vector> scenes::lobby::draw_gui(XrTi auto & config = application::get_config(); const float TopBarH = 72; - // Top bar: logo on the left, status controls on the right + // Top bar: logo on the left, status controls on the right. + // Transparent child bg so the alpha-blended window background shows through. ImGui::SetCursorPos({0, 0}); - ImGui::PushStyleColor(ImGuiCol_ChildBg, wivrn::ui::current().background); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0}); ImGui::BeginChild("TopBar", {ImGui::GetWindowSize().x, TopBarH}, 0, ImGuiWindowFlags_NoScrollbar); { const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height; const float gap = 8; - // logo + // logo: WiVRn mascot followed by the wordmark + const float logo_size = 44; + ImGui::SetCursorPos({24, (TopBarH - logo_size) * 0.5f}); + if (about_picture) + ImGui::Image(about_picture, {logo_size, logo_size}); + ImGui::SameLine(0, 12); ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * 1.3f); - ImGui::SetCursorPos({24, (TopBarH - ImGui::GetFontSize()) * 0.5f}); - ImGui::PushStyleColor(ImGuiCol_Text, wivrn::ui::current().accent); - ImGui::TextUnformatted(ICON_FA_EYE); - ImGui::PopStyleColor(); - ImGui::SameLine(0, 10); + ImGui::SetCursorPosY((TopBarH - ImGui::GetFontSize()) * 0.5f); ImGui::TextUnformatted("WiVRn"); ImGui::PopFont(); @@ -1070,7 +1135,8 @@ std::vector> scenes::lobby::draw_gui(XrTi const std::string conn = _("Not connected"); const ImVec2 cts = ImGui::CalcTextSize(conn.c_str()); const float dot_r = cts.y * 0.26f; - const float chip_w = cts.x + wivrn::ui::metrics::chip_padding.x * 2.5f + dot_r * 2; + // pill: pad_x on each side + dot + 0.55 pad_x gap before the text (see ui::chip) + const float chip_w = cts.x + wivrn::ui::metrics::chip_pill_padding_x * 2.55f + dot_r * 2; // feature toggles available on this headset (mic + passthrough are always shown) const bool has_hand = system.hand_tracking_supported(); @@ -1116,7 +1182,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (*battery.charge < 0.2) battery_style = wivrn::ui::chip_style::danger; } - const float battery_w = battery_label.empty() ? 0 : gap + ImGui::CalcTextSize(battery_label.c_str()).x + wivrn::ui::metrics::chip_padding.x * 2; + const float battery_w = battery_label.empty() ? 0 : gap + ImGui::CalcTextSize(battery_label.c_str()).x + wivrn::ui::metrics::chip_pill_padding_x * 2; #else const float battery_w = 0; #endif @@ -1230,11 +1296,11 @@ std::vector> scenes::lobby::draw_gui(XrTi gui_customize(predicted_display_time); break; -#if WIVRN_CLIENT_DEBUG_MENU - case tab::components: - gui_components(); + case tab::theme: + gui_theme(); break; +#if WIVRN_CLIENT_DEBUG_MENU case tab::debug: gui_debug(); break; @@ -1265,7 +1331,9 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::EndChild(); ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding - ImGui::PushStyleColor(ImGuiCol_ChildBg, wivrn::ui::current().card); + // Sidebar shares the same transparent background as the rest of the window; + // the sections are separated by hairline dividers drawn below. + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0}); ImGui::SetCursorPos({0, TopBarH}); { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16}); @@ -1293,11 +1361,11 @@ std::vector> scenes::lobby::draw_gui(XrTi current_tab = tab::system; wivrn::ui::nav_section(_S("PERSONALIZE")); - if (wivrn::ui::nav_item(ICON_FA_IMAGE, _S("Customize"), current_tab == tab::customize)) + if (wivrn::ui::nav_item(ICON_FA_IMAGE, _S("Environment"), current_tab == tab::customize)) current_tab = tab::customize; + if (wivrn::ui::nav_item(ICON_FA_PALETTE, _S("Theme"), current_tab == tab::theme)) + current_tab = tab::theme; #if WIVRN_CLIENT_DEBUG_MENU - if (wivrn::ui::nav_item(ICON_FA_PALETTE, "Components", current_tab == tab::components)) - current_tab = tab::components; if (wivrn::ui::nav_item(ICON_FA_BUG_SLASH, _S("Debug"), current_tab == tab::debug)) current_tab = tab::debug; #endif @@ -1317,6 +1385,15 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding (Tabs) } ImGui::PopStyleColor(); // ImGuiCol_ChildBg + + // hairline dividers separating the top bar, sidebar and main panel + const ImU32 divider = ImGui::GetColorU32(wivrn::ui::current().border); + const ImVec2 win_pos = ImGui::GetWindowPos(); + const ImVec2 win_size = ImGui::GetWindowSize(); + ImDrawList * dl = ImGui::GetWindowDrawList(); + dl->AddLine({win_pos.x, win_pos.y + TopBarH}, {win_pos.x + win_size.x, win_pos.y + TopBarH}, divider); + dl->AddLine({win_pos.x + TabWidth, win_pos.y + TopBarH}, {win_pos.x + TabWidth, win_pos.y + win_size.y}, divider); + ImGui::End(); ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding } diff --git a/client/scenes/lobby_gui_components.cpp b/client/scenes/lobby_gui_components.cpp deleted file mode 100644 index ddb7e2fb..00000000 --- a/client/scenes/lobby_gui_components.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2026 Guillaume Meunier - * Copyright (C) 2026 Patrick Nicolas - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define IMGUI_DEFINE_MATH_OPERATORS - -#include "lobby.h" - -#if WIVRN_CLIENT_DEBUG_MENU - -#include "render/ui_theme.h" -#include "render/ui_widgets.h" - -#include "imgui.h" - -#include "IconsFontAwesome6.h" - -namespace ui = wivrn::ui; - -// Card title shown above the rows -static void card_title(const char * title) -{ - ImGui::PushStyleColor(ImGuiCol_Text, ui::current().text_muted); - ImGui::TextUnformatted(title); - ImGui::PopStyleColor(); - ImGui::Dummy({0, 4}); -} - -void scenes::lobby::gui_components() -{ - ui::theme & theme = ui::current(); - - ui::page_header("Components", "Live preview of the WiVRn UI kit"); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); - const float control_w = 480; - - // Theme - ui::begin_card("##theme"); - { - card_title("THEME"); - - // Accent - ImGui::TextUnformatted("Accent color"); - ImGui::Dummy({0, 2}); - for (const auto & swatch: ui::accent_swatches()) - { - const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z; - const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop); - if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f})) - ui::set_accent(swatch); - ImGui::SameLine(); - } - ImGui::NewLine(); - - ui::row_separator(); - - // Preset - static int preset = 1; // dark_default - const auto preset_list = ui::presets(); - std::vector preset_items; - for (const auto & p: preset_list) - preset_items.push_back({p.name.c_str()}); - - static const int preset_default = 1; - ui::setting_label("Preset", "Surface and background palette", control_w); - if (ui::combo("##preset", "Theme preset", preset_items, &preset, control_w, &preset_default)) - { - const ImVec4 keep_accent = theme.accent; - const ImVec4 keep_hover = theme.accent_hovered; - const ImVec4 keep_active = theme.accent_active; - ui::set_theme(preset_list[preset]); - theme.accent = keep_accent; - theme.accent_hovered = keep_hover; - theme.accent_active = keep_active; - } - - ui::row_separator(); - - // Rounding - static const int rounding_default = 8; - int rounding = int(theme.rounding); - ui::setting_label("Rounding", "Corner radius of controls", control_w); - if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default)) - theme.rounding = float(rounding); - - ui::row_separator(); - - static const int card_rounding_default = 14; - int card_rounding = int(theme.card_rounding); - ui::setting_label("Card rounding", "Corner radius of panels", control_w); - if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default)) - theme.card_rounding = float(card_rounding); - - ui::row_separator(); - - // Text size, applied globally via style.FontScaleMain next frame. 100% is the - // design default; the value is a user multiplier on metrics::font_base. - static const int font_scale_default = 100; - int font_scale = int(theme.font_scale * 100); - ui::setting_label("Text size", "Global font scale", control_w); - if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default)) - theme.font_scale = float(font_scale) / 100.f; - - ui::row_separator(); - - // Panel transparency - static const int opacity_default = 88; - int opacity = int(theme.background_alpha * 100); - ui::setting_label("Panel opacity", "Opacity of the main panel background", control_w); - if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) - theme.background_alpha = float(opacity) / 100.f; - - ui::end_card(); - } - - // Buttons - ui::begin_card("##buttons"); - { - card_title("BUTTONS"); - - ui::button("Primary", ui::button_style::primary); - ImGui::SameLine(); - ui::button("Secondary", ui::button_style::secondary); - ImGui::SameLine(); - ui::button(ICON_FA_POWER_OFF " Disconnect", ui::button_style::danger); - ImGui::SameLine(); - ui::button("Ghost", ui::button_style::ghost); - - ui::row_separator(); - - card_title("ICON BUTTONS"); - static bool mic = true; - if (ui::icon_button(ICON_FA_MICROPHONE, {}, mic, mic ? "Mute microphone" : "Unmute microphone")) - mic = not mic; - ImGui::SameLine(); - ui::icon_button(ICON_FA_EYE_SLASH, {}, false, "Toggle passthrough"); - ImGui::SameLine(); - ui::icon_button(ICON_FA_HAND, {}, false, "Hand tracking"); - ImGui::SameLine(); - ui::icon_button(ICON_FA_ARROW_ROTATE_LEFT, {}, false, "Recenter"); - - ui::end_card(); - } - - // Toggles - ui::begin_card("##toggles"); - { - card_title("TOGGLES"); - - // room for the toggle plus a trailing reset slot - const float toggle_w = ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect; - const float toggle_row_w = toggle_w + ImGui::GetFrameHeight() * ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.x; - - static const bool spacewarp_default = false; - static bool spacewarp = true; - ui::setting_label("Application SpaceWarp", "Synthesises in-between frames so motion stays smooth", toggle_row_w); - ui::toggle("##spacewarp", &spacewarp, &spacewarp_default); - - ui::row_separator(); - - static const bool high_power_default = true; - static bool high_power = true; - ui::setting_label("High power mode", "Higher sustained clocks for steadier frames", toggle_row_w); - ui::toggle("##high_power", &high_power, &high_power_default); - - ui::end_card(); - } - - // Sliders - ui::begin_card("##sliders"); - { - card_title("SLIDERS"); - - static const int resolution_default = 100; - static int resolution = 145; - ui::setting_label("Render resolution", "Pixels rendered per eye", control_w); - ui::slider_int("##resolution", &resolution, 50, 350, "%d%%", {control_w, 0}, &resolution_default); - - ui::row_separator(); - - static const int bitrate_default = 100; - static int bitrate = 165; - ui::setting_label("Bitrate", "Video data rate", control_w); - ui::slider_int("##bitrate", &bitrate, 10, 500, "%d Mbit/s", {control_w, 0}, &bitrate_default); - - ui::end_card(); - } - - // Segmented control - ui::begin_card("##segmented"); - { - card_title("SEGMENTED CONTROL"); - - static const int refresh_default = 0; - static int refresh = 2; - static const std::vector rates = {"Auto", "72", "80", "90", "120"}; - ui::setting_label("Refresh rate", "Frames per second shown in the headset", control_w); - ui::segmented("##refresh", rates, &refresh, {control_w, 0}, &refresh_default); - - ui::end_card(); - } - - // Combo - ui::begin_card("##combo"); - { - card_title("COMBO"); - - static const std::vector codecs = { - {"Automatic", "Picks the best codec your PC supports"}, - {"H.264", "Lowest latency, widest support"}, - {"HEVC (H.265)", "Better quality per bit"}, - {"AV1", "Best efficiency, newest GPUs only"}, - }; - static const int codec_default = 0; - static int selected = 2; - - ui::setting_label("Video codec", "How video is compressed and sent to the headset", control_w); - ui::combo("##codec", "Video codec", codecs, &selected, control_w, &codec_default); - - ui::end_card(); - } - - // Navigation (sidebar styling) - ui::begin_card("##nav"); - { - card_title("NAVIGATION"); - - static int nav = 2; - int row = 0; - - if (ui::nav_item(ICON_FA_COMPUTER, "Computers", nav == row)) - nav = row; - ++row; - - ui::nav_section("SETTINGS"); - for (const auto & [icon, label]: { - std::pair{ICON_FA_GAUGE_HIGH, "Performance"}, - std::pair{ICON_FA_TOWER_BROADCAST, "Streaming"}, - std::pair{ICON_FA_CROP, "Field of view"}, - std::pair{ICON_FA_VOLUME_HIGH, "Audio"}, - std::pair{ICON_FA_LOCATION_CROSSHAIRS, "Tracking"}, - std::pair{ICON_FA_GEARS, "System"}, - }) - { - if (ui::nav_item(icon, label, nav == row)) - nav = row; - ++row; - } - - ui::nav_section("PERSONALIZE"); - if (ui::nav_item(ICON_FA_IMAGE, "Customize", nav == row)) - nav = row; - ++row; - - ui::end_card(); - } - - // Chips - ui::begin_card("##chips"); - { - card_title("CHIPS"); - - ui::chip(ICON_FA_BOLT " Auto", ui::chip_style::accent); - ImGui::SameLine(); - ui::chip(ICON_FA_BATTERY_HALF " 38%", ui::chip_style::success); - ImGui::SameLine(); - ui::chip("Connected", ui::chip_style::success, true); - ImGui::SameLine(); - ui::chip("Not connected", ui::chip_style::muted, true); - ImGui::SameLine(); - ui::chip("Unavailable", ui::chip_style::muted); - ImGui::SameLine(); - ui::chip("Beta", ui::chip_style::warning); - - ui::end_card(); - } - - // Text & number inputs - ui::begin_card("##inputs"); - { - card_title("INPUTS"); - - static std::string name, address; - static int port = 9757; - - ui::setting_label("Name", "Friendly label for the server", control_w); - ui::input_text("##name", name, "My gaming PC", control_w); - - ui::row_separator(); - - ui::setting_label("Address", "Hostname or IP of the PC", control_w); - ui::input_text("##address", address, "192.168.1.10 or host.local", control_w); - - ui::row_separator(); - - ui::setting_label("Port", "TCP/UDP port the server listens on", control_w); - ui::input_int("##port", &port, 1, 1, 65535, control_w); - - ui::end_card(); - } - - // Dialog - ui::begin_card("##dialog"); - { - card_title("DIALOG"); - - if (ui::button("Add server")) - ImGui::OpenPopup("##add_server_demo"); - - static std::string d_name, d_address; - static int d_port = 9757; - if (ui::begin_modal("##add_server_demo", "Add server", 620)) - { - const float w = ImGui::GetContentRegionAvail().x; - ImGui::TextUnformatted("Name"); - ui::input_text("##d_name", d_name, "My gaming PC", w); - ImGui::Dummy({0, 4}); - ImGui::TextUnformatted("Address"); - ui::input_text("##d_address", d_address, "192.168.1.10 or host.local", w); - ImGui::Dummy({0, 4}); - ImGui::TextUnformatted("Port"); - ui::input_int("##d_port", &d_port, 1, 1, 65535, w); - - ImGui::Dummy({0, 12}); - - // right-aligned footer - const float gap = ImGui::GetStyle().ItemSpacing.x; - const float cancel_w = ImGui::CalcTextSize("Cancel").x + ui::metrics::button_padding.x * 2; - const float save_w = ImGui::CalcTextSize("Save").x + ui::metrics::button_padding.x * 2; - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - cancel_w - save_w - gap); - - if (ui::button("Cancel", ui::button_style::secondary)) - ImGui::CloseCurrentPopup(); - ImGui::SameLine(); - if (ui::button("Save", ui::button_style::primary)) - ImGui::CloseCurrentPopup(); - - ui::end_modal(); - } - - ui::end_card(); - } - - ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing -} - -#endif // WIVRN_CLIENT_DEBUG_MENU diff --git a/client/scenes/lobby_gui_customize.cpp b/client/scenes/lobby_gui_customize.cpp index a42935c8..a5441c5b 100644 --- a/client/scenes/lobby_gui_customize.cpp +++ b/client/scenes/lobby_gui_customize.cpp @@ -651,7 +651,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time) namespace ui = wivrn::ui; - ui::page_header(_S("Customize"), _S("Choose the environment your panels float in.")); + ui::page_header(_S("Environment"), _S("Choose the environment your panels float in.")); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); diff --git a/client/scenes/lobby_gui_theme.cpp b/client/scenes/lobby_gui_theme.cpp new file mode 100644 index 00000000..2cfcf12f --- /dev/null +++ b/client/scenes/lobby_gui_theme.cpp @@ -0,0 +1,122 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define IMGUI_DEFINE_MATH_OPERATORS + +#include "lobby.h" + +#include "render/ui_theme.h" +#include "render/ui_widgets.h" +#include "utils/i18n.h" + +#include "imgui.h" + +#include +#include + +namespace ui = wivrn::ui; + +void scenes::lobby::gui_theme() +{ + ui::theme & theme = ui::current(); + + ui::page_header(_S("Theme"), _S("Accent color, palette and sizing of the interface.")); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + const float control_w = 480; + + ui::begin_card("##theme"); + { + // Accent + ImGui::TextUnformatted(_S("Accent color")); + ImGui::Dummy({0, 2}); + for (const auto & swatch: ui::accent_swatches()) + { + const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z; + const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop); + if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f})) + ui::set_accent(swatch); + ImGui::SameLine(); + } + ImGui::NewLine(); + + ui::row_separator(); + + // Preset + static int preset = 1; // dark_default + const auto preset_list = ui::presets(); + std::vector preset_items; + for (const auto & p: preset_list) + preset_items.push_back({p.name.c_str()}); + + static const int preset_default = 1; + ui::setting_label(_S("Preset"), _S("Surface and background palette"), control_w); + if (ui::combo("##preset", _("Theme preset"), preset_items, &preset, control_w, &preset_default)) + { + // keep the accent across a preset change, only the surfaces swap + const ImVec4 keep_accent = theme.accent; + const ImVec4 keep_hover = theme.accent_hovered; + const ImVec4 keep_active = theme.accent_active; + ui::set_theme(preset_list[preset]); + theme.accent = keep_accent; + theme.accent_hovered = keep_hover; + theme.accent_active = keep_active; + } + + ui::row_separator(); + + // Rounding + static const int rounding_default = 8; + int rounding = int(theme.rounding); + ui::setting_label(_S("Rounding"), _S("Corner radius of controls"), control_w); + if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default)) + theme.rounding = float(rounding); + + ui::row_separator(); + + static const int card_rounding_default = 14; + int card_rounding = int(theme.card_rounding); + ui::setting_label(_S("Card rounding"), _S("Corner radius of panels"), control_w); + if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default)) + theme.card_rounding = float(card_rounding); + + ui::row_separator(); + + // Text size, applied globally via style.FontScaleMain next frame. 100% is the + // design default; the value is a user multiplier on metrics::font_base. + static const int font_scale_default = 100; + int font_scale = int(theme.font_scale * 100); + ui::setting_label(_S("Text size"), _S("Global font scale"), control_w); + if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default)) + theme.font_scale = float(font_scale) / 100.f; + + ui::row_separator(); + + // Panel transparency + static const int opacity_default = 100; + int opacity = int(theme.background_alpha * 100); + ui::setting_label(_S("Panel opacity"), _S("Opacity of the main panel background"), control_w); + if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) + theme.background_alpha = float(opacity) / 100.f; + + ui::end_card(); + } + + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing +} From e4b4bfa66d4ab470947a22a83745941271fc895e Mon Sep 17 00:00:00 2001 From: ahsanswr Date: Sat, 13 Jun 2026 20:23:14 +0500 Subject: [PATCH 008/147] Fixes and improvements --- client/render/ui_theme.h | 3 ++ client/render/ui_widgets.cpp | 30 ++++++++++++++++- client/render/ui_widgets.h | 20 ++++++++++++ client/scenes/lobby_gui.cpp | 46 +++++++++++---------------- client/scenes/lobby_gui_customize.cpp | 32 +++++++------------ client/scenes/lobby_gui_settings.cpp | 4 +-- client/scenes/lobby_gui_theme.cpp | 4 +-- 7 files changed, 86 insertions(+), 53 deletions(-) diff --git a/client/render/ui_theme.h b/client/render/ui_theme.h index d2a15f1c..005355e3 100644 --- a/client/render/ui_theme.h +++ b/client/render/ui_theme.h @@ -115,6 +115,9 @@ constexpr float font_modal_title = 1.2; // modal heading, x base font size constexpr float label_line_gap = 5; // title to description constexpr float label_bottom_pad = 6; // breathing room below the description constexpr float nav_section_gap = 18; // space above a sidebar section header + +constexpr ImVec2 card_item_spacing = {12, 10}; // ItemSpacing pushed around a card section +constexpr float setting_control_width = 480; // width of the control in a setting row } // namespace metrics // Theme in effect, call current().apply() after mutating diff --git a/client/render/ui_widgets.cpp b/client/render/ui_widgets.cpp index 46846c64..596d522c 100644 --- a/client/render/ui_widgets.cpp +++ b/client/render/ui_widgets.cpp @@ -224,6 +224,31 @@ button_colors colors_for(button_style s, const theme & t) } } // namespace +std::string icon_label(const char * icon, const std::string & label) +{ + return std::string(icon) + " " + label; +} + +float button_width(const std::string & label) +{ + return ImGui::CalcTextSize(label.c_str()).x + metrics::button_padding.x * 2; +} + +float button_width(const char * icon, const std::string & label) +{ + ImGui::PushFont(nullptr, ImGui::GetFontSize() * metrics::button_label_glyph); + const float icon_w = ImGui::CalcTextSize(icon).x; + ImGui::PopFont(); + const float gap = ImGui::GetFontSize() * 0.4f; + return icon_w + gap + ImGui::CalcTextSize(label.c_str()).x + metrics::button_padding.x * 2; +} + +ImVec2 chip_size(const std::string & label) +{ + const ImVec2 ts = ImGui::CalcTextSize(label.c_str()); + return {ts.x + metrics::chip_padding.x * 2, ts.y + metrics::chip_padding.y * 2}; +} + bool button(const std::string & label, button_style s, const ImVec2 & size) { const theme & t = current(); @@ -866,7 +891,10 @@ bool nav_item(const char * icon, const std::string & label, bool selected) hover_haptic(); ImDrawList * draw = window->DrawList; - const ImVec4 bg = selected ? t.control : (hovered ? t.control_hovered : ImVec4{0, 0, 0, 0}); + // Subtle accent tint at a fixed alpha so the highlight reads the same in every + // theme, instead of the per-theme control surface whose contrast varies. + ImVec4 bg = t.accent; + bg.w = selected ? 0.16f : (hovered ? 0.08f : 0); if (bg.w > 0) draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); diff --git a/client/render/ui_widgets.h b/client/render/ui_widgets.h index 2abb0fb4..054782e4 100644 --- a/client/render/ui_widgets.h +++ b/client/render/ui_widgets.h @@ -52,6 +52,19 @@ void row_separator(); // enough for a multi-line label. float setting_label(const std::string & title, const std::string & description, float control_width); +// "