Skip to content

Commit

Permalink
working Arc<AtomicBool> -> bool
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Dec 9, 2024
1 parent 6203280 commit 158ab54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
49 changes: 21 additions & 28 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ pub struct Data {
pub show_full_parameters: bool,
}

impl Model for Data {}
enum AppEvent {
ToggleShowView,
}

impl Model for Data {
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
event.map(|app_event, _| match app_event {
AppEvent::ToggleShowView => self.show_full_parameters ^= true,
});
}
}

// Makes sense to also define this here, makes it a bit easier to keep track of
pub fn default_state() -> Arc<ViziaState> {
Expand All @@ -78,10 +88,8 @@ pub fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dy
;
Label::new(cx, "DEL2").class("plugin-name");
});
let show_parameters = Data::show_full_parameters;

Binding::new(cx, show_parameters, |cx, show_parameters| {
if show_parameters.get(cx) {
Binding::new(cx, Data::show_full_parameters, |cx, show| {
if show.get(cx) {
full_parameters(cx);
} else {
minimal_parameters(cx);
Expand Down Expand Up @@ -178,7 +186,7 @@ fn full_parameters(cx: &mut Context) {
})
.class("param-group");
ZStack::new(cx, |cx| {
CollapseButton::new(cx, Data::show_full_parameters).class("show-full-parameters");
CollapseButton::new(cx).class("show-full-parameters");
Label::new(cx, "triggers").class("mid-group-title");
});
HStack::new(cx, |cx| {
Expand Down Expand Up @@ -375,7 +383,7 @@ fn minimal_parameters(cx: &mut Context) {
Label::new(cx, "high velocity").class("column-title");
})
.class("column-title-group-minimal");
CollapseButton::new(cx, Data::show_full_parameters).class("show-full-parameters");
CollapseButton::new(cx).class("show-full-parameters");
});
HStack::new(cx, |cx| {
VStack::new(cx, |cx| {
Expand Down Expand Up @@ -1697,24 +1705,13 @@ impl View for ActionTrigger {
// CollapseButton //
///////////////////////////////////////////////////////////////////////////////

pub struct CollapseButton {
show_full_parameters: bool,
}
pub struct CollapseButton {}
impl CollapseButton {
pub fn new<ShowFullParametersL>(
cx: &mut Context,
show_full_parameters: ShowFullParametersL,
) -> Handle<Self>
where
ShowFullParametersL: Lens<Target = bool>,
{
Self {
show_full_parameters: show_full_parameters.get(cx),
}
.build(cx, move |cx| {
pub fn new(cx: &mut Context) -> Handle<Self> {
Self {}.build(cx, move |cx| {
Label::new(
cx,
show_full_parameters.map(|show_full_parameters| {
Data::show_full_parameters.map(|show_full_parameters| {
// ▲ ▼ ◀ ▶
if *show_full_parameters {
String::from("▴")
Expand All @@ -1728,17 +1725,13 @@ impl CollapseButton {
}

impl View for CollapseButton {
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
event.map(|window_event, meta| match window_event {
// We don't need special double and triple click handling
WindowEvent::MouseDown(MouseButton::Left)
| WindowEvent::MouseDoubleClick(MouseButton::Left)
| WindowEvent::MouseTripleClick(MouseButton::Left) => {
if self.show_full_parameters {
self.show_full_parameters = false;
} else {
self.show_full_parameters = true;
}
cx.emit(AppEvent::ToggleShowView);
meta.consume();
}
_ => {}
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub struct Del2 {
counting_state: CountingState,
should_update_filter: Arc<AtomicBool>,
enabled_actions: Arc<AtomicBoolArray>,
show_full_parameters: bool,
running_delay_tempo: f32,
first_process_after_reset: bool,
}
Expand Down Expand Up @@ -532,7 +531,6 @@ impl Default for Del2 {
counting_state: CountingState::TimeOut,
should_update_filter,
enabled_actions,
show_full_parameters: true,
running_delay_tempo: DEFAULT_TEMPO,
first_process_after_reset: true,
}
Expand Down Expand Up @@ -634,7 +632,7 @@ impl Plugin for Del2 {
last_learned_notes: self.last_learned_notes.clone(),
last_played_notes: self.last_played_notes.clone(),
enabled_actions: self.enabled_actions.clone(),
show_full_parameters: self.show_full_parameters.clone(),
show_full_parameters: true,
},
self.params.editor_state.clone(),
)
Expand Down

0 comments on commit 158ab54

Please sign in to comment.