Skip to content

Commit 37a3be8

Browse files
authored
freeplay(recorder): Start the cleanup process of the UI of the recorder panel (#399)
1 parent b4aabf7 commit 37a3be8

3 files changed

Lines changed: 77 additions & 68 deletions

File tree

neothesia/src/icons.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ pub fn note_list_icon() -> &'static str {
4747
pub fn caret_down() -> &'static str {
4848
"\u{f229}"
4949
}
50+
51+
pub fn record_icon() -> &'static str {
52+
"\u{f519}"
53+
}
54+
55+
pub fn record_stop_icon() -> &'static str {
56+
"\u{f591}"
57+
}
58+
59+
pub fn save_icon() -> &'static str {
60+
"\u{f7D9}"
61+
}

neothesia/src/scene/freeplay/mod.rs

Lines changed: 56 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ impl FreeplayScene {
200200

201201
/// Recorder related methods
202202
impl FreeplayScene {
203-
fn preview_bar_button() -> nuon::Button {
204-
nuon::button().size(30.0, 30.0).border_radius([5.0; 4])
205-
}
206-
207203
fn clear_preview(&mut self) {
208204
self.preview_state = None;
209205
self.keyboard.set_song_config(Default::default());
@@ -324,14 +320,6 @@ impl FreeplayScene {
324320
self.recorder_status.clone()
325321
}
326322

327-
fn record_button_label(&self) -> &'static str {
328-
if self.recorder.is_recording() {
329-
"STOP"
330-
} else {
331-
"REC"
332-
}
333-
}
334-
335323
fn stop_recording(&mut self, ctx: &Context) -> Result<(), String> {
336324
self.recorder.stop();
337325
self.rebuild_preview(ctx)
@@ -429,7 +417,6 @@ impl FreeplayScene {
429417
let width = ctx.window_state.logical_size.width;
430418
let preview = self.preview_ui_state();
431419

432-
let record_label = self.record_button_label();
433420
let status_label = self.preview_status_label();
434421

435422
enum Msg {
@@ -453,7 +440,9 @@ impl FreeplayScene {
453440
.color([37, 35, 42])
454441
.build(ui);
455442

456-
if Self::preview_bar_button()
443+
if nuon::button()
444+
.size(30.0, 30.0)
445+
.border_radius([5.0; 4])
457446
.icon(icons::left_arrow_icon())
458447
.build(ui)
459448
{
@@ -480,65 +469,68 @@ impl FreeplayScene {
480469
.build(ui);
481470

482471
nuon::translate().x(width).build(ui, |ui| {
483-
if preview.available {
484-
if Self::preview_bar_button()
485-
.x(-30.0)
486-
.icon(if preview.is_paused {
487-
icons::play_icon()
488-
} else {
489-
icons::pause_icon()
490-
})
491-
.build(ui)
492-
{
493-
msg = Msg::TogglePlay;
494-
}
495-
} else {
496-
nuon::quad()
497-
.x(-30.0)
498-
.size(30.0, 30.0)
499-
.color([52, 52, 52])
500-
.border_radius([5.0; 4])
501-
.build(ui);
502-
nuon::label()
503-
.x(-30.0)
504-
.size(30.0, 30.0)
505-
.icon(icons::play_icon())
506-
.color([140, 140, 140])
507-
.build(ui);
472+
nuon::translate().x(-30.0).add_to_current(ui);
473+
474+
if nuon::button()
475+
.size(30.0, 30.0)
476+
.border_radius([5.0; 4])
477+
.icon(if preview.is_paused {
478+
icons::play_icon()
479+
} else {
480+
icons::pause_icon()
481+
})
482+
.font_color(if preview.available {
483+
[255, 255, 255, 255]
484+
} else {
485+
[255, 255, 255, 100]
486+
})
487+
.build(ui)
488+
&& preview.available
489+
{
490+
msg = Msg::TogglePlay;
508491
}
509492

493+
nuon::translate().x(-30.0).add_to_current(ui);
494+
510495
if nuon::button()
511-
.x(-85.0)
512-
.size(45.0, 30.0)
496+
.size(30.0, 30.0)
513497
.border_radius([5.0; 4])
514-
.color([67, 67, 67])
515-
.hover_color([87, 87, 87])
516-
.preseed_color([97, 97, 97])
517-
.label("SAVE")
498+
.icon(icons::save_icon())
499+
.font_color(if preview.available {
500+
[255, 255, 255, 255]
501+
} else {
502+
[255, 255, 255, 100]
503+
})
518504
.build(ui)
505+
&& preview.available
519506
{
520507
msg = Msg::Save;
521508
}
522509

510+
nuon::translate().x(-30.0).add_to_current(ui);
511+
523512
if nuon::button()
524-
.x(-147.0)
525-
.size(52.0, 30.0)
513+
.size(30.0, 30.0)
526514
.border_radius([5.0; 4])
527-
.label(record_label)
515+
.icon(if self.recorder.is_recording() {
516+
icons::record_stop_icon()
517+
} else {
518+
icons::record_icon()
519+
})
528520
.color(if self.recorder.is_recording() {
529-
[125, 27, 27]
521+
[208, 18, 0, 255]
530522
} else {
531-
[67, 67, 67]
523+
[0, 0, 0, 0]
532524
})
533525
.hover_color(if self.recorder.is_recording() {
534-
[145, 37, 37]
526+
[165, 47, 47]
535527
} else {
536-
[87, 87, 87]
528+
[97, 97, 97]
537529
})
538530
.preseed_color(if self.recorder.is_recording() {
539-
[165, 47, 47]
531+
[145, 37, 37]
540532
} else {
541-
[97, 97, 97]
533+
[87, 87, 87]
542534
})
543535
.build(ui)
544536
{
@@ -566,13 +558,15 @@ impl FreeplayScene {
566558
if preview.length > 0.0 {
567559
for measure in preview.measures.iter() {
568560
let x = (measure.as_secs_f32() / preview.length) * width;
569-
let color = if x < width * preview.progress {
570-
nuon::Color::new(1.0, 1.0, 1.0, 0.5)
571-
} else {
572-
nuon::Color::new(0.4, 0.4, 0.4, 1.0)
573-
};
574-
575-
nuon::quad().x(x).size(1.0, 45.0).color(color).build(ui);
561+
nuon::quad()
562+
.x(x)
563+
.size(1.0, 45.0)
564+
.color(if x < width * preview.progress {
565+
[255, 255, 255, 127]
566+
} else {
567+
[102, 102, 102, 255]
568+
})
569+
.build(ui);
576570
}
577571
}
578572

@@ -582,11 +576,7 @@ impl FreeplayScene {
582576
.size((width - 20.0).max(0.0), 15.0)
583577
.text(&status_label)
584578
.text_justify(nuon::TextJustify::Left)
585-
.color(if preview.available {
586-
[210, 210, 210]
587-
} else {
588-
[170, 170, 170]
589-
})
579+
.color([255, 255, 255, 200])
590580
.build(ui);
591581
});
592582
});

nuon/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ pub struct Button {
961961
color: Color,
962962
hover_color: Color,
963963
preseed_color: Color,
964+
font_color: Color,
964965
border_radius: [f32; 4],
965966
icon: &'static str,
966967
label: Cow<'static, str>,
@@ -986,6 +987,7 @@ impl Button {
986987
color: Color::new_u8(0, 0, 0, 0.0),
987988
hover_color: Color::new_u8(57, 55, 62, 1.0),
988989
preseed_color: Color::new_u8(67, 65, 72, 1.0),
990+
font_color: Color::WHITE,
989991
border_radius: [0.0; 4],
990992
icon: "X",
991993
label: Cow::Borrowed(""),
@@ -1043,6 +1045,11 @@ impl Button {
10431045
self
10441046
}
10451047

1048+
pub fn font_color(mut self, color: impl Into<Color>) -> Self {
1049+
self.font_color = color.into();
1050+
self
1051+
}
1052+
10461053
pub fn border_radius(mut self, border_radius: [f32; 4]) -> Self {
10471054
self.border_radius = border_radius;
10481055
self
@@ -1122,7 +1129,7 @@ impl Button {
11221129
origin: Point::new(x, y),
11231130
size: icon_size,
11241131
icon: self.icon.to_string(),
1125-
color: Color::WHITE,
1132+
color: self.font_color,
11261133
});
11271134
} else {
11281135
let pad_x = pad_x * 10.0;
@@ -1136,7 +1143,7 @@ impl Button {
11361143
size: 16.0,
11371144
bold: false,
11381145
text: self.label.to_string(),
1139-
color: Color::new_u8(255, 255, 255, 1.0),
1146+
color: self.font_color,
11401147
font_family: Cow::Borrowed("Roboto"),
11411148
});
11421149
}

0 commit comments

Comments
 (0)