Skip to content

Commit f26560e

Browse files
committed
some bugfix with layout mode, and preset settings
1 parent 0b52f09 commit f26560e

File tree

7 files changed

+91
-34
lines changed

7 files changed

+91
-34
lines changed

crates/notation_bevy/src/lane/lane_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl LaneView {
106106
if !settings.hide_harmony_lane {
107107
HarmonyPlugin::insert_lane_extra(&mut commands.entity(lane_entity), lane)
108108
}
109-
!settings.hide_melody_lane
109+
!settings.hide_harmony_lane
110110
}
111111
LaneKind::Strings => {
112112
if !settings.hide_strings_lane {

crates/notation_bevy/src/notation/control.rs

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ use super::events::WindowResizedEvent;
99
pub struct Control();
1010

1111
impl Control {
12+
pub const PRESET_GUITAR_TAB: &'static str = "guitar_tab";
13+
pub const PRESET_GUITAR_NOTES: &'static str = "guitar_notes";
1214
pub const PRESET_GUITAR_STRINGS: &'static str = "guitar_strings";
1315
pub const PRESET_MELODY: &'static str = "melody";
14-
pub const ALL_PRESETS: [&'static str ; 2 ] = [
16+
pub const ALL_PRESETS: [&'static str ; 4 ] = [
17+
Self::PRESET_GUITAR_TAB,
18+
Self::PRESET_GUITAR_NOTES,
1519
Self::PRESET_GUITAR_STRINGS,
1620
Self::PRESET_MELODY,
1721
];
@@ -102,6 +106,45 @@ impl Control {
102106
Self::set_window_size(window, width, height);
103107
}
104108
}
109+
fn set_preset_strings(
110+
settings: &mut NotationSettings,
111+
theme: &mut NotationTheme,
112+
always_show_fret: bool,
113+
) {
114+
settings.hide_strings_lane = false;
115+
settings.always_show_fret = always_show_fret;
116+
theme.sizes.layout.page_margin = 24.0;
117+
theme.sizes.strings.string_space = 20.0;
118+
theme.sizes.strings.note_height = 9.0;
119+
theme.texts.strings.text_y = -4.0;
120+
theme.texts.strings.fret_font_size = 20.0;
121+
}
122+
fn set_preset_harmony(
123+
settings: &mut NotationSettings,
124+
theme: &mut NotationTheme,
125+
) {
126+
settings.hide_harmony_lane = false;
127+
theme.sizes.layout.page_margin = 24.0;
128+
theme.sizes.harmony.note_height = 6.0;
129+
theme.sizes.harmony.semitone_height = 6.0;
130+
theme.texts.harmony.text_y = 9.0;
131+
theme.texts.harmony.syllable_font_size = 20.0;
132+
}
133+
fn set_preset_melody(
134+
settings: &mut NotationSettings,
135+
theme: &mut NotationTheme,
136+
show_melody_pitch: bool,
137+
) {
138+
settings.hide_melody_lane = false;
139+
settings.show_melody_pitch = show_melody_pitch;
140+
settings.show_melody_syllable = true;
141+
settings.show_syllable_as_num = true;
142+
theme.sizes.layout.page_margin = 24.0;
143+
theme.sizes.melody.note_height = 9.0;
144+
theme.sizes.melody.semitone_height = 9.0;
145+
theme.texts.melody.text_y = -18.0;
146+
theme.texts.melody.syllable_font_size = 20.0;
147+
}
105148
pub fn set_preset(
106149
state: &mut NotationState,
107150
settings: &mut NotationSettings,
@@ -115,27 +158,23 @@ impl Control {
115158
#[cfg(not(target_arch = "wasm32"))]
116159
Self::set_primary_window_size(windows, 1080, 1920);
117160
match preset {
161+
Self::PRESET_GUITAR_TAB => {
162+
settings.hack_for_screenshot();
163+
Self::set_preset_strings(settings, theme, true);
164+
Self::set_preset_harmony(settings, theme);
165+
settings.hide_shapes_lane = false;
166+
},
167+
Self::PRESET_GUITAR_NOTES => {
168+
settings.hack_for_screenshot();
169+
Self::set_preset_harmony(settings, theme);
170+
},
118171
Self::PRESET_GUITAR_STRINGS => {
119172
settings.hack_for_screenshot();
120-
settings.hide_strings_lane = false;
121-
settings.always_show_fret = true;
122-
theme.sizes.layout.page_margin = 24.0;
123-
theme.sizes.strings.string_space = 20.0;
124-
theme.sizes.strings.note_height = 9.0;
125-
theme.texts.strings.fret_font_size = 20.0;
126-
theme.texts.strings.text_y = 8.0;
173+
Self::set_preset_strings(settings, theme, true);
127174
},
128175
Self::PRESET_MELODY => {
129176
settings.hack_for_screenshot();
130-
settings.hide_melody_lane = false;
131-
settings.show_melody_pitch = true;
132-
settings.show_melody_syllable = true;
133-
settings.show_syllable_as_num = true;
134-
theme.sizes.layout.page_margin = 24.0;
135-
theme.sizes.melody.note_height = 9.0;
136-
theme.sizes.melody.semitone_height = 9.0;
137-
theme.texts.melody.text_y = -18.0;
138-
theme.texts.melody.syllable_font_size = 20.0;
177+
Self::set_preset_melody(settings, theme, true);
139178
},
140179
_ => {
141180
println!("Control::set_preset() Invalid Preset: {}", preset);

crates/notation_bevy/src/notation/control_panel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ impl ControlPanel {
161161
CollapsingHeader::new("Display Options")
162162
.default_open(true)
163163
.show(ui, |ui| {
164+
let mut hide_harmony_lane = settings.hide_harmony_lane;
165+
ui.checkbox(&mut hide_harmony_lane, "Hide Guitar Notes");
166+
if settings.hide_harmony_lane != hide_harmony_lane {
167+
settings.hide_harmony_lane = hide_harmony_lane;
168+
Control::reload_tab(state, theme);
169+
}
164170
let mut hide_shapes_lane = settings.hide_shapes_lane;
165171
ui.checkbox(&mut hide_shapes_lane, "Hide Guitar Chords");
166172
if settings.hide_shapes_lane != hide_shapes_lane {
@@ -173,12 +179,6 @@ impl ControlPanel {
173179
settings.hide_strings_lane = hide_strings_lane;
174180
Control::reload_tab(state, theme);
175181
}
176-
let mut hide_harmony_lane = settings.hide_harmony_lane;
177-
ui.checkbox(&mut hide_harmony_lane, "Hide Guitar Notes");
178-
if settings.hide_harmony_lane != hide_harmony_lane {
179-
settings.hide_harmony_lane = hide_harmony_lane;
180-
Control::reload_tab(state, theme);
181-
}
182182
let mut hide_lyrics_lane = settings.hide_lyrics_lane;
183183
ui.checkbox(&mut hide_lyrics_lane, "Hide Lyrics ");
184184
if settings.hide_lyrics_lane != hide_lyrics_lane {

crates/notation_bevy/src/play/play_plugin.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ fn update_indicators(
8181
bar_playing: &BarPlaying,
8282
bar_layout: LayoutData,
8383
) {
84-
if settings.hide_indicators {
85-
return;
86-
}
8784
let bar_props = bar_playing.bar_props;
8885
let mut in_bar_pos = None;
8986
for (entity, mut data) in pos_indicator_query.iter_mut() {
87+
data.hidden = settings.hide_indicators;
9088
data.bar_props = bar_props;
9189
data.bar_layout = bar_layout;
9290
data.update(commands, &theme, entity);
@@ -95,6 +93,9 @@ fn update_indicators(
9593
.focus_bar(commands, theme, tab_bars_query, &data);
9694
in_bar_pos = Some(data.bar_position.in_bar_pos);
9795
}
96+
if settings.hide_indicators {
97+
return;
98+
}
9899
for (entity, mut data) in bar_indicator_query.iter_mut() {
99100
data.bar_props = bar_props;
100101
data.bar_layout = bar_layout;

crates/notation_bevy/src/play/pos_indicator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::prelude::NotationTheme;
77

88
#[derive(Clone, Debug, Component)]
99
pub struct PosIndicatorData {
10+
pub hidden: bool,
1011
pub bar_props: TabBarProps,
1112
pub bar_layout: LayoutData,
1213
pub bar_units: Units,
@@ -16,6 +17,7 @@ pub struct PosIndicatorData {
1617
impl PosIndicatorData {
1718
pub fn new(bar_units: Units) -> Self {
1819
PosIndicatorData {
20+
hidden: false,
1921
bar_props: TabBarProps::default(),
2022
bar_layout: LayoutData::ZERO,
2123
bar_units,
@@ -36,7 +38,11 @@ impl ShapeOp<NotationTheme, OutlineRectangle> for PosIndicatorData {
3638
fn get_shape(&self, theme: &NotationTheme) -> OutlineRectangle {
3739
let width = theme.sizes.bar.pos_indicator_size;
3840
let height = self.bar_layout.size.height + theme.sizes.bar.bar_separator_extra * 2.0;
39-
let color = theme.colors.of_section(self.bar_props.section_ordinal);
41+
let color = if self.hidden {
42+
crate::theme::theme_colors::hex_linear("00000000")
43+
} else {
44+
theme.colors.of_section(self.bar_props.section_ordinal)
45+
};
4046
let outline_color = theme.colors.bar.pos_indicator_color;
4147
let outline_width = theme.sizes.bar.pos_indicator_outline;
4248
let offset = if self.bar_layout.size.width <= 0.0 {

crates/notation_bevy/src/settings/layout_settings.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,21 @@ impl LayoutSettings {
176176
let grid_size = layout.size;
177177
let content_size = grid_data.content_size;
178178
if self.video_recording_mode || self.grid_align_mode == GridAlignMode::ForceTop {
179-
y += self.override_focus_offset_y.unwrap_or(0.0);
179+
match self.override_focus_offset_y {
180+
Some(offset_y) => {
181+
y += offset_y;
182+
},
183+
None => {
184+
if grid_size.height > content_size.height {
185+
y += (content_size.height - grid_size.height) / 2.0;
186+
}
187+
}
188+
}
180189
} else {
181190
if grid_size.height > content_size.height {
182-
y = -(grid_size.height - content_size.height);
191+
if self.grid_align_mode != GridAlignMode::ForceCenter {
192+
y = -(grid_size.height - content_size.height);
193+
}
183194
} else {
184195
/* try to show as 2nd row
185196
let last_row_height = grid_data.calc_cell_size(row - 1, col).height;
@@ -196,9 +207,7 @@ impl LayoutSettings {
196207
/ 2.0
197208
+ self.override_focus_offset_y.unwrap_or(0.0);
198209
}
199-
if self.grid_align_mode != GridAlignMode::ForceCenter
200-
&& self.grid_align_mode != GridAlignMode::ForceTop
201-
{
210+
if self.grid_align_mode != GridAlignMode::ForceCenter {
202211
let min_y = grid_size.height
203212
- content_size.height
204213
- theme.sizes.layout.page_margin * 2.0;

crates/notation_bevy/src/settings/notation_settings.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use super::layout_settings::LayoutSettings;
3+
use super::layout_settings::{LayoutSettings, LayoutMode, GridAlignMode};
44

55
#[derive(Clone, Serialize, Deserialize, Debug)]
66
pub struct NotationSettings {
@@ -77,6 +77,8 @@ impl NotationSettings {
7777
self.hide_melody_lane = true;
7878
}
7979
pub fn hack_for_screenshot(&mut self) {
80+
self.layout.mode = LayoutMode::Grid;
81+
self.layout.grid_align_mode = GridAlignMode::ForceTop;
8082
self.add_ready_section = false;
8183
self.hide_indicators = true;
8284
self.hide_guitar_view = true;

0 commit comments

Comments
 (0)