Skip to content

Commit e6c16e2

Browse files
committed
fixes #87, showing bar number on each bar
1 parent f13eb1b commit e6c16e2

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

crates/notation_bevy/src/bar/bar_plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ impl Plugin for BarPlugin {
1212
BarViewDoLayoutEvent::setup(app);
1313
app.add_system_set(
1414
SystemSet::on_update(NotationAssetsStates::Loaded)
15-
.with_system(BarView::do_layout.system()),
15+
.with_system(BarView::do_layout.system())
16+
.with_system(BarView::update_number_text.system())
1617
);
1718
}
1819
}

crates/notation_bevy/src/bar/bar_view.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ impl BarView {
7171
}
7272
}
7373
}
74+
pub fn update_number_text(
75+
theme: Res<NotationTheme>,
76+
settings: Res<NotationSettings>,
77+
mut evts: EventReader<BarViewDoLayoutEvent>,
78+
mut text_query: Query<(&Parent, &mut Transform), With<Text>>,
79+
) {
80+
if !settings.hide_bar_number {
81+
for evt in evts.iter() {
82+
for (parent, mut transform) in text_query.iter_mut() {
83+
if parent.0 == evt.entity {
84+
theme.texts.tab.update_bar_number_x(&mut transform, evt.layout.size.width);
85+
}
86+
}
87+
}
88+
}
89+
}
7490
pub fn spawn(
7591
commands: &mut Commands,
7692
assets: &NotationAssets,
@@ -113,6 +129,12 @@ impl BarView {
113129
let data = BarBeatData::new(bar, BarBeatValue::new(bar, &signature, beat));
114130
data.create(commands, theme, bar_entity);
115131
}
132+
if !settings.hide_bar_number {
133+
theme
134+
.texts
135+
.tab
136+
.spawn_bar_number(commands, assets, bar_entity, &bar.props.bar_ordinal.to_string());
137+
}
116138
bar_entity
117139
}
118140
}

crates/notation_bevy/src/mini/mini_bar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl MiniBar {
112112
section_separator_data.create(commands, theme, bar_entity);
113113
theme.texts.mini_map.spawn_bar_text(
114114
commands,
115-
shape_entity,
116115
assets,
116+
shape_entity,
117117
bar.props.bar_ordinal.to_string().as_str(),
118118
);
119119
}

crates/notation_bevy/src/rhythm/rhythm_bar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl RhythmBarData {
102102
theme
103103
.texts
104104
.rhythm
105-
.spawn_bar_text(commands, bar_entity, assets, "0");
105+
.spawn_bar_text(commands, assets, bar_entity, "0");
106106
bar_entity
107107
}
108108
pub fn update_rhythm(

crates/notation_bevy/src/settings/notation_settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct NotationSettings {
1111
pub layout: LayoutSettings,
1212
pub should_loop: bool,
1313
pub speed_factor: f32,
14+
pub hide_bar_number: bool,
1415
pub always_show_fret: bool,
1516
pub melody_piano_mode: bool,
1617
pub mouse_dragged_panning: bool,
@@ -22,6 +23,7 @@ impl Default for NotationSettings {
2223
layout: LayoutSettings::default(),
2324
should_loop: false,
2425
speed_factor: 1.0,
26+
hide_bar_number: false,
2527
always_show_fret: false,
2628
melody_piano_mode: false,
2729
mouse_dragged_panning: false,

crates/notation_bevy/src/theme/theme_texts.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,57 @@ use crate::prelude::{NotationAssets, ThemeColors};
1111
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, Debug, Default)]
1212
#[cfg_attr(feature = "inspector", derive(Inspectable))]
1313
pub struct ThemeTexts {
14+
pub tab: TabTexts,
1415
pub rhythm: RhythmTexts,
1516
pub mini_map: MiniMapTexts,
1617
}
1718

19+
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, Debug)]
20+
#[cfg_attr(feature = "inspector", derive(Inspectable))]
21+
pub struct TabTexts {
22+
pub bar_font_size: f32,
23+
pub bar_font_color: Color,
24+
pub bar_x: f32,
25+
pub bar_y: f32,
26+
}
27+
impl Default for TabTexts {
28+
fn default() -> Self {
29+
Self {
30+
bar_font_size: 18.0,
31+
bar_font_color: ThemeColors::hex_linear("00000066"),
32+
bar_x: -6.0,
33+
bar_y: -6.0,
34+
}
35+
}
36+
}
37+
impl TabTexts {
38+
pub fn spawn_bar_number(
39+
&self,
40+
commands: &mut Commands,
41+
assets: &NotationAssets,
42+
entity: Entity,
43+
text: &str,
44+
) {
45+
//NOTE: not sure why, using HorizontalAlign::Right here got the left behaviour
46+
BevyUtil::spawn_text(
47+
commands,
48+
entity,
49+
text,
50+
assets.en_font.clone(),
51+
self.bar_font_size,
52+
self.bar_font_color,
53+
HorizontalAlign::Left,
54+
VerticalAlign::Center,
55+
self.bar_x,
56+
self.bar_y,
57+
3.0,
58+
);
59+
}
60+
pub fn update_bar_number_x(&self, transform: &mut Transform, bar_width: f32) {
61+
transform.translation.x = bar_width + self.bar_x;
62+
}
63+
}
64+
1865
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, Debug)]
1966
#[cfg_attr(feature = "inspector", derive(Inspectable))]
2067
pub struct RhythmTexts {
@@ -35,8 +82,8 @@ impl RhythmTexts {
3582
pub fn spawn_bar_text(
3683
&self,
3784
commands: &mut Commands,
38-
entity: Entity,
3985
assets: &NotationAssets,
86+
entity: Entity,
4087
text: &str,
4188
) {
4289
//NOTE: not sure why, using HorizontalAlign::Right here got the left behaviour
@@ -74,8 +121,8 @@ impl MiniMapTexts {
74121
pub fn spawn_bar_text(
75122
&self,
76123
commands: &mut Commands,
77-
entity: Entity,
78124
assets: &NotationAssets,
125+
entity: Entity,
79126
text: &str,
80127
) {
81128
//NOTE: not sure why, using HorizontalAlign::Right here got the left behaviour

crates/notation_bevy/src/viewer/control.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ impl ControlView {
269269
&mut play_control_evts,
270270
)
271271
}
272+
let hide_bar_number = settings.hide_bar_number;
273+
ui.checkbox(&mut settings.hide_bar_number, "Hide Bar Number");
274+
if hide_bar_number != settings.hide_bar_number {
275+
Self::reload_tab(&mut commands, &mut state, &viewer_query);
276+
}
272277
if ui.button(format!("Begin: {}", midi_state.play_control.begin_bar_ordinal)).clicked() {
273278
Self::set_begin_bar_ordinal(&mut midi_state, &mut play_control_evts);
274279
}

0 commit comments

Comments
 (0)