Skip to content

Commit abcd157

Browse files
committed
Fix URL button layout and add URL history
1 parent 8e3c37a commit abcd157

5 files changed

Lines changed: 137 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ naga = { version = "29.0.3", features = ["wgsl-in"] }
5151
glam = "0.32.1"
5252
env_logger = "0.11.10"
5353
ureq = "3.3.0"
54+
directories = "6.0.0"
5455

5556
[build-dependencies]
5657
winres = "0.1.12"

src/engine.rs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,27 +1812,48 @@ impl<'a> VulkanEngine<'a> {
18121812
egui::Window::new("Open Network Stream")
18131813
.collapsible(false)
18141814
.resizable(false)
1815+
.default_width(600.0)
18151816
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
18161817
.show(ctx, |ui| {
18171818
ui.label("Enter Stream URL (e.g. .pls, .m3u, or direct stream link):");
1819+
ui.add_space(4.0);
18181820
let mut url_text = state.url_input_text.clone();
1819-
let text_resp = ui.add_sized([400.0, 30.0], egui::TextEdit::singleline(&mut url_text));
1821+
let text_resp = ui.add(
1822+
egui::TextEdit::singleline(&mut url_text)
1823+
.desired_width(f32::INFINITY)
1824+
.min_size(egui::vec2(0.0, 30.0))
1825+
);
18201826
if text_resp.changed() {
18211827
engine_action = EngineAction::SetUrlInput(url_text.clone());
18221828
}
18231829
ui.add_space(10.0);
18241830
ui.horizontal(|ui| {
1825-
ui.allocate_ui_with_layout(ui.available_size(), egui::Layout::centered_and_justified(egui::Direction::LeftToRight), |ui| {
1826-
if ui.button("Cancel").clicked() {
1827-
engine_action = EngineAction::CloseUrlDialog;
1828-
}
1829-
if ui.button("Open").clicked() || (text_resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
1831+
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
1832+
if ui.add_sized([80.0, 30.0], egui::Button::new("Open")).clicked() || (text_resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
18301833
if !url_text.is_empty() {
18311834
engine_action = EngineAction::LoadUrl(url_text);
18321835
}
18331836
}
1837+
if ui.add_sized([80.0, 30.0], egui::Button::new("Cancel")).clicked() {
1838+
engine_action = EngineAction::CloseUrlDialog;
1839+
}
18341840
});
18351841
});
1842+
1843+
if !state.url_history.is_empty() {
1844+
ui.separator();
1845+
ui.label(egui::RichText::new("Recent Streams:").strong());
1846+
egui::ScrollArea::vertical().max_height(150.0).show(ui, |ui| {
1847+
for (url, title) in &state.url_history {
1848+
if ui.add_sized(
1849+
[ui.available_width(), 30.0],
1850+
egui::Button::new(format!("{} ({})", title, url))
1851+
).clicked() {
1852+
engine_action = EngineAction::LoadUrl(url.clone());
1853+
}
1854+
}
1855+
});
1856+
}
18361857
});
18371858
}
18381859

@@ -2179,15 +2200,13 @@ impl<'a> VulkanEngine<'a> {
21792200
}
21802201

21812202
let mut append = state.append_to_playlist;
2182-
// Only update the file dialog UI when it's actually open to avoid layout overhead
2183-
if state.is_file_picker_open || *file_dialog.state() != egui_file_dialog::DialogState::Closed {
2184-
file_dialog.update_with_right_panel_ui(ctx, &mut |ui, _fd| {
2185-
ui.add_space(10.0);
2186-
ui.heading("Options");
2187-
ui.separator();
2188-
ui.checkbox(&mut append, "Add to Playlist instead of replacing");
2189-
});
2190-
}
2203+
file_dialog.update_with_right_panel_ui(ctx, &mut |ui, _fd| {
2204+
ui.add_space(10.0);
2205+
ui.heading("Options");
2206+
ui.separator();
2207+
ui.checkbox(&mut append, "Add to Playlist instead of replacing");
2208+
});
2209+
21912210
if append != state.append_to_playlist {
21922211
engine_action = EngineAction::SetAppendToPlaylist(append);
21932212
}
@@ -2388,7 +2407,6 @@ impl<'a> VulkanEngine<'a> {
23882407

23892408
egui::Area::new(egui::Id::new("splash_shortcuts_area"))
23902409
.anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -40.0))
2391-
.order(egui::Order::Foreground)
23922410
.show(ctx, |ui| {
23932411
egui::Frame::NONE
23942412
.fill(egui::Color32::from_black_alpha(200))
@@ -2595,13 +2613,12 @@ impl<'a> VulkanEngine<'a> {
25952613
}
25962614
ui.add_space(20.0);
25972615

2598-
if !is_game_mode {
25992616
egui::Frame::NONE
26002617
.shadow(egui::Shadow { offset: [0, 4], blur: 12, spread: 0, color: egui::Color32::from_black_alpha(200) })
26012618
.corner_radius(6.0)
26022619
.show(ui, |ui| {
26032620
ui.horizontal(|ui| {
2604-
let total_width = 300.0 + 20.0 + 250.0;
2621+
let total_width = 300.0 + 20.0 + 300.0;
26052622
ui.add_space((ui.available_width() - total_width) / 2.0);
26062623

26072624
let btn = egui::Button::new(
@@ -2613,7 +2630,11 @@ impl<'a> VulkanEngine<'a> {
26132630
.fill(egui::Color32::from_rgb(0, 100, 200))
26142631
.stroke(egui::Stroke::new(1.0, egui::Color32::from_rgb(80, 180, 255)));
26152632

2616-
if ui.add_sized([300.0, 60.0], btn).clicked() {
2633+
let resp1 = ui.add_sized([300.0, 60.0], btn);
2634+
if resp1.has_focus() {
2635+
ui.painter().rect(resp1.rect.expand(2.0), 6.0, egui::Color32::TRANSPARENT, egui::Stroke::new(3.0, egui::Color32::YELLOW), egui::StrokeKind::Outside);
2636+
}
2637+
if resp1.clicked() {
26172638
engine_action = EngineAction::OpenFile;
26182639
}
26192640

@@ -2628,14 +2649,17 @@ impl<'a> VulkanEngine<'a> {
26282649
.fill(egui::Color32::from_rgb(100, 50, 150))
26292650
.stroke(egui::Stroke::new(1.0, egui::Color32::from_rgb(180, 80, 255)));
26302651

2631-
if ui.add_sized([250.0, 60.0], url_btn).clicked() {
2652+
let resp2 = ui.add_sized([300.0, 60.0], url_btn);
2653+
if resp2.has_focus() {
2654+
ui.painter().rect(resp2.rect.expand(2.0), 6.0, egui::Color32::TRANSPARENT, egui::Stroke::new(3.0, egui::Color32::YELLOW), egui::StrokeKind::Outside);
2655+
}
2656+
if resp2.clicked() {
26322657
engine_action = EngineAction::OpenUrlDialog;
26332658
}
26342659
});
26352660
});
26362661

26372662
ui.add_space(30.0);
2638-
}
26392663

26402664
let mut force_stereo = state.force_stereo_downmix;
26412665
if ui.checkbox(&mut force_stereo, "Force Stereo Downmix (Fixes crackling on some devices)").changed() {

src/main.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ fn main() -> Result<(), Box<dyn Error>> {
104104
state.playlist = args.file.clone();
105105
state.playlist_index = 0;
106106

107+
let mut history_changed = false;
108+
for path in &args.file {
109+
if path.starts_with("http") {
110+
if !state.url_history.iter().any(|(u, _)| u == path) {
111+
state.url_history.push((path.clone(), "Network Stream".to_string()));
112+
history_changed = true;
113+
}
114+
}
115+
}
116+
if history_changed {
117+
let mut out = String::new();
118+
for (u, t) in &state.url_history {
119+
out.push_str(&format!("{}|{}\n", u, t));
120+
}
121+
let _ = std::fs::write(crate::state::get_history_file_path(), out);
122+
}
123+
107124
if let Some(vis) = &args.vis {
108125
let vis_lower = vis.to_lowercase();
109126
if let Some(idx) = crate::state::VISUALIZERS.iter().position(|v| v.filename.to_lowercase().contains(&vis_lower) || v.name.to_lowercase().contains(&vis_lower)) {
@@ -808,8 +825,16 @@ async fn run_gui(app_state: Arc<Mutex<AppState>>, mut active_stream: Option<audi
808825
state.url_input_text.clear();
809826
state.playlist = vec![url.clone()];
810827
state.playlist_index = 0;
811-
state.load_request = Some(url);
828+
state.load_request = Some(url.clone());
812829
state.file_loaded = true;
830+
if !state.url_history.iter().any(|(u, _)| u == &url) {
831+
state.url_history.push((url.clone(), "Network Stream".to_string()));
832+
let mut out = String::new();
833+
for (u, t) in &state.url_history {
834+
out.push_str(&format!("{}|{}\n", u, t));
835+
}
836+
let _ = std::fs::write(crate::state::get_history_file_path(), out);
837+
}
813838
}
814839
EngineAction::None => {}
815840
}
@@ -880,7 +905,10 @@ async fn run_gui(app_state: Arc<Mutex<AppState>>, mut active_stream: Option<audi
880905
}
881906
},
882907
Event::AboutToWait => {
883-
let is_dialog_open = *file_dialog.state() != egui_file_dialog::DialogState::Closed;
908+
let is_dialog_open = *file_dialog.state() != egui_file_dialog::DialogState::Closed || {
909+
let state = app_state.lock().unwrap();
910+
state.is_url_dialog_open
911+
};
884912

885913
{
886914
let mut state = app_state.lock().unwrap();
@@ -973,8 +1001,41 @@ async fn run_gui(app_state: Arc<Mutex<AppState>>, mut active_stream: Option<audi
9731001
gilrs::Button::DPadRight => { push_key(egui::Key::ArrowRight); continue; }
9741002
gilrs::Button::South => { push_key(egui::Key::Enter); continue; }
9751003
gilrs::Button::East => { push_key(egui::Key::Escape); continue; }
1004+
gilrs::Button::RightTrigger => {
1005+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE });
1006+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE });
1007+
continue;
1008+
}
1009+
gilrs::Button::LeftTrigger => {
1010+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::SHIFT });
1011+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::SHIFT });
1012+
continue;
1013+
}
9761014
_ => {}
9771015
}
1016+
} else {
1017+
let is_splash = {
1018+
let state = app_state.lock().unwrap();
1019+
!state.file_loaded
1020+
};
1021+
if is_splash {
1022+
let mut state = app_state.lock().unwrap();
1023+
let mut push_tab = |shift: bool| {
1024+
let modifiers = if shift { egui::Modifiers::SHIFT } else { egui::Modifiers::NONE };
1025+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers });
1026+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Tab, physical_key: None, pressed: false, repeat: false, modifiers });
1027+
};
1028+
match button {
1029+
gilrs::Button::DPadLeft => { push_tab(true); continue; }
1030+
gilrs::Button::DPadRight => { push_tab(false); continue; }
1031+
gilrs::Button::South => {
1032+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE });
1033+
state.egui_gamepad_events.push(egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE });
1034+
continue;
1035+
}
1036+
_ => {}
1037+
}
1038+
}
9781039
}
9791040

