Skip to content

Commit 4bf76e7

Browse files
committed
fixes #146, check egui for input handling, refs #145, add empty kb page for guitar
1 parent 747e85e commit 4bf76e7

File tree

8 files changed

+52
-16
lines changed

8 files changed

+52
-16
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

apps/notation_kb/src/assets.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub struct NotationKnowledgeBaseAssets {
1111

1212
#[asset(path = "kb/scale.md")]
1313
pub kb_scale: Handle<MarkDownAsset>,
14+
15+
#[asset(path = "kb/guitar.md")]
16+
pub kb_guitar: Handle<MarkDownAsset>,
1417
}
1518

1619
impl ExtraAssets for NotationKnowledgeBaseAssets {
@@ -19,6 +22,7 @@ impl ExtraAssets for NotationKnowledgeBaseAssets {
1922
self.kb_welcome.clone_untyped(),
2023
self.kb_sound.clone_untyped(),
2124
self.kb_scale.clone_untyped(),
25+
self.kb_guitar.clone_untyped(),
2226
]
2327
}
2428
fn get_latin_font() -> &'static str {

apps/notation_kb/src/guitar/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod fretboard;
1+
pub mod page;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use notation_bevy::kb::markdown_page::MarkDownPage;
88
use notation_bevy::prelude::{NotationState, NotationAssets, NotationTheme, MarkDownAsset, KbPage, KbContent, EasyLinkEvent, BevyUtil, Syllable};
99

