ImGuiDoubleSlider: Implemented Freeze/Thaw functions to avoid redundant call of the process_thumb_move();

+ Use SetSelectionSpan instead of SetHigherPos and SetLowerPos at the same time
This commit is contained in:
YuSanka 2024-05-29 17:00:03 +02:00 committed by Lukas Matena
parent 34a79d69eb
commit 6ee8901338
2 changed files with 22 additions and 8 deletions

View File

@ -195,8 +195,8 @@ Preview::Preview(
void Preview::set_layers_slider_values_range(int bottom, int top) void Preview::set_layers_slider_values_range(int bottom, int top)
{ {
m_layers_slider->SetHigherPos(std::min(top, m_layers_slider->GetMaxPos())); m_layers_slider->SetSelectionSpan(std::min(top, m_layers_slider->GetMaxPos()),
m_layers_slider->SetLowerPos(std::max(bottom, m_layers_slider->GetMinPos())); std::max(bottom, m_layers_slider->GetMinPos()));
} }
bool Preview::init(wxWindow* parent, Bed3D& bed, Model* model) bool Preview::init(wxWindow* parent, Bed3D& bed, Model* model)
@ -606,6 +606,9 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config(wxGetApp().is_editor() ? nullptr : m_gcode_result)); m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config(wxGetApp().is_editor() ? nullptr : m_gcode_result));
m_layers_slider->SetSliderValues(layers_z); m_layers_slider->SetSliderValues(layers_z);
assert(m_layers_slider->GetMinPos() == 0); assert(m_layers_slider->GetMinPos() == 0);
m_layers_slider->Freeze();
m_layers_slider->SetMaxPos(layers_z.empty() ? 0 : layers_z.size() - 1); m_layers_slider->SetMaxPos(layers_z.empty() ? 0 : layers_z.size() - 1);
int idx_low = 0; int idx_low = 0;
@ -633,6 +636,8 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
else else
m_layers_slider->SetLayersTimes(m_canvas->get_gcode_layers_times_cache(), m_gcode_result->print_statistics.modes.front().time); m_layers_slider->SetLayersTimes(m_canvas->get_gcode_layers_times_cache(), m_gcode_result->print_statistics.modes.front().time);
m_layers_slider->Thaw();
// check if ticks_info_from_model contains ColorChange g-code // check if ticks_info_from_model contains ColorChange g-code
bool color_change_already_exists = false; bool color_change_already_exists = false;
for (const CustomGCode::Item& gcode: ticks_info_from_model.gcodes) for (const CustomGCode::Item& gcode: ticks_info_from_model.gcodes)
@ -768,8 +773,7 @@ void Preview::update_layers_slider_mode()
void Preview::reset_layers_slider() void Preview::reset_layers_slider()
{ {
m_layers_slider->SetHigherPos(0); m_layers_slider->SetSelectionSpan(0, 0);
m_layers_slider->SetLowerPos(0);
} }
void Preview::update_sliders_from_canvas(wxKeyEvent& event) void Preview::update_sliders_from_canvas(wxKeyEvent& event)
@ -871,8 +875,11 @@ void Preview::update_moves_slider(std::optional<int> visible_range_min, std::opt
m_moves_slider->SetSliderValues(values); m_moves_slider->SetSliderValues(values);
m_moves_slider->SetSliderAlternateValues(alternate_values); m_moves_slider->SetSliderAlternateValues(alternate_values);
m_moves_slider->Freeze();
m_moves_slider->SetMaxPos(static_cast<int>(values.size()) - 1); m_moves_slider->SetMaxPos(static_cast<int>(values.size()) - 1);
m_moves_slider->SetSelectionSpan(span_min_id, span_max_id); m_moves_slider->SetSelectionSpan(span_min_id, span_max_id);
m_moves_slider->Thaw();
m_moves_slider->ShowLowerThumb(get_app_config()->get("seq_top_layer_only") == "0"); m_moves_slider->ShowLowerThumb(get_app_config()->get("seq_top_layer_only") == "0");
} }

View File

@ -136,7 +136,7 @@ private:
int m_lower_pos; int m_lower_pos;
int m_higher_pos; int m_higher_pos;
// slider's position of the mouse cursor // slider's position of the mouse cursor
int m_mouse_pos; int m_mouse_pos { 0 };
bool m_rclick_on_selected_thumb{ false }; bool m_rclick_on_selected_thumb{ false };
bool m_lclick_on_selected_thumb{ false }; bool m_lclick_on_selected_thumb{ false };
@ -230,6 +230,13 @@ public:
m_ctrl.SetMaxPos(max_pos); m_ctrl.SetMaxPos(max_pos);
process_thumb_move(); process_thumb_move();
} }
void Freeze() {
m_allow_process_thumb_move = false;
}
void Thaw() {
m_allow_process_thumb_move = true;
process_thumb_move();
}
void SetSliderValues(const std::vector<ValType>& values) { m_values = values; } void SetSliderValues(const std::vector<ValType>& values) { m_values = values; }
// values used to show thumb labels // values used to show thumb labels
@ -274,14 +281,14 @@ protected:
} }
void process_thumb_move() { void process_thumb_move() {
if (m_cb_thumb_move) if (m_cb_thumb_move && m_allow_process_thumb_move)
m_cb_thumb_move(); m_cb_thumb_move();
} }
private: private:
std::function<void()> m_cb_thumb_move{ nullptr }; std::function<void()> m_cb_thumb_move { nullptr };
bool m_allow_process_thumb_move { true };
}; };
} // DoubleSlider } // DoubleSlider