When create new text object discard style changes

Fix style issue 15
This commit is contained in:
Filip Sykala - NTB T15p 2022-07-26 10:23:27 +02:00
parent 5558523b19
commit 1bdc291dba
2 changed files with 50 additions and 46 deletions

View File

@ -166,7 +166,9 @@ void GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mous
volume_type == ModelVolumeType::NEGATIVE_VOLUME ||
volume_type == ModelVolumeType::PARAMETER_MODIFIER);
if (!m_gui_cfg.has_value()) initialize();
set_default_text();
discard_changes_in_style();
Vec2d screen_coor = mouse_pos;
if (mouse_pos.x() < 0 || mouse_pos.y() < 0) {
@ -1616,10 +1618,8 @@ void GLGizmoEmboss::draw_delete_style_button() {
}
}
void GLGizmoEmboss::draw_undo_style_button(bool is_stored, bool is_changed)
void GLGizmoEmboss::discard_changes_in_style()
{
bool can_undo = is_stored && is_changed;
if (draw_button(IconType::undo, !can_undo)) {
FontItem &font_item = m_font_manager.get_font_item();
bool is_path_changed = font_item.path != m_stored_font_item->path;
@ -1658,15 +1658,6 @@ void GLGizmoEmboss::draw_undo_style_button(bool is_stored, bool is_changed)
m_font_manager.get_wx_font() = WxFontUtils::load_wxFont(font_item.path);
m_font_manager.wx_font_changed();
}
process();
} else if (ImGui::IsItemHovered()) {
if (can_undo)
ImGui::SetTooltip("%s", _u8L("Reload stored values of selected style").c_str());
else if (!is_stored)
ImGui::SetTooltip("%s", _u8L("Nothing to reload from").c_str());
else if (!is_changed)
ImGui::SetTooltip("%s", _u8L("No change to restore from style").c_str());
}
}
void GLGizmoEmboss::draw_revert_all_styles_button() {
@ -1764,6 +1755,7 @@ void GLGizmoEmboss::draw_style_list() {
bool is_changed = (is_stored) ? !(*m_stored_font_item == font_item) : true;
// TODO: check order of font items in list to allowe save actual order
// save button
ImGui::SameLine();
if (draw_button(IconType::save, !is_changed)) {
// save styles to app config
@ -1776,8 +1768,20 @@ void GLGizmoEmboss::draw_style_list() {
}
}
// undo button
ImGui::SameLine();
draw_undo_style_button(is_stored, is_changed);
bool can_undo = is_stored && is_changed;
if (draw_button(IconType::undo, !can_undo)) {
discard_changes_in_style();
process();
} else if (ImGui::IsItemHovered()) {
if (can_undo)
ImGui::SetTooltip("%s", _u8L("Reload stored values of selected style").c_str());
else if (!is_stored)
ImGui::SetTooltip("%s", _u8L("Nothing to reload from").c_str());
else if (!is_changed)
ImGui::SetTooltip("%s", _u8L("No change to restore from style").c_str());
}
#ifdef ALLOW_REVERT_ALL_STYLES
ImGui::SameLine();

View File

@ -101,7 +101,7 @@ private:
void draw_model_type();
void draw_style_list();
void draw_delete_style_button();
void draw_undo_style_button(bool is_stored, bool is_changed);
void discard_changes_in_style();
void draw_revert_all_styles_button();
void draw_rename_style_botton();
void draw_font_list();