Skip to content

Commit

Permalink
[UI] Improve track controls responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
native-m committed Oct 27, 2024
1 parent 4ef846c commit 1132919
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
23 changes: 23 additions & 0 deletions src/ui/test_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ void render_test_controls() {

ImGui::Button("Test");

/*
controls::slider2<float>(
SliderProperties {
.grab_shape = controls::SliderGrabShape::Rectangle,
.grab_size = {16.0f, 28.0f},
.grab_roundness = 2.0f,
.extra_padding = {0.0f, 4.0f},
.frame_width = 4.0f,
},
"##slider_test", ImVec2(20.f, 130.0f), 0xFFED961C, &slider_value, 0.0f, 1.0f);
ImGui::SameLine();
controls::slider2<float>(
SliderProperties {
.grab_shape = controls::SliderGrabShape::Circle,
.grab_size = {16.0f, 28.0f},
.grab_roundness = 2.0f,
.extra_padding = {0.0f, 4.0f},
.frame_width = 4.0f,
},
"##slider_test2", ImVec2(20.f, 130.0f), 0xFFED961C, &slider_value, 0.0f, 1.0f);
*/
end_window();
}

Expand Down
56 changes: 34 additions & 22 deletions src/ui/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,50 +401,62 @@ void GuiTimeline::render_track_controls() {
ImGui::EndDisabled();
}

ImVec2 free_region = ImGui::GetWindowContentRegionMax();
ImVec2 free_region = ImGui::GetContentRegionAvail();
float item_height = controls::get_item_height();

float volume = track->ui_parameter_state.volume_db;
if (height < item_height * 2.5f) {
bool mute = track->ui_parameter_state.mute;
if (ImGui::Button("M")) {
track->set_mute(!mute);
}

ImGui::SameLine(0.0f, 2.0f);
if (ImGui::Button("S")) {
g_engine.solo_track(i);
}
bool mute = track->ui_parameter_state.mute;

if (free_region.y < item_height * 1.5f) [[likely]] {
if (free_region.y < (item_height - style.ItemSpacing.y)) {
if (free_region.y >= item_height * 0.5f) {
// Mute & solo only
if (ImGui::SmallButton("M")) {
track->set_mute(!mute);
}
ImGui::SameLine(0.0f, 2.0f);
if (ImGui::SmallButton("S")) {
g_engine.solo_track(i);
}
}
} else [[likely]] {
// Compact
if (ImGui::Button("M")) {
track->set_mute(!mute);
}
ImGui::SameLine(0.0f, 2.0f);
if (ImGui::Button("S")) {
g_engine.solo_track(i);
}

ImGui::SameLine(0.0f, 2.0f);
ImVec2 pos = ImGui::GetCursorPos();
ImGui::SetNextItemWidth(free_region.x - pos.x);
if (controls::param_drag_db("##Vol.", &volume)) {
track->set_volume(volume);
ImGui::SameLine(0.0f, 2.0f);
ImVec2 pos = ImGui::GetCursorPos();
ImGui::SetNextItemWidth(free_region.x - pos.x);
if (controls::param_drag_db("##Vol.", &volume)) {
track->set_volume(volume);
}
}
} else {
// Large
if (controls::param_drag_db("Vol.", &volume)) {
track->set_volume(volume);
}
}

if (height > item_height * 2.5f) {
if (height > item_height * 3.5f) {
if (free_region.y >= item_height * 2.5f) {
float pan = track->ui_parameter_state.pan;
if (controls::param_drag_panning("Pan", &pan)) {
track->set_pan(pan);
}
}

bool mute = track->ui_parameter_state.mute;
if (ImGui::SmallButton("M")) {
track->set_mute(!mute);
}

ImGui::SameLine(0.0f, 2.0f);
if (ImGui::SmallButton("S")) {
g_engine.solo_track(i);
}

if (mute) {
ImGui::SameLine(0.0f, 2.0f);
ImGui::Text("Muted");
Expand Down

0 comments on commit 1132919

Please sign in to comment.