ImguiDoubleSlider: WIP: All data, related to Slider are in ImGuiControl now

+ code cleaning to avoid of use wxWidgets to render DoubleSlider
This commit is contained in:
YuSanka 2024-03-21 22:00:12 +01:00 committed by Lukas Matena
parent d06ef37df9
commit 6ea3dc6c27
7 changed files with 212 additions and 1771 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,13 +47,8 @@ bool check_color_change(const PrintObject* object, size_t frst_layer_id, size_t
// custom message the slider sends to its parent to notify a tick-change:
wxDECLARE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
/*
enum SelectedSlider {
ssUndef,
ssLower,
ssHigher
};
*/
enum FocusedItem {
fiNone,
fiRevertIcon,
@ -123,8 +118,7 @@ class TickCodeInfo
std::string pause_print_msg;
bool m_suppress_plus = false;
bool m_suppress_minus = false;
bool m_use_default_colors= false;
// int m_default_color_idx = 0;
bool m_use_default_colors{ true };
std::vector<std::string>* m_colors {nullptr};
@ -156,6 +150,7 @@ public:
bool suppressed_plus () { return m_suppress_plus; }
bool suppressed_minus() { return m_suppress_minus; }
void set_default_colors(bool default_colors_on) { m_use_default_colors = default_colors_on; }
bool used_default_colors() const { return m_use_default_colors; }
void set_extruder_colors(std::vector<std::string>* extruder_colors) { m_colors = extruder_colors; }
};
@ -214,31 +209,22 @@ class Control : public wxControl
public:
Control(
wxWindow *parent,
wxWindowID id,
int lowerValue,
int higherValue,
int minValue,
int maxValue,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxSL_VERTICAL,
const wxString& name = wxEmptyString);
~Control() {}
void msw_rescale();
void sys_color_changed();
int GetMinValue() const { return m_min_value; }
int GetMaxValue() const { return m_max_value; }
double GetMinValueD() { return m_values.empty() ? 0. : m_values[m_min_value]; }
double GetMaxValueD() { return m_values.empty() ? 0. : m_values[m_max_value]; }
int GetLowerValue() const { return m_lower_value; }
int GetHigherValue() const { return m_higher_value; }
int GetActiveValue() const;
int GetMinValue() const { return imgui_ctrl.GetMinValue(); }
int GetMaxValue() const { return imgui_ctrl.GetMaxValue(); }
double GetMinValueD() { return m_values.empty() ? 0. : m_values[GetMinValue()]; }
double GetMaxValueD() { return m_values.empty() ? 0. : m_values[GetMaxValue()]; }
int GetLowerValue() const { return imgui_ctrl.GetLowerValue(); }
int GetHigherValue()const { return imgui_ctrl.GetHigherValue(); }
double GetLowerValueD() { return get_double_value(ssLower); }
double GetHigherValueD() { return get_double_value(ssHigher); }
wxSize DoGetBestSize() const override;
wxSize get_min_size() const ;
// Set low and high slider position. If the span is non-empty, disable the "one layer" mode.
void SetLowerValue (const int lower_val);
@ -246,7 +232,6 @@ public:
void SetSelectionSpan(const int lower_val, const int higher_val);
void SetMaxValue(const int max_value);
void SetKoefForLabels(const double koef) { m_label_koef = koef; }
void SetSliderValues(const std::vector<double>& values);
void ChangeOneLayerLock();
void SetSliderAlternateValues(const std::vector<double>& values) { m_alternate_values = values; }
@ -269,25 +254,15 @@ public:
void set_render_as_disabled(bool value) { m_render_as_disabled = value; }
bool is_rendering_as_disabled() const { return m_render_as_disabled; }
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
bool is_one_layer() const { return m_is_one_layer; }
bool is_lower_at_min() const { return m_lower_value == m_min_value; }
bool is_higher_at_max() const { return m_higher_value == m_max_value; }
bool is_full_span() const { return this->is_lower_at_min() && this->is_higher_at_max(); }
bool is_lower_at_min() const { return imgui_ctrl.is_lower_at_min(); }
bool is_higher_at_max() const { return imgui_ctrl.is_higher_at_max(); }
void OnPaint(wxPaintEvent& ) { render(); }
void OnLeftDown(wxMouseEvent& event);
void OnMotion(wxMouseEvent& event);
void OnLeftUp(wxMouseEvent& event);
void OnEnterWin(wxMouseEvent& event) { enter_window(event, true); }
void OnLeaveWin(wxMouseEvent& event) { enter_window(event, false); }
void UseDefaultColors(bool def_colors_on) { m_ticks.set_default_colors(def_colors_on); }
void OnWheel(wxMouseEvent& event);
void UseDefaultColors(bool def_colors_on);
void OnKeyDown(wxKeyEvent &event);
void OnKeyUp(wxKeyEvent &event);
void OnChar(wxKeyEvent &event);
void OnRightDown(wxMouseEvent& event);
void OnRightUp(wxMouseEvent& event);
bool Show(bool show = true) override { imgui_ctrl.Show(show); return true; }
bool Hide() { return Show(false); }
void add_code_as_tick(Type type, int selected_extruder = -1);
// add default action for tick, when press "+"
@ -297,68 +272,28 @@ public:
void edit_tick(int tick = -1);
void switch_one_layer_mode();
void discard_all_thicks();
void move_current_thumb_to_pos(wxPoint pos);
void edit_extruder_sequence();
void jump_to_value();
void enable_action_icon(bool enable) { m_enable_action_icon = enable; }
void show_add_context_menu();
void show_edit_context_menu();
void show_cog_icon_context_menu();
void auto_color_change();
void imgui_render(GUI::GLCanvas3D& canvas, float extra_scale = 1.f);
protected:
void render();
void draw_focus_rect(wxDC& dc);
void draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end);
void draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos);
void draw_thumb(wxDC& dc, const wxCoord& pos_coord, const SelectedSlider& selection);
void draw_thumbs(wxDC& dc, const wxCoord& lower_pos, const wxCoord& higher_pos);
void draw_ticks_pair(wxDC& dc, wxCoord pos, wxCoord mid, int tick_len);
void draw_ticks(wxDC& dc);
void draw_colored_band(wxDC& dc);
void draw_ruler(wxDC& dc);
void draw_one_layer_icon(wxDC& dc);
void draw_revert_icon(wxDC& dc);
void draw_cog_icon(wxDC &dc);
void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection);
void draw_info_line_with_icon(wxDC& dc, const wxPoint& pos, SelectedSlider selection);
void draw_tick_on_mouse_position(wxDC &dc);
void draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, LabelType label_type = ltHeight, bool right_side = true) const;
void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const;
void update_thumb_rect(const wxCoord begin_x, const wxCoord begin_y, const SelectedSlider& selection);
bool is_lower_thumb_editable();
bool detect_selected_slider(const wxPoint& pt);
void correct_lower_value();
void correct_higher_value();
void move_current_thumb(const bool condition);
void enter_window(wxMouseEvent& event, const bool enter);
bool is_wipe_tower_layer(int tick) const;
private:
bool is_point_in_rect(const wxPoint& pt, const wxRect& rect);
int get_tick_near_point(const wxPoint& pt);
bool is_lower_thumb_editable();
void move_current_thumb(const bool condition);
bool is_wipe_tower_layer(int tick) const;
double get_scroll_step();
wxString get_label(int tick, LabelType label_type = ltHeightWithLayer) const;
void get_lower_and_higher_position(int& lower_pos, int& higher_pos);
int get_value_from_position(const wxCoord x, const wxCoord y);
int get_value_from_position(const wxPoint pos) { return get_value_from_position(pos.x, pos.y); }
wxCoord get_position_from_value(const int value);
wxSize get_size() const;
void get_size(int* w, int* h) const;
double get_double_value(const SelectedSlider& selection);
int get_tick_from_value(double value, bool force_lower_bound = false);
wxString get_tooltip(int tick = -1);
int get_edited_tick_for_position(wxPoint pos, Type type = ColorChange);
std::string get_color_for_tool_change_tick(std::set<TickCode>::const_iterator it) const;
std::string get_color_for_color_change_tick(std::set<TickCode>::const_iterator it) const;
wxRect get_colored_band_rect();
// Get active extruders for tick.
// Means one current extruder for not existing tick OR
@ -373,32 +308,10 @@ private:
void append_add_color_change_menu_item(wxMenu*, bool switch_current_code = false);
bool is_osx { false };
wxFont m_font;
int m_min_value;
int m_max_value;
int m_lower_value;
int m_higher_value;
bool m_render_as_disabled{ false };
bool m_allow_editing{ true };
ScalableBitmap m_bmp_thumb_higher;
ScalableBitmap m_bmp_thumb_lower;
ScalableBitmap m_bmp_add_tick_on;
ScalableBitmap m_bmp_add_tick_off;
ScalableBitmap m_bmp_del_tick_on;
ScalableBitmap m_bmp_del_tick_off;
ScalableBitmap m_bmp_one_layer_lock_on;
ScalableBitmap m_bmp_one_layer_lock_off;
ScalableBitmap m_bmp_one_layer_unlock_on;
ScalableBitmap m_bmp_one_layer_unlock_off;
ScalableBitmap m_bmp_revert;
ScalableBitmap m_bmp_cog;
SelectedSlider m_selection;
bool m_is_left_down = false;
bool m_is_right_down = false;
bool m_is_one_layer = false;
bool m_is_focused = false;
bool m_force_mode_apply = true;
bool m_enable_action_icon = true;
bool m_is_wipe_tower = false; //This flag indicates that there is multiple extruder print with wipe tower
@ -410,22 +323,8 @@ private:
MouseAction m_mouse = maNone;
FocusedItem m_focus = fiNone;
wxPoint m_moving_pos = wxDefaultPosition;
wxRect m_rect_lower_thumb;
wxRect m_rect_higher_thumb;
wxRect m_rect_tick_action;
wxRect m_rect_one_layer_icon;
wxRect m_rect_revert_icon;
wxRect m_rect_cog_icon;
wxSize m_thumb_size;
int m_tick_icon_dim;
int m_lock_icon_dim;
int m_revert_icon_dim;
int m_cog_icon_dim;
long m_style;
long m_extra_style;
float m_label_koef{ 1.0 };
bool m_show_estimated_times{ false };
std::vector<double> m_values;
TickCodeInfo m_ticks;
@ -438,63 +337,17 @@ private:
ExtrudersSequence m_extruders_sequence;
// control's view variables
wxCoord SLIDER_MARGIN; // margin around slider
wxPen DARK_ORANGE_PEN;
wxPen ORANGE_PEN;
wxPen LIGHT_ORANGE_PEN;
wxPen DARK_GREY_PEN;
wxPen GREY_PEN;
wxPen LIGHT_GREY_PEN;
wxPen FOCUS_RECT_PEN;
wxBrush FOCUS_RECT_BRUSH;
std::vector<wxPen*> m_line_pens;
std::vector<wxPen*> m_segm_pens;
class Ruler {
wxWindow* m_parent{nullptr}; // m_parent is nullptr for Unused ruler
// in this case we will not init/update/render it
// values to check if ruler has to be updated
double m_min_val;
double m_max_val;
double m_scroll_step;
size_t m_max_values_cnt;
int m_DPI;
public:
double long_step;
double short_step;
std::vector<double> max_values;// max value for each object/instance in sequence print
// > 1 for sequential print
void set_parent(wxWindow* parent);
void update_dpi();
void init(const std::vector<double>& values, double scroll_step);
void update(const std::vector<double>& values, double scroll_step);
bool is_ok() { return long_step > 0 && short_step > 0; }
size_t count() { return max_values.size(); }
bool can_draw() { return m_parent != nullptr; }
} m_ruler;
// ImGuiDS
float m_scale{ 1.0 };
float m_scale{ 1.f };
bool m_can_change_color{ true };
bool m_show_menu{ false };
void draw_colored_band(const ImRect& groove, const ImRect& slideable_region);
void draw_ticks(const ImRect& slideable_region);
void render_menu();
bool render_button(const wchar_t btn_icon, const wchar_t btn_icon_hovered, const std::string& label_id, const ImVec2& pos, FocusedItem focus, int tick = -1);
void update_callbacks();
GUI::ImGuiControl imgui_ctrl;
};
} // DoubleSlider;

