mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
222 lines
7.5 KiB
Rust
222 lines
7.5 KiB
Rust
use super::theme::*;
|
|
use super::SteamFrameGpuiApp;
|
|
use crate::engine::SubsystemStatus;
|
|
use gpui::{div, prelude::*, px, rgb, DefiniteLength, IntoElement};
|
|
|
|
impl SteamFrameGpuiApp {
|
|
pub(super) fn render_status_badge(&self, label: &str, status: &SubsystemStatus) -> impl IntoElement {
|
|
let (color, text) = match status {
|
|
SubsystemStatus::Stopped => (COLOR_TEXT_MUTED, "Arrêté"),
|
|
SubsystemStatus::Disabled => (COLOR_TEXT_MUTED, "OFF"),
|
|
SubsystemStatus::Starting => (COLOR_ORANGE, "Démarrage..."),
|
|
SubsystemStatus::Running(_) => (COLOR_GREEN, "Actif"),
|
|
SubsystemStatus::Warning(_) => (COLOR_ORANGE, "Attention"),
|
|
SubsystemStatus::Error(_) => (COLOR_RED, "Erreur"),
|
|
};
|
|
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_1p5()
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.child(
|
|
div()
|
|
.w(px(6.0))
|
|
.h(px(6.0))
|
|
.rounded_full()
|
|
.bg(rgb(color)),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
|
.child(label.to_string()),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(rgb(color))
|
|
.child(text.to_string()),
|
|
)
|
|
}
|
|
|
|
pub(super) fn render_toggle_pill(&self, label: &str, is_on: bool, on_color: gpui::Rgba) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_1p5()
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(if is_on { rgb(0x132320) } else { rgb(COLOR_SURFACE_ELEVATED) })
|
|
.border_1()
|
|
.border_color(if is_on { on_color } else { rgb(COLOR_BORDER_SUBTLE) })
|
|
.rounded_md()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
|
.text_color(if is_on { on_color } else { rgb(COLOR_TEXT_MUTED) })
|
|
.child(format!("{} : {}", label, if is_on { "ON" } else { "OFF" }))
|
|
}
|
|
|
|
pub(super) fn render_monitor_progress_bar(
|
|
&self,
|
|
label: &str,
|
|
pct: u8,
|
|
crsf: u16,
|
|
bar_color: u32,
|
|
) -> impl IntoElement {
|
|
let frac = (pct as f32 / 100.0).clamp(0.0, 1.0);
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_0p5()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child(div().text_color(rgb(COLOR_TEXT_MAIN)).child(label.to_string()))
|
|
.child(
|
|
div()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child(format!("{:3}% | CRSF {}", pct, crsf)),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.w_full()
|
|
.h(px(7.0))
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_full()
|
|
.overflow_hidden()
|
|
.child(
|
|
div()
|
|
.h_full()
|
|
.w(DefiniteLength::Fraction(frac))
|
|
.bg(rgb(bar_color)),
|
|
),
|
|
)
|
|
}
|
|
|
|
pub(super) fn render_monitor_bipolar_bar(
|
|
&self,
|
|
label: &str,
|
|
pct_signed: f32,
|
|
crsf: u16,
|
|
bar_color: u32,
|
|
) -> impl IntoElement {
|
|
let clamped = pct_signed.clamp(-100.0, 100.0);
|
|
let left_frac = if clamped < 0.0 {
|
|
(-clamped / 100.0).clamp(0.0, 1.0)
|
|
} else {
|
|
0.0
|
|
};
|
|
let right_frac = if clamped > 0.0 {
|
|
(clamped / 100.0).clamp(0.0, 1.0)
|
|
} else {
|
|
0.0
|
|
};
|
|
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_0p5()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child(div().text_color(rgb(COLOR_TEXT_MAIN)).child(label.to_string()))
|
|
.child(
|
|
div()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child(format!("{:+.0}% | CRSF {}", clamped, crsf)),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.w_full()
|
|
.h(px(8.0))
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_full()
|
|
.overflow_hidden()
|
|
// Moitié gauche (remplissage depuis le centre vers la gauche)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_end()
|
|
.w(DefiniteLength::Fraction(0.5))
|
|
.h_full()
|
|
.child(
|
|
div()
|
|
.h_full()
|
|
.w(DefiniteLength::Fraction(left_frac))
|
|
.bg(rgb(bar_color)),
|
|
),
|
|
)
|
|
// Repère central
|
|
.child(div().w(px(2.0)).h_full().bg(rgb(COLOR_TEXT_MUTED)))
|
|
// Moitié droite (remplissage depuis le centre vers la droite)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_start()
|
|
.w(DefiniteLength::Fraction(0.5))
|
|
.h_full()
|
|
.child(
|
|
div()
|
|
.h_full()
|
|
.w(DefiniteLength::Fraction(right_frac))
|
|
.bg(rgb(bar_color)),
|
|
),
|
|
),
|
|
)
|
|
}
|
|
|
|
|
|
pub(super) fn render_crsf_gauge(&self, label: &str, deg: f32, crsf: u16, max_deg: f32) -> impl IntoElement {
|
|
let safe_max = max_deg.max(1.0);
|
|
let safe_deg = if deg.is_finite() { deg } else { 0.0 };
|
|
let norm = ((safe_deg / safe_max) * 0.5 + 0.5).clamp(0.0, 1.0);
|
|
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_0p5()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child(label.to_string())
|
|
.child(format!("{:+.1}° (CRSF: {})", safe_deg, crsf)),
|
|
)
|
|
.child(
|
|
div()
|
|
.w_full()
|
|
.h(px(6.0))
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_full()
|
|
.overflow_hidden()
|
|
.child(
|
|
div()
|
|
.h_full()
|
|
.w(DefiniteLength::Fraction(norm))
|
|
.bg(rgb(COLOR_ORANGE)),
|
|
),
|
|
)
|
|
}
|
|
}
|