add UndoValueUIManager from PS
from prusa3d/PrusaSlicer@32ff20d Co-authored-by: YuSanka <yusanka@gmail.com>
This commit is contained in:
parent
7739252711
commit
4f0a47b7f4
7 changed files with 162 additions and 88 deletions
|
@ -206,7 +206,7 @@ wxString Field::get_tooltip_text(const wxString &default_string)
|
|||
wxString tooltip_text("");
|
||||
#ifdef NDEBUG
|
||||
wxString tooltip = _(m_opt.tooltip);
|
||||
edit_tooltip(tooltip);
|
||||
::edit_tooltip(tooltip);
|
||||
|
||||
std::string opt_id = m_opt_id;
|
||||
auto hash_pos = opt_id.find("#");
|
||||
|
|
|
@ -41,7 +41,120 @@ wxString double_to_string(double const value, const int max_precision = 4);
|
|||
wxString get_thumbnail_string(const Vec2d& value);
|
||||
wxString get_thumbnails_string(const std::vector<Vec2d>& values);
|
||||
|
||||
class Field {
|
||||
class UndoValueUIManager
|
||||
{
|
||||
struct UndoValueUI {
|
||||
// Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
|
||||
const ScalableBitmap* undo_bitmap{ nullptr };
|
||||
const wxString* undo_tooltip{ nullptr };
|
||||
// Bitmap and Tooltip text for m_Undo_to_sys_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
|
||||
const ScalableBitmap* undo_to_sys_bitmap{ nullptr };
|
||||
const wxString* undo_to_sys_tooltip{ nullptr };
|
||||
// Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one.
|
||||
const wxColour* label_color{ nullptr };
|
||||
// State of the blinker icon
|
||||
bool blink{ false };
|
||||
|
||||
bool set_undo_bitmap(const ScalableBitmap* bmp) {
|
||||
if (undo_bitmap != bmp) {
|
||||
undo_bitmap = bmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_undo_to_sys_bitmap(const ScalableBitmap* bmp) {
|
||||
if (undo_to_sys_bitmap != bmp) {
|
||||
undo_to_sys_bitmap = bmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_label_colour(const wxColour* clr) {
|
||||
if (label_color != clr) {
|
||||
label_color = clr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_undo_tooltip(const wxString* tip) {
|
||||
if (undo_tooltip != tip) {
|
||||
undo_tooltip = tip;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_undo_to_sys_tooltip(const wxString* tip) {
|
||||
if (undo_to_sys_tooltip != tip) {
|
||||
undo_to_sys_tooltip = tip;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
UndoValueUI m_undo_ui;
|
||||
|
||||
struct EditValueUI {
|
||||
// Bitmap and Tooltip text for m_Edit_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
|
||||
const ScalableBitmap* bitmap{ nullptr };
|
||||
wxString tooltip { wxEmptyString };
|
||||
|
||||
bool set_bitmap(const ScalableBitmap* bmp) {
|
||||
if (bitmap != bmp) {
|
||||
bitmap = bmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_tooltip(const wxString& tip) {
|
||||
if (tooltip != tip) {
|
||||
tooltip = tip;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
EditValueUI m_edit_ui;
|
||||
|
||||
public:
|
||||
UndoValueUIManager() {}
|
||||
~UndoValueUIManager() {}
|
||||
|
||||
bool set_undo_bitmap(const ScalableBitmap* bmp) { return m_undo_ui.set_undo_bitmap(bmp); }
|
||||
bool set_undo_to_sys_bitmap(const ScalableBitmap* bmp) { return m_undo_ui.set_undo_to_sys_bitmap(bmp); }
|
||||
bool set_label_colour(const wxColour* clr) { return m_undo_ui.set_label_colour(clr); }
|
||||
bool set_undo_tooltip(const wxString* tip) { return m_undo_ui.set_undo_tooltip(tip); }
|
||||
bool set_undo_to_sys_tooltip(const wxString* tip) { return m_undo_ui.set_undo_to_sys_tooltip(tip); }
|
||||
|
||||
bool set_edit_bitmap(const ScalableBitmap* bmp) { return m_edit_ui.set_bitmap(bmp); }
|
||||
bool set_edit_tooltip(const wxString& tip) { return m_edit_ui.set_tooltip(tip); }
|
||||
|
||||
// ui items used for revert line value
|
||||
bool has_undo_ui() const { return m_undo_ui.undo_bitmap != nullptr; }
|
||||
const ScalableBitmap* undo_bitmap() const { return m_undo_ui.undo_bitmap; }
|
||||
const wxString* undo_tooltip() const { return m_undo_ui.undo_tooltip; }
|
||||
const ScalableBitmap* undo_to_sys_bitmap() const { return m_undo_ui.undo_to_sys_bitmap; }
|
||||
const wxString* undo_to_sys_tooltip() const { return m_undo_ui.undo_to_sys_tooltip; }
|
||||
const wxColour* label_color() const { return m_undo_ui.label_color; }
|
||||
|
||||
// Extentions
|
||||
|
||||
// Search blinker
|
||||
const bool blink() const { return m_undo_ui.blink; }
|
||||
bool* get_blink_ptr() { return &m_undo_ui.blink; }
|
||||
|
||||
// Edit field button
|
||||
bool has_edit_ui() const { return !m_edit_ui.tooltip.IsEmpty(); }
|
||||
const wxBitmapBundle* edit_bitmap() const { return &m_edit_ui.bitmap->bmp(); }
|
||||
const wxString* edit_tooltip() const { return &m_edit_ui.tooltip; }
|
||||
};
|
||||
|
||||
class Field : public UndoValueUIManager {
|
||||
protected:
|
||||
// factory function to defer and enforce creation of derived type.
|
||||
virtual void PostInitialize();
|
||||
|
@ -139,49 +252,6 @@ public:
|
|||
return std::move(p); //!p;
|
||||
}
|
||||
|
||||
bool set_undo_bitmap(const ScalableBitmap *bmp) {
|
||||
if (m_undo_bitmap != bmp) {
|
||||
m_undo_bitmap = bmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_undo_to_sys_bitmap(const ScalableBitmap *bmp) {
|
||||
if (m_undo_to_sys_bitmap != bmp) {
|
||||
m_undo_to_sys_bitmap = bmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_label_colour(const wxColour *clr) {
|
||||
if (m_label_color != clr) {
|
||||
m_label_color = clr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_undo_tooltip(const wxString *tip) {
|
||||
if (m_undo_tooltip != tip) {
|
||||
m_undo_tooltip = tip;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set_undo_to_sys_tooltip(const wxString *tip) {
|
||||
if (m_undo_to_sys_tooltip != tip) {
|
||||
m_undo_to_sys_tooltip = tip;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool* get_blink_ptr() {
|
||||
return &m_blink;
|
||||
}
|
||||
|
||||
virtual void msw_rescale();
|
||||
virtual void sys_color_changed();
|
||||
|
||||
|
@ -193,27 +263,9 @@ public:
|
|||
static int def_width_wider() ;
|
||||
static int def_width_thinner() ;
|
||||
|
||||
const ScalableBitmap* undo_bitmap() { return m_undo_bitmap; }
|
||||
const wxString* undo_tooltip() { return m_undo_tooltip; }
|
||||
const ScalableBitmap* undo_to_sys_bitmap() { return m_undo_to_sys_bitmap; }
|
||||
const wxString* undo_to_sys_tooltip() { return m_undo_to_sys_tooltip; }
|
||||
const wxColour* label_color() { return m_label_color; }
|
||||
const bool blink() { return m_blink; }
|
||||
const bool combine_side_text() { return m_combine_side_text; } // BBS: new param style
|
||||
|
||||
protected:
|
||||
// Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
|
||||
const ScalableBitmap* m_undo_bitmap = nullptr;
|
||||
const wxString* m_undo_tooltip = nullptr;
|
||||
// Bitmap and Tooltip text for m_Undo_to_sys_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
|
||||
const ScalableBitmap* m_undo_to_sys_bitmap = nullptr;
|
||||
const wxString* m_undo_to_sys_tooltip = nullptr;
|
||||
|
||||
bool m_blink{ false };
|
||||
|
||||
// Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one.
|
||||
const wxColour* m_label_color = nullptr;
|
||||
|
||||
// current value
|
||||
boost::any m_value;
|
||||
// last maeningful value
|
||||
|
|
|
@ -195,7 +195,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
|
|||
|
||||
if (line.widget) {
|
||||
#ifndef DISABLE_BLINKING
|
||||
h_pos += blinking_button_width;
|
||||
h_pos += (line.has_undo_ui() ? 3 : 1) * blinking_button_width;
|
||||
#endif
|
||||
|
||||
for (auto child : line.widget_sizer->GetChildren())
|
||||
|
@ -761,7 +761,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord h_pos, wxCoord v_pos)
|
|||
wxColour blink_color = StateColor::darkModeColorFor("#009688");
|
||||
bool is_url_string = false;
|
||||
if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) {
|
||||
const wxColour* text_clr = field ? field->label_color() : og_line.full_Label_color;
|
||||
const wxColour* text_clr = field ? field->label_color() : og_line.label_color();
|
||||
for (const Option& opt : option_set) {
|
||||
Field* field = ctrl->opt_group->get_field(opt.opt_id);
|
||||
if (field && field->blink()) {
|
||||
|
|
|
@ -210,7 +210,7 @@ void OptionsGroup::append_line(const Line& line)
|
|||
m_options_mode.push_back(option_set[0].opt.mode);
|
||||
}
|
||||
|
||||
//BBS: get line for opt_key
|
||||
/*//BBS: get line for opt_key
|
||||
Line* OptionsGroup::get_line(const std::string& opt_key)
|
||||
{
|
||||
for (auto& l : m_lines)
|
||||
|
@ -222,7 +222,7 @@ Line* OptionsGroup::get_line(const std::string& opt_key)
|
|||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}*/
|
||||
|
||||
void OptionsGroup::append_separator()
|
||||
{
|
||||
|
@ -678,6 +678,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config,
|
|||
opt_key == "thumbnails" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") {
|
||||
value = get_config_value(config, opt_key);
|
||||
this->change_opt_value(opt_key, value);
|
||||
OptionsGroup::on_change_OG(opt_key, value);
|
||||
return;
|
||||
} else {
|
||||
auto opt_id = m_opt_map.find(opt_key)->first;
|
||||
|
|
|
@ -48,7 +48,8 @@ struct Option {
|
|||
using t_option = std::unique_ptr<Option>; //!
|
||||
|
||||
/// Represents option lines
|
||||
class Line {
|
||||
class Line : public UndoValueUIManager
|
||||
{
|
||||
bool m_is_separator{ false };
|
||||
public:
|
||||
wxString label;
|
||||
|
@ -58,8 +59,6 @@ public:
|
|||
bool toggle_visible{true}; // BBS: hide some line
|
||||
|
||||
size_t full_width {0};
|
||||
wxColour* full_Label_color {nullptr};
|
||||
bool blink {false};
|
||||
widget_t widget {nullptr};
|
||||
std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr };
|
||||
wxWindow* near_label_widget_win {nullptr};
|
||||
|
@ -83,10 +82,10 @@ public:
|
|||
Line() : m_is_separator(true) {}
|
||||
|
||||
bool is_separator() const { return m_is_separator; }
|
||||
bool has_only_option(const std::string& opt_key) const { return m_options.size() == 1 && m_options[0].opt_id == opt_key; }
|
||||
|
||||
const std::vector<widget_t>& get_extra_widgets() const {return m_extra_widgets;}
|
||||
const std::vector<Option>& get_options() const { return m_options; }
|
||||
bool* get_blink_ptr() { return &blink; }
|
||||
|
||||
private:
|
||||
std::vector<Option> m_options;//! {std::vector<Option>()};
|
||||
|
@ -139,7 +138,7 @@ public:
|
|||
// create controls for the option group
|
||||
void activate_line(Line& line);
|
||||
//BBS: get line for opt_key
|
||||
Line* get_line(const std::string& opt_key);
|
||||
// Line* get_line(const std::string& opt_key);
|
||||
|
||||
// create all controls for the option group from the m_lines
|
||||
bool activate(std::function<void()> throw_if_canceled = [](){}, int horiz_alignment = wxALIGN_LEFT);
|
||||
|
@ -155,6 +154,14 @@ public:
|
|||
if (m_fields.find(id) == m_fields.end()) return nullptr;
|
||||
return m_fields.at(id).get();
|
||||
}
|
||||
|
||||
inline Line* get_line(const t_config_option_key& id) {
|
||||
for (Line& line : m_lines)
|
||||
if (line.has_only_option(id))
|
||||
return &line;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool set_value(const t_config_option_key& id, const boost::any& value, bool change_event = false) {
|
||||
if (m_fields.find(id) == m_fields.end()) return false;
|
||||
m_fields.at(id)->set_value(value, change_event);
|
||||
|
|
|
@ -717,8 +717,8 @@ void Tab::update_label_colours()
|
|||
}
|
||||
if (opt.first == "printable_area" ||
|
||||
opt.first == "compatible_prints" || opt.first == "compatible_printers" ) {
|
||||
if (m_colored_Label_colors.find(opt.first) != m_colored_Label_colors.end())
|
||||
m_colored_Label_colors.at(opt.first) = *color;
|
||||
if (Line* line = get_line(opt.first))
|
||||
line->set_label_colour(color);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -757,13 +757,13 @@ void Tab::decorate()
|
|||
for (const auto& opt : m_options_list)
|
||||
{
|
||||
Field* field = nullptr;
|
||||
wxColour* colored_label_clr = nullptr;
|
||||
bool option_without_field = false;
|
||||
|
||||
if (opt.first == "printable_area" ||
|
||||
opt.first == "compatible_prints" || opt.first == "compatible_printers")
|
||||
colored_label_clr = (m_colored_Label_colors.find(opt.first) == m_colored_Label_colors.end()) ? nullptr : &m_colored_Label_colors.at(opt.first);
|
||||
option_without_field = true;
|
||||
|
||||
if (!colored_label_clr) {
|
||||
if (!option_without_field) {
|
||||
field = get_field(opt.first);
|
||||
if (!field)
|
||||
continue;
|
||||
|
@ -798,8 +798,14 @@ void Tab::decorate()
|
|||
tt = &m_tt_white_bullet;
|
||||
}
|
||||
|
||||
if (colored_label_clr) {
|
||||
*colored_label_clr = *color;
|
||||
if (option_without_field) {
|
||||
if (Line* line = get_line(opt.first)) {
|
||||
line->set_undo_bitmap(icon);
|
||||
line->set_undo_to_sys_bitmap(sys_icon);
|
||||
line->set_undo_tooltip(tt);
|
||||
line->set_undo_to_sys_tooltip(sys_tt);
|
||||
line->set_label_colour(color);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1079,7 +1085,7 @@ void Tab::on_roll_back_value(const bool to_sys /*= true*/)
|
|||
|
||||
m_postpone_update_ui = false;
|
||||
|
||||
// When all values are rolled, then we hane to update whole tab in respect to the reverted values
|
||||
// When all values are rolled, then we have to update whole tab in respect to the reverted values
|
||||
update();
|
||||
|
||||
// BBS: restore all pages in preset, update_dirty also update combobox
|
||||
|
@ -1261,6 +1267,11 @@ Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/
|
|||
return m_active_page ? m_active_page->get_field(opt_key, opt_index) : nullptr;
|
||||
}
|
||||
|
||||
Line* Tab::get_line(const t_config_option_key& opt_key)
|
||||
{
|
||||
return m_active_page ? m_active_page->get_line(opt_key) : nullptr;
|
||||
}
|
||||
|
||||
std::pair<OG_CustomCtrl*, bool*> Tab::get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index/* = -1*/)
|
||||
{
|
||||
if (!m_active_page)
|
||||
|
@ -5279,8 +5290,12 @@ void Tab::create_line_with_widget(ConfigOptionsGroup* optgroup, const std::strin
|
|||
line.widget = widget;
|
||||
line.label_path = path;
|
||||
|
||||
m_colored_Label_colors[opt_key] = m_default_text_clr;
|
||||
line.full_Label_color = &m_colored_Label_colors[opt_key];
|
||||
// set default undo ui
|
||||
line.set_undo_bitmap(&m_bmp_white_bullet);
|
||||
line.set_undo_to_sys_bitmap(&m_bmp_white_bullet);
|
||||
line.set_undo_tooltip(&m_tt_white_bullet);
|
||||
line.set_undo_to_sys_tooltip(&m_tt_white_bullet);
|
||||
line.set_label_colour(&m_default_text_clr);
|
||||
|
||||
optgroup->append_line(line);
|
||||
}
|
||||
|
@ -5638,12 +5653,10 @@ Field *Page::get_field(const t_config_option_key &opt_key, int opt_index /*= -1*
|
|||
|
||||
Line *Page::get_line(const t_config_option_key &opt_key)
|
||||
{
|
||||
Line *line = nullptr;
|
||||
for (auto opt : m_optgroups) {
|
||||
line = opt->get_line(opt_key);
|
||||
if (line != nullptr) return line;
|
||||
}
|
||||
return line;
|
||||
for (auto opt : m_optgroups)
|
||||
if (Line* line = opt->get_line(opt_key))
|
||||
return line;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Page::set_value(const t_config_option_key &opt_key, const boost::any &value)
|
||||
|
|
|
@ -369,6 +369,7 @@ public:
|
|||
virtual void msw_rescale();
|
||||
virtual void sys_color_changed();
|
||||
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
|
||||
Line* get_line(const t_config_option_key& opt_key);
|
||||
std::pair<OG_CustomCtrl*, bool*> get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index = -1);
|
||||
|
||||
Field* get_field(const t_config_option_key &opt_key, Page** selected_page, int opt_index = -1);
|
||||
|
|
Loading…
Reference in a new issue