View File

@ -231,29 +231,16 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Model* model)
m_canvas->show_legend(true);
m_canvas->enable_dynamic_background(true);
m_layers_slider_sizer = create_layers_slider_sizer();
wxGetApp().UpdateDarkUI(m_bottom_toolbar_panel = new wxPanel(this));
create_layers_slider();
m_left_sizer = new wxBoxSizer(wxVERTICAL);
m_left_sizer->Add(m_canvas_widget, 1, wxALL | wxEXPAND, 0);
wxBoxSizer* right_sizer = new wxBoxSizer(wxVERTICAL);
right_sizer->Add(m_layers_slider_sizer, 1, wxEXPAND, 0);
m_moves_slider = new DoubleSlider::Control(m_bottom_toolbar_panel, wxID_ANY, 0, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL, "moves_slider");
m_moves_slider = new DoubleSlider::Control(this, 0, 0, 0, 100, wxSL_HORIZONTAL, "moves_slider");
m_moves_slider->SetDrawMode(DoubleSlider::dmSequentialGCodeView);
wxBoxSizer* bottom_toolbar_sizer = new wxBoxSizer(wxHORIZONTAL);
bottom_toolbar_sizer->Add(m_moves_slider, 1, wxALL | wxEXPAND, 0);
m_bottom_toolbar_panel->SetSizer(bottom_toolbar_sizer);
m_left_sizer->Add(m_bottom_toolbar_panel, 0, wxALL | wxEXPAND, 0);
m_left_sizer->Hide(m_bottom_toolbar_panel);
wxBoxSizer* main_sizer = new wxBoxSizer(wxHORIZONTAL);
main_sizer->Add(m_left_sizer, 1, wxALL | wxEXPAND, 0);
main_sizer->Add(right_sizer, 0, wxALL | wxEXPAND, 0);
SetSizer(main_sizer);
SetMinSize(GetSize());
@ -325,10 +312,6 @@ void Preview::reload_print()
void Preview::msw_rescale()
{
// rescale slider
if (m_layers_slider != nullptr) m_layers_slider->msw_rescale();
if (m_moves_slider != nullptr) m_moves_slider->msw_rescale();
// rescale warning legend on the canvas
get_canvas3d()->msw_rescale();
@ -336,23 +319,11 @@ void Preview::msw_rescale()
reload_print();
}
void Preview::sys_color_changed()
{
#ifdef _WIN32
wxWindowUpdateLocker noUpdates(this);
wxGetApp().UpdateAllStaticTextDarkUI(m_bottom_toolbar_panel);
#endif // _WIN32
if (m_layers_slider != nullptr)
m_layers_slider->sys_color_changed();
}
void Preview::render_sliders(GLCanvas3D& canvas, float extra_scale/* = 0.1f*/)
{
if (m_layers_slider && m_layers_slider->IsShown())
if (m_layers_slider)
m_layers_slider->imgui_render(canvas, extra_scale);
if (m_moves_slider && m_moves_slider->IsShown() && m_bottom_toolbar_panel->IsShown())
if (m_moves_slider)
m_moves_slider->imgui_render(canvas, extra_scale);
}
@ -390,8 +361,7 @@ void Preview::move_moves_slider(wxKeyEvent& evt)
void Preview::hide_layers_slider()
{
m_layers_slider_sizer->Hide((size_t)0);
Layout();
m_layers_slider->Hide();
}
void Preview::on_size(wxSizeEvent& evt)
@ -400,16 +370,14 @@ void Preview::on_size(wxSizeEvent& evt)
Refresh();
}
wxBoxSizer* Preview::create_layers_slider_sizer()
void Preview::create_layers_slider()
{
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
m_layers_slider = new DoubleSlider::Control(this, wxID_ANY, 0, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxVERTICAL, "layers_slider");
m_layers_slider = new DoubleSlider::Control(this,0, 0, 0, 100, wxVERTICAL, "layers_slider");
m_layers_slider->SetDrawMode(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA,
wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects"));
m_layers_slider->enable_action_icon(wxGetApp().is_editor());
sizer->Add(m_layers_slider, 0, wxEXPAND, 0);
m_layers_slider->enable_action_icon(wxGetApp().is_editor());
// sizer, m_canvas_widget
m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_layers_slider_from_canvas, this);
@ -429,8 +397,6 @@ wxBoxSizer* Preview::create_layers_slider_sizer()
m_keep_current_preview_type = false;
reload_print();
});
return sizer;
}
// Find an index of a value in a sorted vector, which is in <z-eps, z+eps>.
@ -602,9 +568,7 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
break;
}
}
m_layers_slider_sizer->Show((size_t)0);
Layout();
m_layers_slider->Show();
}
void Preview::update_layers_slider_mode()
@ -679,12 +643,10 @@ void Preview::update_layers_slider_from_canvas(wxKeyEvent& event)
if (key == 'S' || key == 'W') {
const int new_pos = key == 'W' ? m_layers_slider->GetHigherValue() + 1 : m_layers_slider->GetHigherValue() - 1;
m_layers_slider->SetHigherValue(new_pos);
if (event.ShiftDown() || m_layers_slider->is_one_layer()) m_layers_slider->SetLowerValue(m_layers_slider->GetHigherValue());
}
else if (key == 'A' || key == 'D') {
const int new_pos = key == 'D' ? m_moves_slider->GetHigherValue() + 1 : m_moves_slider->GetHigherValue() - 1;
m_moves_slider->SetHigherValue(new_pos);
if (event.ShiftDown() || m_moves_slider->is_one_layer()) m_moves_slider->SetLowerValue(m_moves_slider->GetHigherValue());
}
else if (key == 'X')
m_layers_slider->ChangeOneLayerLock();
@ -790,9 +752,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
if (wxGetApp().is_editor() && !has_layers) {
m_canvas->reset_gcode_layers_times_cache();
hide_layers_slider();
m_left_sizer->Hide(m_bottom_toolbar_panel);
m_left_sizer->Layout();
Refresh();
m_moves_slider->Hide();
m_canvas_widget->Refresh();
return;
}
@ -819,11 +779,9 @@ void Preview::load_print_as_fff(bool keep_z_range)
m_canvas->load_gcode_preview(*m_gcode_result, tool_colors, color_print_colors);
// the view type may have been changed by the call m_canvas->load_gcode_preview()
gcode_view_type = m_canvas->get_gcode_view_type();
m_left_sizer->Layout();
Refresh();
zs = m_canvas->get_gcode_layers_zs();
if (!zs.empty())
m_left_sizer->Show(m_bottom_toolbar_panel);
m_moves_slider->Show();
m_loaded = true;
}
else if (is_pregcode_preview) {
@ -832,15 +790,11 @@ void Preview::load_print_as_fff(bool keep_z_range)
// the view type has been changed by the call m_canvas->load_gcode_preview()
if (gcode_view_type == libvgcode::EViewType::ColorPrint && !color_print_values.empty())
m_canvas->set_gcode_view_type(gcode_view_type);
m_left_sizer->Hide(m_bottom_toolbar_panel);
m_left_sizer->Layout();
Refresh();
m_moves_slider->Hide();
zs = m_canvas->get_gcode_layers_zs();
}
else {
m_left_sizer->Hide(m_bottom_toolbar_panel);
m_left_sizer->Layout();
Refresh();
m_moves_slider->Hide();
}
if (!zs.empty() && !m_keep_current_preview_type) {
@ -902,9 +856,7 @@ void Preview::load_print_as_sla()
if (IsShown()) {
m_canvas->load_sla_preview();
m_left_sizer->Hide(m_bottom_toolbar_panel);
m_left_sizer->Layout();
Refresh();
m_moves_slider->Hide();
if (n_layers > 0)
update_layers_slider(zs);

View File

@ -82,8 +82,6 @@ class Preview : public wxPanel
wxGLCanvas* m_canvas_widget { nullptr };
GLCanvas3D* m_canvas { nullptr };
wxBoxSizer* m_left_sizer { nullptr };
wxBoxSizer* m_layers_slider_sizer { nullptr };
wxPanel* m_bottom_toolbar_panel { nullptr };
DynamicPrintConfig* m_config;
BackgroundSlicingProcess* m_process;
@ -135,7 +133,6 @@ public:
void reload_print();
void msw_rescale();
void sys_color_changed();
void jump_layers_slider(wxKeyEvent& evt);
void move_layers_slider(wxKeyEvent& evt);
void edit_layers_slider(wxKeyEvent& evt);
@ -162,7 +159,7 @@ private:
void on_size(wxSizeEvent& evt);
// Create/Update/Reset double slider on 3dPreview
wxBoxSizer* create_layers_slider_sizer();
void create_layers_slider();
void check_layers_slider_values(std::vector<CustomGCode::Item>& ticks_from_model,
const std::vector<double>& layers_z);
void reset_layers_slider();

View File

@ -148,18 +148,22 @@ void ImGuiControl::SetLowerValue(const int lower_val)
{
m_selection = ssLower;
m_lower_value = lower_val;
correct_lower_value();
}
void ImGuiControl::SetHigherValue(const int higher_val)
{
m_selection = ssHigher;
m_higher_value = higher_val;
correct_higher_value();
}
void ImGuiControl::SetSelectionSpan(const int lower_val, const int higher_val)
{
m_lower_value = std::max(lower_val, m_min_value);
m_higher_value = std::max(std::min(higher_val, m_max_value), m_lower_value);
if (m_lower_value < m_higher_value)
m_combine_thumbs = false;
}
void ImGuiControl::SetMaxValue(const int max_value)
@ -167,16 +171,61 @@ void ImGuiControl::SetMaxValue(const int max_value)
m_max_value = max_value;
}
void ImGuiControl::SetSliderValues(const std::vector<double>& values)
void ImGuiControl::MoveActiveThumb(int delta)
{
m_values = values;
if (m_selection == ssUndef)
m_selection = ssHigher;
if (m_selection == ssLower) {
m_lower_value -= delta;
correct_lower_value();
}
else if (m_selection == ssHigher) {
m_higher_value -= delta;
correct_higher_value();
}
}
void ImGuiControl::correct_lower_value()
{
if (m_lower_value < m_min_value)
m_lower_value = m_min_value;
else if (m_lower_value > m_max_value)
m_lower_value = m_max_value;
if ((m_lower_value >= m_higher_value && m_lower_value <= m_max_value) || m_combine_thumbs) {
m_higher_value = m_lower_value;
}
}
void ImGuiControl::correct_higher_value()
{
if (m_higher_value > m_max_value)
m_higher_value = m_max_value;
else if (m_higher_value < m_min_value)
m_higher_value = m_min_value;
if ((m_higher_value <= m_lower_value && m_higher_value >= m_min_value) || m_combine_thumbs) {
m_lower_value = m_higher_value;
}
}
void ImGuiControl::CombineThumbs(bool combine)
{
m_combine_thumbs = combine;
if (combine)
m_selection = ssHigher;
if (combine) {
m_selection = ssHigher;
correct_higher_value();
}
else
ResetValues();
}
void ImGuiControl::ResetValues()
{
SetLowerValue(m_min_value);
SetHigherValue(m_max_value);
m_selection == ssLower ? correct_lower_value() : correct_higher_value();
}
std::string ImGuiControl::get_label(int pos) const
@ -184,16 +233,10 @@ std::string ImGuiControl::get_label(int pos) const
if (m_cb_get_label)
return m_cb_get_label(pos);
const size_t value = pos;
if (m_label_koef == 1.0 && m_values.empty())
return std::to_string(static_cast<unsigned long>(value));
if (value >= m_values.size())
if (pos >= m_max_value || pos < m_min_value)
return "ErrVal";
return m_values.empty() ?
to_string_with_precision(m_label_koef * value) :
to_string_with_precision(m_values[value]);
return std::to_string(pos);
}
float ImGuiControl::GetPositionFromValue(int value, const ImRect& rect) const
@ -457,7 +500,7 @@ bool ImGuiControl::draw_slider( int* higher_value, int* lower_value,
return value_changed;
}
bool ImGuiControl::render(SelectedSlider& selection)
bool ImGuiControl::render()
{
bool result = false;
@ -488,13 +531,15 @@ bool ImGuiControl::render(SelectedSlider& selection)
int temp_lower_value = m_lower_value;
if (draw_slider(&higher_value, &lower_value, higher_label, lower_label, m_pos, m_size, scale)) {
if (temp_higher_value != higher_value)
SetHigherValue(higher_value);
if (temp_higher_value != higher_value) {
m_higher_value = higher_value;
if (m_combine_thumbs)
m_lower_value = m_higher_value;
}
if (temp_lower_value != lower_value)
SetLowerValue(lower_value);
m_lower_value = lower_value;
result = true;
}
selection = m_selection;
ImGuiPureWrap::end();

View File

@ -56,8 +56,6 @@ public:
int GetMinValue() const { return m_min_value; }
int GetMaxValue() const { return m_max_value; }
double GetMinValueD() { return m_values.empty() ? 0. : m_values[m_min_value]; }
double GetMaxValueD() { return m_values.empty() ? 0. : m_values[m_max_value]; }
int GetLowerValue() const { return m_lower_value; }
int GetHigherValue() const { return m_higher_value; }
int GetActiveValue() const;
@ -69,8 +67,8 @@ public:
void SetSelectionSpan(const int lower_val, const int higher_val);
void SetMaxValue(const int max_value);
void SetSliderValues(const std::vector<double>& values);
void CombineThumbs(bool combine);
void ResetValues();
void SetPos(ImVec2 pos) { m_pos = pos; }
void SetSize(ImVec2 size) { m_size = size; }
@ -80,6 +78,14 @@ public:
m_size = size;
m_draw_opts.scale = scale;
}
void Show(bool show) { m_is_shown = show; }
void Hide() { m_is_shown = false; }
bool IsShown() const { return m_is_shown; }
void MoveActiveThumb(int delta);
bool IsCombineThumbs() const { return m_combine_thumbs; }
bool IsActiveHigherThumb() const { return m_selection == ssHigher; }
void ShowLabelOnMouseMove(bool show = true) { m_show_move_label = show; }
ImRect GetGrooveRect() const { return m_draw_opts.groove(m_pos, m_size, is_horizontal()); }
@ -89,7 +95,10 @@ public:
bool is_full_span() const { return this->is_lower_at_min() && this->is_higher_at_max(); }
bool is_rclick_on_thumb() const { return m_rclick_on_selected_thumb; }
bool render(SelectedSlider& selection);
void correct_lower_value();
void correct_higher_value();
bool render();
void draw_scroll_line(const ImRect& scroll_line, const ImRect& slideable_region);
std::string get_label(int pos) const;
@ -132,6 +141,7 @@ private:
ImVec2 m_size;
std::string m_name;
ImGuiSliderFlags m_flags{ ImGuiSliderFlags_None };
bool m_is_shown{ true };
int m_min_value;
int m_max_value;
@ -139,14 +149,15 @@ private:
int m_higher_value;
int m_mouse_pos_value;
double m_label_koef{ 1. };
bool m_rclick_on_selected_thumb{ false };
bool m_draw_lower_thumb{ true };
bool m_combine_thumbs { false };
bool m_show_move_label{ false };
DrawOptions m_draw_opts;
Regions m_regions;
std::function<std::string(int)> m_cb_get_label { nullptr };
std::function<std::string(int)> m_cb_get_label_on_move { nullptr };
std::function<void(const ImRect&, const ImRect&)> m_cb_draw_scroll_line { nullptr };
@ -163,13 +174,6 @@ private:
bool draw_slider(int* higher_value, int* lower_value,
std::string& higher_label, std::string& lower_label,
const ImVec2& pos, const ImVec2& size, float scale = 1.0f);
protected:
std::vector<double> m_values;
DrawOptions m_draw_opts;
Regions m_regions;
};
} // GUI

View File

@ -6698,7 +6698,6 @@ void Plater::msw_rescale()
void Plater::sys_color_changed()
{
p->preview->sys_color_changed();
p->sidebar->sys_color_changed();
p->menus.sys_color_changed();