Added gauge like UI for R2/L2 triggers for finer details

master
Wynd 2025-01-05 00:10:50 +02:00
parent 845a88a360
commit 8bfe46acb3
4 changed files with 57 additions and 6 deletions

2
Cargo.lock generated
View File

@ -229,7 +229,7 @@ checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
[[package]]
name = "gamo"
version = "1.0.0"
version = "1.1.0"
dependencies = [
"color-eyre",
"gilrs",

View File

@ -1,7 +1,12 @@
[package]
name = "gamo"
version = "1.0.0"
version = "1.1.0"
edition = "2021"
authors = ["Wynd <wyndftw@proton.me>"]
description = "TUI gamepad tester"
readme = "README.md"
repository = "https://git.pixelatedw.xyz/wynd/gamo"
license = "GPL-3.0-or-later"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -10,4 +10,7 @@ there's nothing particularly fancy about this and it does what it says, allows t
## controls
use `v` to start a weak vibrations test and `V` (uppercase) for a strong vibration test if your gamepad supports them.
`v` to start a weak vibrations test
`V` (uppercase) for a strong vibration test
`r` to start a gamepad scan if none are automatically found
`q` or `ESC` are used to quit the app

View File

@ -7,9 +7,10 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Style, Stylize},
symbols::Marker,
text::Span,
widgets::{
canvas::{Canvas, Rectangle, Shape},
Block, BorderType, Widget,
BarChart, Block, BorderType, Gauge, Widget,
},
DefaultTerminal,
};
@ -169,10 +170,26 @@ impl App {
}
fn render_trigger_buttons(&self, area: Rect, buf: &mut Buffer) {
let right_trigger_value = match self.manager.active_gamepad() {
Ok(gp) => match gp.button_data(gilrs::Button::RightTrigger2) {
Some(val) => val.value(),
None => 0.0,
},
Err(_) => 0.0,
};
let left_trigger_value = match self.manager.active_gamepad() {
Ok(gp) => match gp.button_data(gilrs::Button::LeftTrigger2) {
Some(val) => val.value(),
None => 0.0,
},
Err(_) => 0.0,
};
let r1_button = self.create_button_ui(gilrs::Button::RightTrigger, "R1");
let r2_button = self.create_button_ui(gilrs::Button::RightTrigger2, "R2");
let r2_button = self.create_gauge_button_ui(gilrs::Button::RightTrigger2, "R2");
let l1_button = self.create_button_ui(gilrs::Button::LeftTrigger, "L1");
let l2_button = self.create_button_ui(gilrs::Button::LeftTrigger2, "L2");
let l2_button = self.create_gauge_button_ui(gilrs::Button::LeftTrigger2, "L2");
let layers = Layout::horizontal([
Fill(2),
@ -246,6 +263,32 @@ impl App {
.style(Style::default().bg(color))
}
fn create_gauge_button_ui(&self, btn: gilrs::Button, title: &'static str) -> Gauge {
let value = match self.manager.active_gamepad() {
Ok(gamepad) => match gamepad.button_data(btn) {
Some(val) => val.value(),
None => 0.0,
},
Err(_) => 0.0,
};
let value = value.clamp(0.0, 1.0);
let color = match value {
x if x > 0.0 => Color::Green,
_ => Color::DarkGray,
};
let value_label = Span::default().content(format!("{:.1}", value * 100.0));
let empty_label = Span::default().content("");
Gauge::default()
.block(Block::bordered().title_top(title).title_bottom(value_label))
.gauge_style(Style::default().fg(color))
.label(empty_label)
.use_unicode(true)
.ratio(value.into())
}
fn create_joystick_ui(&self, axis_x: gilrs::Axis, axis_y: gilrs::Axis) -> impl Widget + '_ {
let (x, y) = match self.manager.active_gamepad() {
Ok(gp) => {