Draw popup confirm/cancel rows with one helper
popup_buttons_draw takes its labels, tooltips and enabled state as a struct. Three hand-written rows use it.
This commit is contained in:
1 parent
8d3ebf2329
commit
a9177b13d0
9 files changed
+50
-62
No files matched your search
@@ -529,9 +529,10 @@ static void animations_merge_popup_update(Panel& panel, AnimationsPanel& animati
|
|||||||
ImGui::Checkbox(localize.get(LABEL_DELETE_ANIMATIONS_AFTER), &settings.mergeIsDeleteAnimationsAfter);
|
ImGui::Checkbox(localize.get(LABEL_DELETE_ANIMATIONS_AFTER), &settings.mergeIsDeleteAnimationsAfter);
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto result =
|
auto result = popup_buttons_draw(
|
||||||
popup_buttons_draw(manager, localize.get(LABEL_MERGE),
|
manager, {.confirm = LABEL_MERGE,
|
||||||
!animation_merge_indices_get(document, mergeSelection, mergeReference).empty(), LABEL_CLOSE);
|
.cancel = LABEL_CLOSE,
|
||||||
|
.isConfirmEnabled = !animation_merge_indices_get(document, mergeSelection, mergeReference).empty()});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
command_push(
|
command_push(
|
||||||
panel, [options = AnimationMergeOptions{.selection = mergeSelection,
|
panel, [options = AnimationMergeOptions{.selection = mergeSelection,
|
||||||
|
|||||||
@@ -150,11 +150,11 @@ bool ItemProperties::update(Manager& manager, Settings& settings, Document& docu
|
|||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto widgetSize = widget_size_with_row_get(2);
|
auto result = popup_buttons_draw(manager, {.confirm = BASIC_ADD,
|
||||||
|
.confirmTooltip = TOOLTIP_ADD_ITEM,
|
||||||
ImGui::BeginDisabled(source == SOURCE_EXISTING && edit.id == -1);
|
.cancelTooltip = TOOLTIP_CANCEL_ADD_ITEM,
|
||||||
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
.isConfirmEnabled = source != SOURCE_EXISTING || edit.id != -1});
|
||||||
if (ImGui::Button(localize.get(BASIC_ADD), widgetSize))
|
if (result == PopupButton::CONFIRM)
|
||||||
{
|
{
|
||||||
auto queuedType = type;
|
auto queuedType = type;
|
||||||
auto queuedDestination = destination;
|
auto queuedDestination = destination;
|
||||||
@@ -185,17 +185,9 @@ bool ItemProperties::update(Manager& manager, Settings& settings, Document& docu
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
isAdded = true;
|
isAdded = true;
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
if (result != PopupButton::NONE)
|
||||||
tooltip_set(TOOLTIP_ADD_ITEM);
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
|
||||||
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize))
|
|
||||||
close();
|
close();
|
||||||
tooltip_set(TOOLTIP_CANCEL_ADD_ITEM);
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@ void item_properties_update(Panel& panel, int popupIndex, int rows, SelectionKin
|
|||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto result = popup_buttons_draw(manager, localize.get(edit.id == -1 ? BASIC_ADD : BASIC_CONFIRM));
|
auto result = popup_buttons_draw(manager, {.confirm = edit.id == -1 ? BASIC_ADD : BASIC_CONFIRM});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
{
|
{
|
||||||
Item item = {};
|
Item item = {};
|
||||||
|
|||||||
+9
-6
@@ -424,7 +424,7 @@ static void content_remove_popup_draw(Panel& panel)
|
|||||||
ImGui::BulletText("%s", localize_format(FORMAT_REMOVE_MORE, (int)(lines.size() - REMOVE_LINES_MAX)).c_str());
|
ImGui::BulletText("%s", localize_format(FORMAT_REMOVE_MORE, (int)(lines.size() - REMOVE_LINES_MAX)).c_str());
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
ImGui::TextUnformatted(localize.get(TEXT_REMOVE_CONFIRM));
|
ImGui::TextUnformatted(localize.get(TEXT_REMOVE_CONFIRM));
|
||||||
auto result = popup_buttons_draw(panel.manager, localize.get(BASIC_REMOVE));
|
auto result = popup_buttons_draw(panel.manager, {.confirm = BASIC_REMOVE});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
content_remove_apply(panel);
|
content_remove_apply(panel);
|
||||||
if (result != PopupButton::NONE)
|
if (result != PopupButton::NONE)
|
||||||
@@ -521,21 +521,24 @@ void directory_open(Dialog& dialog, Document& document, const std::filesystem::p
|
|||||||
dialog.file_explorer_open(target);
|
dialog.file_explorer_open(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupButton popup_buttons_draw(Manager& manager, const char* confirmLabel, bool isConfirmEnabled,
|
PopupButton popup_buttons_draw(Manager& manager, const PopupButtons& buttons)
|
||||||
StringType cancelLabel)
|
|
||||||
{
|
{
|
||||||
auto widgetSize = widget_size_with_row_get(2);
|
auto widgetSize = widget_size_with_row_get(2);
|
||||||
auto result = PopupButton::NONE;
|
auto result = PopupButton::NONE;
|
||||||
|
|
||||||
ImGui::BeginDisabled(!isConfirmEnabled);
|
ImGui::BeginDisabled(!buttons.isConfirmEnabled);
|
||||||
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
||||||
if (ImGui::Button(confirmLabel, widgetSize))
|
if (ImGui::Button(localize.get(buttons.confirm), widgetSize))
|
||||||
result = PopupButton::CONFIRM;
|
result = PopupButton::CONFIRM;
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
if (buttons.confirmTooltip != STRING_UNDEFINED)
|
||||||
|
tooltip_set(buttons.confirmTooltip);
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
||||||
if (ImGui::Button(localize.get(cancelLabel), widgetSize))
|
if (ImGui::Button(localize.get(buttons.cancel), widgetSize))
|
||||||
result = PopupButton::CANCEL;
|
result = PopupButton::CANCEL;
|
||||||
|
if (buttons.cancelTooltip != STRING_UNDEFINED)
|
||||||
|
tooltip_set(buttons.cancelTooltip);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
+11
-1
@@ -111,7 +111,17 @@ void tooltip_name_draw(Resources&, const std::string&);
|
|||||||
void tooltip_image_draw(const CardImage&, const std::function<void()>&);
|
void tooltip_image_draw(const CardImage&, const std::function<void()>&);
|
||||||
void directory_open(Dialog&, Document&, const std::filesystem::path&);
|
void directory_open(Dialog&, Document&, const std::filesystem::path&);
|
||||||
std::filesystem::path asset_path_get(Document&, const std::filesystem::path&);
|
std::filesystem::path asset_path_get(Document&, const std::filesystem::path&);
|
||||||
PopupButton popup_buttons_draw(Manager&, const char*, bool = true, StringType = BASIC_CANCEL);
|
// The confirm and cancel buttons that end a popup, side by side, on the confirm and cancel shortcuts.
|
||||||
|
struct PopupButtons
|
||||||
|
{
|
||||||
|
StringType confirm = BASIC_CONFIRM;
|
||||||
|
StringType cancel = BASIC_CANCEL;
|
||||||
|
StringType confirmTooltip = STRING_UNDEFINED;
|
||||||
|
StringType cancelTooltip = STRING_UNDEFINED;
|
||||||
|
bool isConfirmEnabled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
PopupButton popup_buttons_draw(Manager&, const PopupButtons&);
|
||||||
void content_remove_action_add(Actions&, Panel&, ElementType, SelectionKind, int = -1);
|
void content_remove_action_add(Actions&, Panel&, ElementType, SelectionKind, int = -1);
|
||||||
|
|
||||||
struct SpritesheetsPanel
|
struct SpritesheetsPanel
|
||||||
|
|||||||
+2
-2
@@ -286,7 +286,7 @@ static void region_properties_popup_update(Panel& panel, RegionsPanel& regions)
|
|||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto result = popup_buttons_draw(panel.manager, localize.get(regions.editId == -1 ? BASIC_ADD : BASIC_CONFIRM));
|
auto result = popup_buttons_draw(panel.manager, {.confirm = regions.editId == -1 ? BASIC_ADD : BASIC_CONFIRM});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
{
|
{
|
||||||
auto& state = panel.state;
|
auto& state = panel.state;
|
||||||
@@ -368,7 +368,7 @@ static void region_export_popup_update(Panel& panel, RegionsPanel& regions)
|
|||||||
auto texture = document.texture_get(spritesheetId);
|
auto texture = document.texture_get(spritesheetId);
|
||||||
auto isValid = region && texture && texture->is_valid() && !texture->pixels.empty() &&
|
auto isValid = region && texture && texture->is_valid() && !texture->pixels.empty() &&
|
||||||
(settings.isExportRegionMakeSpritesheet || !settings.exportRegionPath.empty());
|
(settings.isExportRegionMakeSpritesheet || !settings.exportRegionPath.empty());
|
||||||
auto result = popup_buttons_draw(manager, localize.get(BASIC_CONFIRM), isValid);
|
auto result = popup_buttons_draw(manager, {.confirm = BASIC_CONFIRM, .isConfirmEnabled = isValid});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
{
|
{
|
||||||
if (!settings.exportRegionPath.empty())
|
if (!settings.exportRegionPath.empty())
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ static void spritesheets_merge_popup_update(Panel& panel, SpritesheetsPanel& spr
|
|||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto result = popup_buttons_draw(manager, localize.get(BASIC_MERGE), spritesheets.mergeIds.size() > 1);
|
auto result =
|
||||||
|
popup_buttons_draw(manager, {.confirm = BASIC_MERGE, .isConfirmEnabled = spritesheets.mergeIds.size() > 1});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
command_push(panel,
|
command_push(panel,
|
||||||
[ids = spritesheets.mergeIds, isAppendRight = settings.mergeSpritesheetsOrigin == APPEND_RIGHT,
|
[ids = spritesheets.mergeIds, isAppendRight = settings.mergeSpritesheetsOrigin == APPEND_RIGHT,
|
||||||
@@ -187,8 +188,8 @@ static void spritesheets_pack_popup_update(Panel& panel, SpritesheetsPanel& spri
|
|||||||
ImGui::DragInt(localize.get(LABEL_PACK_PADDING), &settings.packPadding, DRAG_SPEED, 0, PADDING_MAX);
|
ImGui::DragInt(localize.get(LABEL_PACK_PADDING), &settings.packPadding, DRAG_SPEED, 0, PADDING_MAX);
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto result =
|
auto result = popup_buttons_draw(
|
||||||
popup_buttons_draw(manager, localize.get(BASIC_PACK), is_spritesheet_regions(document, spritesheets.packId));
|
manager, {.confirm = BASIC_PACK, .isConfirmEnabled = is_spritesheet_regions(document, spritesheets.packId)});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
command_push(panel, [id = spritesheets.packId, padding = settings.packPadding](Document& document) {
|
command_push(panel, [id = spritesheets.packId, padding = settings.packPadding](Document& document) {
|
||||||
spritesheet_textures_edit(
|
spritesheet_textures_edit(
|
||||||
@@ -208,7 +209,7 @@ static void spritesheets_overwrite_popup_update(Panel& panel, SpritesheetsPanel&
|
|||||||
return popup.end();
|
return popup.end();
|
||||||
|
|
||||||
ImGui::TextUnformatted(localize.get(LABEL_OVERWRITE_CONFIRMATION));
|
ImGui::TextUnformatted(localize.get(LABEL_OVERWRITE_CONFIRMATION));
|
||||||
auto result = popup_buttons_draw(panel.manager, localize.get(BASIC_YES), true, BASIC_NO);
|
auto result = popup_buttons_draw(panel.manager, {.confirm = BASIC_YES, .cancel = BASIC_NO});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
command_push(panel, [ids = spritesheets.saveIds](Document& document) { spritesheets_save(document, ids); });
|
command_push(panel, [ids = spritesheets.saveIds](Document& document) { spritesheets_save(document, ids); });
|
||||||
if (result != PopupButton::NONE)
|
if (result != PopupButton::NONE)
|
||||||
|
|||||||
+11
-30
@@ -70,7 +70,7 @@ void TimelineContext::popups_update()
|
|||||||
input_text_string(localize.get(LABEL_FORMAT), &settings.generateRegionNameFormat);
|
input_text_string(localize.get(LABEL_FORMAT), &settings.generateRegionNameFormat);
|
||||||
ImGui::Checkbox(localize.get(LABEL_MAP_FRAMES_TO_REGIONS), &isMakeManyRegionsMapFrames);
|
ImGui::Checkbox(localize.get(LABEL_MAP_FRAMES_TO_REGIONS), &isMakeManyRegionsMapFrames);
|
||||||
|
|
||||||
auto result = popup_buttons_draw(manager, localize.get(LABEL_MAKE_MANY_REGIONS));
|
auto result = popup_buttons_draw(manager, {.confirm = LABEL_MAKE_MANY_REGIONS});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
edit_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS,
|
edit_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS,
|
||||||
[targetFrames = makeManyRegionReferences, format = settings.generateRegionNameFormat,
|
[targetFrames = makeManyRegionReferences, format = settings.generateRegionNameFormat,
|
||||||
@@ -101,22 +101,13 @@ void TimelineContext::popups_update()
|
|||||||
ImGui::Checkbox(localize.get(LABEL_ROUND_SCALE), &isRoundScale);
|
ImGui::Checkbox(localize.get(LABEL_ROUND_SCALE), &isRoundScale);
|
||||||
tooltip_set(TOOLTIP_ROUND_SCALE);
|
tooltip_set(TOOLTIP_ROUND_SCALE);
|
||||||
|
|
||||||
auto widgetSize = widget_size_with_row_get(2);
|
auto result = popup_buttons_draw(manager, {.confirm = LABEL_BAKE,
|
||||||
|
.confirmTooltip = TOOLTIP_BAKE_FRAMES_OPTIONS,
|
||||||
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
.cancelTooltip = TOOLTIP_CANCEL_BAKE_FRAMES});
|
||||||
if (ImGui::Button(localize.get(LABEL_BAKE), widgetSize))
|
if (result == PopupButton::CONFIRM)
|
||||||
{
|
|
||||||
frames_bake();
|
frames_bake();
|
||||||
|
if (result != PopupButton::NONE)
|
||||||
bakePopup.close();
|
bakePopup.close();
|
||||||
}
|
|
||||||
tooltip_set(TOOLTIP_BAKE_FRAMES_OPTIONS);
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
|
||||||
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize))
|
|
||||||
bakePopup.close();
|
|
||||||
tooltip_set(TOOLTIP_CANCEL_BAKE_FRAMES);
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
@@ -155,23 +146,13 @@ void TimelineContext::popups_update()
|
|||||||
ImGui::Checkbox(localize.get(LABEL_BAKE_USE_ROOT_PIVOT), &isUseRootPivot);
|
ImGui::Checkbox(localize.get(LABEL_BAKE_USE_ROOT_PIVOT), &isUseRootPivot);
|
||||||
tooltip_set(TOOLTIP_BAKE_USE_ROOT_PIVOT);
|
tooltip_set(TOOLTIP_BAKE_USE_ROOT_PIVOT);
|
||||||
|
|
||||||
auto widgetSize = widget_size_with_row_get(2);
|
auto result = popup_buttons_draw(manager, {.confirm = LABEL_BAKE,
|
||||||
|
.cancelTooltip = TOOLTIP_CANCEL_BAKE_FRAMES,
|
||||||
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
.isConfirmEnabled = is_bake_into_other_frames_ready()});
|
||||||
ImGui::BeginDisabled(!is_bake_into_other_frames_ready());
|
if (result == PopupButton::CONFIRM)
|
||||||
if (ImGui::Button(localize.get(LABEL_BAKE), widgetSize))
|
|
||||||
{
|
|
||||||
bake_into_other_frames();
|
bake_into_other_frames();
|
||||||
|
if (result != PopupButton::NONE)
|
||||||
bakeIntoOtherFramesPopup.close();
|
bakeIntoOtherFramesPopup.close();
|
||||||
}
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
|
||||||
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize))
|
|
||||||
bakeIntoOtherFramesPopup.close();
|
|
||||||
tooltip_set(TOOLTIP_CANCEL_BAKE_FRAMES);
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ void TimelineContext::group_properties_update()
|
|||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
auto result = popup_buttons_draw(manager, localize.get(BASIC_CONFIRM));
|
auto result = popup_buttons_draw(manager, {.confirm = BASIC_CONFIRM});
|
||||||
if (result == PopupButton::CONFIRM)
|
if (result == PopupButton::CONFIRM)
|
||||||
{
|
{
|
||||||
auto targetName = groupName;
|
auto targetName = groupName;
|
||||||
|
|||||||
Reference in new issue
Block a user