9801041
match button {

src/state.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct AppState {
170170
pub open_file_request: bool,
171171
pub is_url_dialog_open: bool,
172172
pub url_input_text: String,
173+
pub url_history: Vec<(String, String)>,
173174
pub egui_gamepad_events: Vec<egui::Event>,
174175
pub force_stereo_downmix: bool,
175176
pub append_to_playlist: bool,
@@ -185,6 +186,18 @@ pub struct AppState {
185186
pub cumulative_scrub: f64,
186187
}
187188

189+
pub fn get_history_file_path() -> std::path::PathBuf {
190+
if let Some(proj_dirs) = directories::ProjectDirs::from("com", "RustTracker", "RustTracker") {
191+
let dir = proj_dirs.data_dir();
192+
if !dir.exists() {
193+
let _ = std::fs::create_dir_all(dir);
194+
}
195+
dir.join("url_history.txt")
196+
} else {
197+
std::path::PathBuf::from("url_history.txt")
198+
}
199+
}
200+
188201
impl AppState {
189202
pub fn new(title: String) -> Self {
190203
let mut history = VecDeque::new();
@@ -212,6 +225,17 @@ impl AppState {
212225
vis_enabled[9] = false; // Ferrofluid Particle Sim
213226
vis_enabled[10] = false; // Neon Corridor
214227
}
228+
229+
let mut url_history = Vec::new();
230+
if let Ok(data) = std::fs::read_to_string(get_history_file_path()) {
231+
for line in data.lines() {
232+
if let Some((url, title)) = line.split_once('|') {
233+
if !url_history.iter().any(|(u, _)| u == url) {
234+
url_history.push((url.to_string(), title.to_string()));
235+
}
236+
}
237+
}
238+
}
215239

216240
AppState {
217241
passthrough_enabled: true,
@@ -273,6 +297,7 @@ impl AppState {
273297
open_file_request: false,
274298
is_url_dialog_open: false,
275299
url_input_text: String::new(),
300+
url_history,
276301
egui_gamepad_events: Vec::new(),
277302
force_stereo_downmix: is_steam_deck,
278303
append_to_playlist: false,
@@ -358,6 +383,7 @@ impl AppState {
358383
open_file_request: false,
359384
is_url_dialog_open: self.is_url_dialog_open,
360385
url_input_text: self.url_input_text.clone(),
386+
url_history: self.url_history.clone(),
361387
egui_gamepad_events: Vec::new(),
362388
force_stereo_downmix: self.force_stereo_downmix,
363389
append_to_playlist: self.append_to_playlist,

0 commit comments

Comments
 (0)