1010
#[derive(Copy, Clone, Debug)]
11-
pub struct FretboardPage {
11+
pub struct GuitarPage {
1212
pub path: &'static str,
1313
}
1414

15-
impl KbPage for FretboardPage {
15+
impl KbPage for GuitarPage {
1616
fn page_ui(
1717
&mut self,
1818
ui: &mut Ui,
@@ -26,7 +26,7 @@ impl KbPage for FretboardPage {
2626
}
2727
}
2828

29-
impl KbContent for FretboardPage {
29+
impl KbContent for GuitarPage {
3030
fn content_ui(
3131
&mut self,
3232
ui: &mut Ui,
@@ -40,7 +40,7 @@ impl KbContent for FretboardPage {
4040
}
4141
}
4242

43-
impl FretboardPage {
43+
impl GuitarPage {
4444
pub fn new(path: &'static str) -> Self {
4545
Self {
4646
path,

apps/notation_kb/src/index_panel.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use notation_bevy::prelude::{MarkDownAsset, KbPageId, KbPage, KbContent, KbPanel
66
use notation_bevy::prelude::{NotationState, NotationAssets, NotationTheme};
77

88
use notation_bevy::kb::markdown_page::MarkDownPage;
9+
use notation_bevy::tab::tab_control::TabControl;
910

11+
use crate::guitar::page::GuitarPage;
1012
use crate::theory::scale::ScalePage;
1113
use crate::theory::sound::{SoundPage, SoundSection};
1214

@@ -17,6 +19,7 @@ pub struct IndexPanel {
1719
pub welcome: MarkDownPage,
1820
pub sound: SoundPage,
1921
pub scale: ScalePage,
22+
pub guitar: GuitarPage,
2023
}
2124

2225
impl Default for IndexPanel {
@@ -29,6 +32,7 @@ Caused by:
2932
In CommandEncoder::copy_buffer_to_texture
3033
Copy error
3134
copy of Y 0..256 would end up overruning the bounds of the Destination texture of Y size 128
35+
TODO: Check whether still needed after upgrade bevy and bevy_egui
3236
*/
3337
skip_frames: 2,
3438

@@ -40,6 +44,7 @@ Caused by:
4044
welcome: MarkDownPage::new(Self::PATH_WELCOME),
4145
sound: SoundPage::new(Self::PATH_SOUND),
4246
scale: ScalePage::new(Self::PATH_SCALE),
47+
guitar: GuitarPage::new(Self::PATH_GUITAR),
4348
}
4449
}
4550
}
@@ -48,13 +53,16 @@ impl IndexPanel {
4853
pub const WELCOME: KbPageId = KbPageId::MarkDown(Self::PATH_WELCOME);
4954
pub const SOUND: KbPageId = KbPageId::Custom("sound");
5055
pub const SCALE: KbPageId = KbPageId::Custom("scale");
56+
pub const GUITAR: KbPageId = KbPageId::Custom("guitar");
5157

5258
pub const PATH_WELCOME: &'static str = "kb/welcome.md";
5359
pub const PATH_SOUND: &'static str = "kb/sound.md";
5460
pub const PATH_SCALE: &'static str = "kb/scale.md";
61+
pub const PATH_GUITAR: &'static str = "kb/guitar.md";
5562

5663
pub const LINK_SOUND: &'static str = ":kb:sound";
5764
pub const LINK_SCALE: &'static str = ":kb:scale";
65+
pub const LINK_GUITAR: &'static str = ":kb:guitar";
5866
pub const LINK_SOUND_SINGLE_STRING: &'static str = ":kb:sound:single_string";
5967

6068
pub const LINK_MIDI_PLAY: &'static str = ":midi:play";
@@ -76,12 +84,14 @@ impl KbPanel for IndexPanel {
7684
(Self::WELCOME, "Welcome"),
7785
(Self::SOUND, "Sound"),
7886
(Self::SCALE, "Scale"),
87+
(Self::GUITAR, "Guitar"),
7988
]
8089
}
8190
fn get_page_mut(&mut self, page_id: KbPageId) -> &mut dyn KbPage {
8291
match page_id {
8392
Self::SOUND => &mut self.sound as &mut dyn KbPage,
8493
Self::SCALE => &mut self.scale as &mut dyn KbPage,
94+
Self::GUITAR => &mut self.guitar as &mut dyn KbPage,
8595
_ => &mut self.welcome as &mut dyn KbPage,
8696
}
8797
}
@@ -109,6 +119,7 @@ impl IndexPanel {
109119
state: Res<NotationState>,
110120
mut theme: ResMut<NotationTheme>,
111121
mut settings: ResMut<NotationSettings>,
122+
index: Res<IndexPanel>,
112123
) {
113124
theme.sizes.melody.note_height = 8.0;
114125
theme.sizes.melody.semitone_height = 8.0;
@@ -122,8 +133,9 @@ impl IndexPanel {
122133
if state.window_width > state.window_height {
123134
let width = state.window_width / 3.0 + theme.sizes.layout.page_margin;
124135
settings.hide_guitar_view = false;
125-
settings.override_guitar_width = Some(width);
126136
settings.hide_chords_view = true;
137+
settings.override_guitar_width = Some(width);
138+
settings.layout.override_tab_width = None;
127139
} else {
128140
settings.hide_guitar_view = true;
129141
settings.hide_chords_view = false;

apps/notation_kb_cn/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub struct NotationKnowledgeBaseAssets {
1616

1717
#[asset(path = "kb/scale.md")]
1818
pub kb_scale: Handle<MarkDownAsset>,
19+
20+
#[asset(path = "kb/guitar.md")]
21+
pub kb_guitar: Handle<MarkDownAsset>,
1922
}
2023

2124
impl ExtraAssets for NotationKnowledgeBaseAssets {
@@ -24,6 +27,7 @@ impl ExtraAssets for NotationKnowledgeBaseAssets {
2427
self.kb_welcome.clone_untyped(),
2528
self.kb_sound.clone_untyped(),
2629
self.kb_scale.clone_untyped(),
30+
self.kb_guitar.clone_untyped(),
2731
]
2832
}
2933
fn get_lyrics_font() -> &'static str {

apps/notation_viewer/src/viewer.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use notation_bevy::bevy::prelude::*;
22
use notation_bevy::bevy::input::mouse::{MouseMotion, MouseWheel, MouseScrollUnit};
33

4+
use notation_bevy::bevy_egui::EguiContext;
45
use notation_bevy::prelude::*;
56
use notation_bevy::settings::layout_settings::LayoutMode;
67

@@ -48,6 +49,7 @@ impl NotationViewer {
4849

4950
fn handle_keyboard_inputs(
5051
keyboard_input: Res<Input<KeyCode>>,
52+
egui_ctx: Res<EguiContext>,
5153
mut app_state: ResMut<NotationState>,
5254
mut settings: ResMut<NotationSettings>,
5355
mut theme: ResMut<NotationTheme>,
@@ -60,6 +62,9 @@ impl NotationViewer {
6062
if app_state.tab.is_none() {
6163
return;
6264
}
65+
if egui_ctx.ctx().wants_keyboard_input() {
66+
return;
67+
}
6368
if keyboard_input.just_released(KeyCode::F10) || keyboard_input.just_released(KeyCode::Backslash) {
6469
app_state.show_control = !app_state.show_control;
6570
if !ControlPanel::HUD_MODE {
@@ -121,8 +126,7 @@ impl NotationViewer {
121126
MidiControl::set_begin_bar_ordinal(&mut midi_state, &mut play_control_evts);
122127
MidiControl::set_end_bar_ordinal(&mut midi_state, &mut play_control_evts);
123128
} else if keyboard_input.just_released(KeyCode::E) {
124-
MidiControl::set_begin_bar_ordinal(&mut midi_state, &mut play_control_evts);
125-
MidiControl::set_end_bar_ordinal(&mut midi_state, &mut play_control_evts);
129+
MidiControl::set_begin_end_to_section(&mut midi_state, &mut play_control_evts);
126130
} else if keyboard_input.just_released(KeyCode::Key1) {
127131
MidiControl::set_speed_factor(&mut settings, &mut midi_state, &mut play_control_evts, 0.25);
128132
} else if keyboard_input.just_released(KeyCode::Key2) {
@@ -137,6 +141,7 @@ impl NotationViewer {
137141
fn handle_mouse_inputs(
138142
windows: Res<Windows>,
139143
mouse_input: Res<Input<MouseButton>>,
144+
egui_ctx: Res<EguiContext>,
140145
app_state: Res<NotationState>,
141146
settings: Res<NotationSettings>,
142147
mut mouse_motion_events: EventReader<MouseMotion>,
@@ -147,6 +152,9 @@ impl NotationViewer {
147152
if app_state.tab.is_none() {
148153
return;
149154
}
155+
if egui_ctx.ctx().is_pointer_over_area() {
156+
return;
157+
}
150158
let cursor_position = windows.get_primary().and_then(|x| x.cursor_position());
151159
if cursor_position.is_none() {
152160
return;
@@ -187,13 +195,17 @@ impl NotationViewer {
187195
fn handle_touch_inputs(
188196
windows: Res<Windows>,
189197
touch_input: Res<Touches>,
198+
egui_ctx: Res<EguiContext>,
190199
mut app_state: ResMut<NotationState>,
191200
mut mouse_clicked: EventWriter<MouseClickedEvent>,
192201
//mut mouse_dragged: EventWriter<MouseDraggedEvent>,
193202
) {
194203
if app_state.tab.is_none() {
195204
return;
196205
}
206+
if egui_ctx.ctx().wants_pointer_input() {
207+
return;
208+
}
197209
for (_index, finger) in touch_input.iter().enumerate() {
198210
if touch_input.just_pressed(finger.id()) {
199211
windows

crates/notation_bevy/src/tab/tab_control.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ impl TabControl {
3030
pub fn new(tab: Arc<Tab>) -> Self {
3131
Self { tab }
3232
}
33+
pub fn calc_width(max_width: f32, theme: &NotationTheme) -> f32 {
34+
let mut width =
35+
max_width * theme.sizes.tab_control.control_width_factor;
36+
if width < theme.sizes.tab_control.tab_control_range.0 {
37+
width = theme.sizes.tab_control.tab_control_range.0;
38+
} else if width > theme.sizes.tab_control.tab_control_range.1 {
39+
width = theme.sizes.tab_control.tab_control_range.1;
40+
}
41+
width
42+
}
3343
}
3444
impl<'a> View<NotationLayout<'a>> for TabControl {
3545
fn calc_size(&self, engine: &NotationLayout, constraint: LayoutConstraint) -> LayoutSize {
@@ -39,14 +49,7 @@ impl<'a> View<NotationLayout<'a>> for TabControl {
3949
let width = match engine.settings.override_guitar_width {
4050
Some(width) => width,
4151
None => {
42-
let mut width =
43-
constraint.max.width * engine.theme.sizes.tab_control.control_width_factor;
44-
if width < engine.theme.sizes.tab_control.tab_control_range.0 {
45-
width = engine.theme.sizes.tab_control.tab_control_range.0;
46-
} else if width > engine.theme.sizes.tab_control.tab_control_range.1 {
47-
width = engine.theme.sizes.tab_control.tab_control_range.1;
48-
}
49-
width
52+
Self::calc_width(constraint.max.width, engine.theme)
5053
}
5154
};
5255
LayoutSize::new(width, constraint.max.height)

0 commit comments

Comments
 (0)