Skip to content

Commit

Permalink
Display file name in main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Dec 16, 2023
1 parent 94f2ec2 commit 7765565
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions midi-file/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{fs, path::Path, sync::Arc};

#[derive(Debug, Clone)]
pub struct MidiFile {
pub name: String,
pub format: Format,
pub tracks: Arc<[MidiTrack]>,
pub program_track: ProgramTrack,
Expand All @@ -12,6 +13,13 @@ pub struct MidiFile {

impl MidiFile {
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, String> {
let name = path
.as_ref()
.file_name()
.ok_or(String::from("File not found"))?
.to_string_lossy()
.to_string();

let data = match fs::read(path) {
Ok(buff) => buff,
Err(_) => return Err(String::from("Could Not Open File")),
Expand Down Expand Up @@ -54,6 +62,7 @@ impl MidiFile {
let program_track = ProgramTrack::new(&tracks);

Ok(Self {
name,
format: smf.header.format,
tracks: tracks.into(),
program_track,
Expand Down
13 changes: 11 additions & 2 deletions neothesia/src/scene/menu_scene/iced_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<'a> Step {

let mut layout = Layout::new().body(top_padded(column));

if target.song.is_some() {
if let Some(song) = target.song.as_ref() {
let tracks = NeoBtn::new(
icons::note_list_icon()
.size(30.0)
Expand Down Expand Up @@ -293,7 +293,16 @@ impl<'a> Step {
left: 0.0,
});

layout = layout.bottom(BarLayout::new().right(container));
layout = layout.bottom(
BarLayout::new()
.center(
text(&song.file.name)
.width(Length::Fill)
.vertical_alignment(Vertical::Center)
.horizontal_alignment(Horizontal::Center),
)
.right(container),
);
}

layout.into()
Expand Down

0 comments on commit 7765565

Please sign in to comment.