tools: add icons to move and restore on-canvas text editor position

This commit adds a button inside the on-canvas text editor
that restores the editor to its original position after it has
been moved. The button is only visible when the editor has been
moved, and disappears when it returns to its default position.
It also adds an icon to indicate that the editor can be moved.
This commit is contained in:
Gabriele Barbero 2025-06-14 18:20:03 +02:00
parent 17edeb355d
commit d08c690769
6 changed files with 86 additions and 7 deletions

View file

@ -216,10 +216,7 @@ text_tool_restore_on_canvas_editor_position_cmd_callback (GimpAction *action,
{ {
GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); GimpTextTool *text_tool = GIMP_TEXT_TOOL (data);
if (text_tool->layer) gimp_text_tool_restore_on_canvas_editor_position (text_tool);
gimp_text_layer_set_style_overlay_position (text_tool->layer, FALSE, 0, 0);
gimp_text_tool_editor_position (text_tool);
} }

View file

@ -293,6 +293,9 @@ gimp_text_tool_editor_position (GimpTextTool *text_tool)
x, y, -1, x, y, -1,
text_tool->drag_offset_x + 25, text_tool->drag_offset_x + 25,
text_tool->drag_offset_y + 25); text_tool->drag_offset_y + 25);
gimp_text_style_show_restore_position_button (GIMP_TEXT_STYLE_EDITOR (text_tool->style_editor),
TRUE);
} }
else else
{ {
@ -2033,9 +2036,10 @@ gimp_text_tool_style_overlay_button_motion (GtkWidget *widget,
if (text_tool->overlay_dragging) if (text_tool->overlay_dragging)
{ {
GimpTool *tool = GIMP_TOOL (text_tool); GimpTool *tool = GIMP_TOOL (text_tool);
GimpDisplayShell *shell = gimp_display_get_shell (tool->display); GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
gdouble x, y; GimpTextStyleEditor *style_editor;
gdouble x, y;
gdk_window_get_device_position_double (gtk_widget_get_window (GTK_WIDGET (shell)), gdk_window_get_device_position_double (gtk_widget_get_window (GTK_WIDGET (shell)),
event->device, event->device,
@ -2053,6 +2057,9 @@ gimp_text_tool_style_overlay_button_motion (GtkWidget *widget,
gimp_text_layer_set_style_overlay_position (text_tool->layer, TRUE, gimp_text_layer_set_style_overlay_position (text_tool->layer, TRUE,
x, y); x, y);
style_editor = GIMP_TEXT_STYLE_EDITOR (text_tool->style_editor);
gimp_text_style_show_restore_position_button (style_editor, TRUE);
} }
return TRUE; return TRUE;

View file

@ -65,6 +65,7 @@
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimpmenufactory.h" #include "widgets/gimpmenufactory.h"
#include "widgets/gimptextbuffer.h" #include "widgets/gimptextbuffer.h"
#include "widgets/gimptextstyleeditor.h"
#include "widgets/gimpuimanager.h" #include "widgets/gimpuimanager.h"
#include "widgets/gimpviewabledialog.h" #include "widgets/gimpviewabledialog.h"
@ -2418,3 +2419,15 @@ gimp_text_tool_get_direction (GimpTextTool *text_tool)
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool); GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
return options->base_dir; return options->base_dir;
} }
void
gimp_text_tool_restore_on_canvas_editor_position (GimpTextTool *text_tool)
{
GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (text_tool->style_editor);
if (text_tool->layer)
gimp_text_layer_set_style_overlay_position (text_tool->layer, FALSE, 0, 0);
gimp_text_tool_editor_position (text_tool);
gimp_text_style_show_restore_position_button (editor, FALSE);
}

View file

@ -134,5 +134,8 @@ gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool);
void gimp_text_tool_apply (GimpTextTool *text_tool, void gimp_text_tool_apply (GimpTextTool *text_tool,
gboolean push_undo); gboolean push_undo);
void gimp_text_tool_restore_on_canvas_editor_position
(GimpTextTool *text_tool);
#endif /* __GIMP_TEXT_TOOL_H__ */ #endif /* __GIMP_TEXT_TOOL_H__ */

View file

@ -33,6 +33,10 @@
#include "core/gimpcontainer.h" #include "core/gimpcontainer.h"
#include "core/gimpcontext.h" #include "core/gimpcontext.h"
#include "tools/tools-types.h"
#include "tools/tool_manager.h"
#include "tools/gimptexttool.h"
#include "text/gimptext.h" #include "text/gimptext.h"
#include "text/gimpfont.h" #include "text/gimpfont.h"
@ -42,6 +46,7 @@
#include "gimptextbuffer.h" #include "gimptextbuffer.h"
#include "gimptextstyleeditor.h" #include "gimptextstyleeditor.h"
#include "gimptexttag.h" #include "gimptexttag.h"
#include "gimpwidgets-constructors.h"
#include "gimpwidgets-utils.h" #include "gimpwidgets-utils.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -120,6 +125,10 @@ static void gimp_text_style_editor_set_kerning (GimpTextStyleEditor *
static void gimp_text_style_editor_update (GimpTextStyleEditor *editor); static void gimp_text_style_editor_update (GimpTextStyleEditor *editor);
static gboolean gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor); static gboolean gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor);
static void gimp_text_style_editor_restore_position_callback
(GtkWidget *button,
GimpTextStyleEditor *editor);
G_DEFINE_TYPE (GimpTextStyleEditor, gimp_text_style_editor, G_DEFINE_TYPE (GimpTextStyleEditor, gimp_text_style_editor,
GTK_TYPE_BOX) GTK_TYPE_BOX)
@ -193,6 +202,7 @@ gimp_text_style_editor_init (GimpTextStyleEditor *editor)
{ {
GtkWidget *image; GtkWidget *image;
GeglColor *color; GeglColor *color;
GtkWidget *move_icon;
gtk_orientable_set_orientation (GTK_ORIENTABLE (editor), gtk_orientable_set_orientation (GTK_ORIENTABLE (editor),
GTK_ORIENTATION_VERTICAL); GTK_ORIENTATION_VERTICAL);
@ -227,6 +237,30 @@ gimp_text_style_editor_init (GimpTextStyleEditor *editor)
G_CALLBACK (gimp_text_style_editor_size_changed), G_CALLBACK (gimp_text_style_editor_size_changed),
editor); editor);
/* Icon that indicates that the overlay can be moved */
move_icon = gtk_image_new_from_icon_name (GIMP_ICON_TOOL_MOVE,
GTK_ICON_SIZE_MENU);
gtk_widget_set_sensitive (move_icon, FALSE);
gtk_widget_show (move_icon);
/* Restore position button */
editor->restore_position_button = gimp_icon_button_new (GIMP_ICON_RESET, NULL);
gtk_button_set_relief (GTK_BUTTON (editor->restore_position_button),
GTK_RELIEF_NONE);
gtk_image_set_from_icon_name (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (editor->restore_position_button))),
GIMP_ICON_RESET, GTK_ICON_SIZE_MENU);
gimp_help_set_help_data (editor->restore_position_button,
_("Restore On-Canvas Editor Position"), NULL);
g_signal_connect (editor->restore_position_button, "clicked",
G_CALLBACK (gimp_text_style_editor_restore_position_callback),
editor);
gtk_box_pack_end (GTK_BOX (editor->upper_hbox), move_icon, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (editor->upper_hbox), editor->restore_position_button,
FALSE, FALSE, 0);
/* lower row */ /* lower row */
editor->lower_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); editor->lower_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
@ -633,6 +667,16 @@ gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor,
return g_list_reverse (tags); return g_list_reverse (tags);
} }
void
gimp_text_style_show_restore_position_button (GimpTextStyleEditor *editor,
gboolean show)
{
if (show)
gtk_widget_show (editor->restore_position_button);
else
gtk_widget_hide (editor->restore_position_button);
}
/* private functions */ /* private functions */
@ -1339,3 +1383,13 @@ gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor)
return FALSE; return FALSE;
} }
static void
gimp_text_style_editor_restore_position_callback (GtkWidget *button,
GimpTextStyleEditor *editor)
{
GimpTool *tool = tool_manager_get_active (editor->gimp);
GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
gimp_text_tool_restore_on_canvas_editor_position (text_tool);
}

View file

@ -48,6 +48,7 @@ struct _GimpTextStyleEditor
GtkWidget *upper_hbox; GtkWidget *upper_hbox;
GtkWidget *lower_hbox; GtkWidget *lower_hbox;
GtkWidget *restore_position_button;
GtkWidget *font_entry; GtkWidget *font_entry;
GtkWidget *size_entry; GtkWidget *size_entry;
@ -85,5 +86,9 @@ GtkWidget * gimp_text_style_editor_new (Gimp *gimp,
GList * gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor, GList * gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor,
GList **remove_tags); GList **remove_tags);
void gimp_text_style_show_restore_position_button
(GimpTextStyleEditor *editor,
gboolean show);
#endif /* __GIMP_TEXT_STYLE_EDITOR_H__ */ #endif /* __GIMP_TEXT_STYLE_EDITOR_H__ */