Skip to content

Commit

Permalink
fix: 🐛 Fix launcher crash; gui refactor (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Aug 15, 2024
1 parent c39a7e3 commit c615f18
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 299 deletions.
52 changes: 0 additions & 52 deletions alvr/dashboard/src/dashboard/basic_components/modal.rs

This file was deleted.

4 changes: 2 additions & 2 deletions alvr/dashboard/src/dashboard/components/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::{
presets::{builtin_schema, PresetControl},
NestingInfo, SettingControl,
};
use crate::dashboard::{DisplayString, ServerRequest};
use alvr_gui_common::theme;
use crate::dashboard::ServerRequest;
use alvr_gui_common::{theme, DisplayString};
use alvr_packets::AudioDevicesList;
use alvr_session::{SessionSettings, Settings};
use eframe::egui::{self, Align, Frame, Grid, Layout, RichText, ScrollArea, Ui};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{reset, NestingInfo};
use crate::dashboard::basic_components;
use alvr_packets::PathValuePair;
use eframe::{
egui::{Layout, Ui},
Expand Down Expand Up @@ -46,7 +45,7 @@ impl Control {
}

ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
if basic_components::switch(ui, enabled_mut).clicked() {
if alvr_gui_common::switch(ui, enabled_mut).clicked() {
request = get_request(&self.nesting_info, *enabled_mut);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{reset, NestingInfo, SettingControl};
use crate::dashboard::{basic_components, get_id, DisplayString};
use alvr_gui_common::DisplayString;
use alvr_packets::PathValuePair;
use alvr_session::settings_schema::{ChoiceControlType, SchemaEntry, SchemaNode};
use eframe::{
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Control {
variant_indices,
variant_controls,
gui: gui.unwrap_or(ChoiceControlType::Dropdown),
combobox_id: get_id(),
combobox_id: alvr_gui_common::get_id(),
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ impl Control {
let mut request = None;
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
if matches!(&self.gui, ChoiceControlType::ButtonGroup) {
if basic_components::button_group_clicked(ui, &self.variant_labels, variant_mut) {
if alvr_gui_common::button_group_clicked(ui, &self.variant_labels, variant_mut) {
request = get_request(&self.nesting_info, variant_mut);
}
} else if let Some(mut index) = self.variant_indices.get(variant_mut).cloned() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::collections::{HashMap, HashSet};

use super::schema::{HigherOrderChoiceSchema, PresetModifierOperation};
use crate::dashboard::{
basic_components,
components::{self, NestingInfo, SettingControl, INDENTATION_STEP},
};
use crate::dashboard::components::{self, NestingInfo, SettingControl, INDENTATION_STEP};
use alvr_gui_common::theme::{
log_colors::{INFO_LIGHT, WARNING_LIGHT},
OK_GREEN,
Expand Down Expand Up @@ -145,11 +142,11 @@ impl Control {

if let Some(string) = &self.help {
if ui.colored_label(INFO_LIGHT, "❓").hovered() {
basic_components::tooltip(ui, &format!("{}_help_tooltip", self.name), string);
alvr_gui_common::tooltip(ui, &format!("{}_help_tooltip", self.name), string);
}
}
if self.steamvr_restart_flag && ui.colored_label(WARNING_LIGHT, "⚠").hovered() {
basic_components::tooltip(
alvr_gui_common::tooltip(
ui,
"steamvr_restart_tooltip",
&format!(
Expand All @@ -161,7 +158,7 @@ impl Control {

// The emoji is blue but it will be green in the UI
if self.real_time_flag && ui.colored_label(OK_GREEN, "🔵").hovered() {
basic_components::tooltip(
alvr_gui_common::tooltip(
ui,
"real_time_tooltip",
"This setting can be changed in real-time during streaming!",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use super::{collapsible, NestingInfo, SettingControl, INDENTATION_STEP};
use crate::dashboard::{basic_components, DisplayString};
use alvr_gui_common::theme::{
log_colors::{INFO_LIGHT, WARNING_LIGHT},
OK_GREEN,
use alvr_gui_common::{
theme::{
log_colors::{INFO_LIGHT, WARNING_LIGHT},
OK_GREEN,
},
DisplayString,
};
use alvr_packets::PathValuePair;
use alvr_session::settings_schema::{SchemaEntry, SchemaNode};
Expand Down Expand Up @@ -114,7 +116,7 @@ impl Control {

if let Some(string) = &entry.help {
if ui.colored_label(INFO_LIGHT, "❓").hovered() {
basic_components::tooltip(
alvr_gui_common::tooltip(
ui,
&format!("{}_help_tooltip", entry.id.display),
string,
Expand All @@ -123,7 +125,7 @@ impl Control {
}
if entry.steamvr_restart_flag && ui.colored_label(WARNING_LIGHT, "⚠").hovered()
{
basic_components::tooltip(
alvr_gui_common::tooltip(
ui,
"steamvr_restart_tooltip",
&format!(
Expand All @@ -135,7 +137,7 @@ impl Control {

// The emoji is blue but it will be green in the UI
if entry.real_time_flag && ui.colored_label(OK_GREEN, "🔵").hovered() {
basic_components::tooltip(
alvr_gui_common::tooltip(
ui,
"real_time_tooltip",
"This setting can be changed in real-time during streaming!",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{reset, NestingInfo, SettingControl};
use crate::dashboard::basic_components;
use alvr_packets::PathValuePair;
use alvr_session::settings_schema::SchemaNode;
use eframe::{
Expand Down Expand Up @@ -63,7 +62,7 @@ impl Control {
}

ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
if basic_components::switch(ui, enabled_mut).clicked() {
if alvr_gui_common::switch(ui, enabled_mut).clicked() {
request = get_request(&self.nesting_info, *enabled_mut);
}

Expand Down
33 changes: 1 addition & 32 deletions alvr/dashboard/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod basic_components;
mod components;

use self::components::{
Expand All @@ -11,37 +10,7 @@ use alvr_gui_common::theme;
use alvr_packets::{PathValuePair, ServerRequest};
use alvr_session::SessionConfig;
use eframe::egui::{self, Align, CentralPanel, Frame, Layout, Margin, RichText, SidePanel, Stroke};
use std::{
collections::BTreeMap,
ops::Deref,
sync::{atomic::AtomicUsize, Arc},
};

#[derive(Clone)]
pub struct DisplayString {
pub id: String,
pub display: String,
}

impl From<(String, String)> for DisplayString {
fn from((id, display): (String, String)) -> Self {
Self { id, display }
}
}

impl Deref for DisplayString {
type Target = String;

fn deref(&self) -> &String {
&self.id
}
}

fn get_id() -> usize {
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);

NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
}
use std::{collections::BTreeMap, sync::Arc};

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum Tab {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dashboard::DisplayString;
use eframe::egui::Ui;
use crate::DisplayString;
use egui::Ui;

// todo: use a custom widget
pub fn button_group_clicked(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod button_group;
mod modal;
mod switch;
mod tooltip;

pub use button_group::*;
pub use modal::*;
pub use switch::*;
pub use tooltip::*;
56 changes: 56 additions & 0 deletions alvr/gui_common/src/basic_components/modal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use egui::{Align, Align2, Context, Layout, Ui, Window};
use std::fmt::{self, Display, Formatter};

#[derive(Clone, PartialEq)]
pub enum ModalButton {
Ok,
Cancel,
Close,
Custom(String),
}

impl Display for ModalButton {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
ModalButton::Ok => write!(f, "OK"),
ModalButton::Cancel => write!(f, "Cancel"),
ModalButton::Close => write!(f, "Close"),
ModalButton::Custom(text) => write!(f, "{}", text),
}
}
}

pub fn modal(
context: &Context,
title: &str,
content: Option<impl FnOnce(&mut Ui)>,
buttons: &[ModalButton],
) -> Option<ModalButton> {
let mut response = None;

Window::new(title)
.anchor(Align2::CENTER_CENTER, (0.0, 0.0))
.collapsible(false)
.resizable(false)
.show(context, |ui| {
ui.vertical_centered_justified(|ui| {
if let Some(content) = content {
ui.add_space(10.0);
content(ui);
ui.add_space(10.0);
}

ui.columns(buttons.len(), |cols| {
for (idx, response_type) in buttons.iter().enumerate() {
cols[idx].with_layout(Layout::top_down_justified(Align::Center), |ui| {
if ui.button(response_type.to_string()).clicked() {
response = Some(response_type.clone());
}
});
}
});
});
});

response
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eframe::egui::{self, Response, Sense, Ui, WidgetInfo, WidgetType};
use egui::{self, Response, Sense, Ui, WidgetInfo, WidgetType};

pub fn switch(ui: &mut Ui, on: &mut bool) -> Response {
let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0, 1.0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eframe::egui::{self, popup, Ui};
use egui::{self, popup, Ui};

pub fn tooltip(ui: &mut Ui, id: &str, text: &str) {
popup::show_tooltip_text(ui.ctx(), ui.layer_id(), egui::Id::new(id), text);
Expand Down
31 changes: 31 additions & 0 deletions alvr/gui_common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
mod basic_components;
pub mod theme;

pub use basic_components::*;

use std::{ops::Deref, sync::atomic::AtomicUsize};

pub fn get_id() -> usize {
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);

NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
}

#[derive(Clone)]
pub struct DisplayString {
pub id: String,
pub display: String,
}

impl From<(String, String)> for DisplayString {
fn from((id, display): (String, String)) -> Self {
Self { id, display }
}
}

impl Deref for DisplayString {
type Target = String;

fn deref(&self) -> &String {
&self.id
}
}
Loading

0 comments on commit c615f18

Please sign in to comment.