Skip to content

Commit

Permalink
Move layer actions into a context menu
Browse files Browse the repository at this point in the history
So that we don't waste too much space for buttons that are not usually
needed.
  • Loading branch information
guillaumechereau committed Jun 22, 2024
1 parent 3203eb2 commit 89599f7
Show file tree
Hide file tree
Showing 7 changed files with 1,540 additions and 1,534 deletions.
Binary file modified data/images/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,945 changes: 1,446 additions & 1,499 deletions src/assets/images.inl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ enum {
X(ICON_CLOUD, 1, 4, 0),
X(ICON_SHAPE, 2, 4, 0),
X(ICON_CLOSE, 3, 4, 0),
X(ICON_THREE_DOTS, 4, 4, 0),

X(ICON_TOOLS, 0, 5, THEME_GROUP_ICON_EDIT),
X(ICON_PALETTE, 1, 5, THEME_GROUP_ICON_EDIT),
Expand Down
35 changes: 34 additions & 1 deletion src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ typedef struct gui_t {
int is_row;
float item_size;

bool is_context_menu;
int context_menu_row;

int win_dir; // Store the current window direction (for scrolling).

struct {
Expand Down Expand Up @@ -1324,7 +1327,12 @@ bool gui_button(const char *label, float size, int icon)
center + ImVec2(isize, isize),
uv0, uv1, get_icon_color(icon, 0));
}
if (ret) on_click();
if (ret) {
on_click();
if (gui->is_context_menu) {
ImGui::CloseCurrentPopup();
}
}
if (gui->is_row) ImGui::SameLine();
return ret;
}
Expand Down Expand Up @@ -1857,3 +1865,28 @@ bool gui_want_capture_mouse(void)
ImGuiIO& io = ImGui::GetIO();
return io.WantCaptureMouse;
}

bool gui_context_menu_begin(const char *label)
{
if (!ImGui::BeginPopupContextItem(label)) return false;
gui->is_context_menu = true;
gui->context_menu_row = gui->is_row;
gui->is_row = 0;
gui_group_begin(NULL);
return true;
}

void gui_context_menu_end(void)
{
gui_group_end();
ImGui::EndPopup();
gui->is_context_menu = false;
gui->is_row = gui->context_menu_row;
}

void gui_context_menu_button(const char *label, int icon)
{
if (gui_button(label, 0, icon)) {
ImGui::OpenPopup(label);
}
}
7 changes: 7 additions & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,11 @@ void gui_tooltip(const char *str);

bool gui_view_cube(float x, float y, float w, float h);

/*
* Support for context menu popup (like the one on layers).
*/
bool gui_context_menu_begin(const char *label);
void gui_context_menu_end(void);
void gui_context_menu_button(const char *label, int icon);

#endif // GUI_H
65 changes: 40 additions & 25 deletions src/gui/layers_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,39 @@ static const char *get_mode_name(int mode)
}
}

static void layers_context_menu(void)
{
layer_t *layer;
bool bounded;
char buf[256];

gui_action_button(ACTION_img_duplicate_layer, _(DUPLICATE), 1);
gui_action_button(ACTION_img_clone_layer, _(CLONE), 1);
gui_action_button(ACTION_img_merge_layer_down, _(MERGE_DOWN), 1);
gui_action_button(ACTION_img_merge_visible_layers, _(MERGE_VISIBLE), 1);

layer = goxel.image->active_layer;
bounded = !box_is_null(layer->box);

if (bounded && gui_button(_(CROP), 1, 0)) {
volume_crop(layer->volume, layer->box);
}
if (!box_is_null(goxel.image->box)) {
snprintf(buf, sizeof(buf), "%s: %s", _(CROP), _(IMAGE));
if (gui_button(buf, 1, 0))
volume_crop(layer->volume, goxel.image->box);
}
if (layer->shape) {
snprintf(buf, sizeof(buf), "▶ %s", _(VOLUME));
gui_action_button(ACTION_img_unclone_layer, buf, 1);
}

snprintf(buf, sizeof(buf), "%s: %s", _(ADD), _(SHAPE));
if (gui_action_button(ACTION_img_new_shape_layer, buf, 1)) {
action_exec2(ACTION_tool_set_move);
}
}

void gui_layers_panel(void)
{
layer_t *layer;
Expand Down Expand Up @@ -87,35 +120,17 @@ void gui_layers_panel(void)
gui_action_button(ACTION_img_del_layer, NULL, 0);
gui_action_button(ACTION_img_move_layer_up, NULL, 0);
gui_action_button(ACTION_img_move_layer_down, NULL, 0);
gui_row_end();

gui_group_begin(NULL);
gui_action_button(ACTION_img_duplicate_layer, _(DUPLICATE), 1);
gui_action_button(ACTION_img_clone_layer, _(CLONE), 1);
gui_action_button(ACTION_img_merge_layer_down, _(MERGE_DOWN), 1);
gui_action_button(ACTION_img_merge_visible_layers, _(MERGE_VISIBLE), 1);

layer = goxel.image->active_layer;
bounded = !box_is_null(layer->box);
if (bounded && gui_button(_(CROP), 1, 0)) {
volume_crop(layer->volume, layer->box);
}
if (!box_is_null(goxel.image->box)) {
snprintf(buf, sizeof(buf), "%s: %s", _(CROP), _(IMAGE));
if (gui_button(buf, 1, 0))
volume_crop(layer->volume, goxel.image->box);
}
if (layer->shape) {
snprintf(buf, sizeof(buf), "▶ %s", _(VOLUME));
gui_action_button(ACTION_img_unclone_layer, buf, 1);
if (gui_context_menu_begin("##Actions")) {
layers_context_menu();
gui_context_menu_end();
}
gui_context_menu_button("##Actions", ICON_THREE_DOTS);

snprintf(buf, sizeof(buf), "%s: %s", _(ADD), _(SHAPE));
if (gui_action_button(ACTION_img_new_shape_layer, buf, 1)) {
action_exec2(ACTION_tool_set_move);
}
gui_row_end();

gui_group_end();
layer = goxel.image->active_layer;
bounded = !box_is_null(layer->box);

if (layer->base_id) {
gui_group_begin(NULL);
Expand Down
21 changes: 12 additions & 9 deletions svg/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89599f7

Please sign in to comment.