Skip to content

Commit

Permalink
Fix a couple issues with the toolbars
Browse files Browse the repository at this point in the history
- When the header bar is being used (Windows / Linux), avoid adding an empty main toolbar. This added a few pixels of unnecessary padding
- Similarly, omit the option to hide the main toolbar when the header bar is being used
- The tool's toolbar now scrolls horizontally if there are too many widgets (e.g. the line/curve tool)
  • Loading branch information
cameronwhite committed Jan 6, 2024
1 parent 1c90ebf commit 3e3d3f3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Pinta.Core/Actions/ViewActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ public void RegisterActions (Gtk.Application app, Gio.Menu menu)
app.AddAction (Rulers);
show_hide_menu.AppendItem (Rulers.CreateMenuItem ());

app.AddAction (ToolBar);
show_hide_menu.AppendItem (ToolBar.CreateMenuItem ());
if (PintaCore.Chrome.MainToolBar is not null) {
app.AddAction (ToolBar);
show_hide_menu.AppendItem (ToolBar.CreateMenuItem ());
}

app.AddAction (StatusBar);
show_hide_menu.AppendItem (StatusBar.CreateMenuItem ());
Expand Down
9 changes: 9 additions & 0 deletions Pinta.Core/Extensions/GtkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public static Gtk.Box CreateToolBar ()
return toolbar;
}

/// <summary>
/// Remove all child widgets from a box.
/// </summary>
public static void RemoveAll (this Gtk.Box box)
{
while (box.GetFirstChild () is Widget child)
box.Remove (child);
}

public static Gtk.Button CreateToolBarItem (this Command action, bool force_icon_only = false)
{
var label = action.ShortLabel ?? action.Label;
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Managers/ChromeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed class ChromeManager
private MessageDialogHandler message_dialog_handler = null!;
private SimpleEffectDialogHandler simple_effect_dialog_handler = null!;

public Box MainToolBar { get; private set; } = null!;
public Box? MainToolBar { get; private set; }
public Box ToolToolBar { get; private set; } = null!;
public Box ToolBox { get; private set; } = null!;
public Box StatusBar { get; private set; } = null!;
Expand Down
25 changes: 19 additions & 6 deletions Pinta.Core/Managers/ToolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public void SetCurrentTool (BaseTool tool)
PintaCore.Chrome.ToolToolBar.Append (ToolImage);
PintaCore.Chrome.ToolToolBar.Append (ToolSeparator);

tool.DoBuildToolBar (PintaCore.Chrome.ToolToolBar);
PintaCore.Chrome.ToolToolBar.Append (ToolWidgetsScroll);
tool.DoBuildToolBar (ToolWidgetsBox);

PintaCore.Workspace.Invalidate ();
PintaCore.Chrome.SetStatusBarText ($" {tool.Name}: {tool.StatusBarText}");
Expand Down Expand Up @@ -242,12 +243,10 @@ public bool SetCurrentTool (Gdk.Key shortcut)
return shortcut_tools[next_index];
}

private static void DeactivateTool (BaseTool tool, BaseTool? newTool)
private void DeactivateTool (BaseTool tool, BaseTool? newTool)
{
var toolbar = PintaCore.Chrome.ToolToolBar;

while (toolbar.GetFirstChild () is Widget child)
toolbar.Remove (child);
ToolWidgetsBox.RemoveAll ();
PintaCore.Chrome.ToolToolBar.RemoveAll ();

tool.DoDeactivated (PintaCore.Workspace.ActiveDocumentOrDefault, newTool);
tool.ToolItem.Active = false;
Expand Down Expand Up @@ -350,8 +349,22 @@ public override int Compare (BaseTool? x, BaseTool? y)
private Label? tool_label;
private Image? tool_image;
private Separator? tool_sep;
private Box? tool_widgets_box;
private ScrolledWindow? tool_widgets_scroll;

private Label ToolLabel => tool_label ??= Label.New (string.Format (" {0}: ", Translations.GetString ("Tool")));
private Image ToolImage => tool_image ??= new Image ();
private Separator ToolSeparator => tool_sep ??= GtkExtensions.CreateToolBarSeparator ();
private Box ToolWidgetsBox => tool_widgets_box ??= Gtk.Box.New (Orientation.Horizontal, 0);
// Scroll the toolbar contents if they are very long (e.g. the line/curve tool).
private ScrolledWindow ToolWidgetsScroll => tool_widgets_scroll ??= new ScrolledWindow () {
Child = ToolWidgetsBox,
HscrollbarPolicy = PolicyType.Automatic,
VscrollbarPolicy = PolicyType.Never,
HasFrame = false,
OverlayScrolling = true,
WindowPlacement = CornerType.BottomRight,
Hexpand = true,
Halign = Align.Fill
};
}
3 changes: 2 additions & 1 deletion Pinta/Actions/View/ToolBarToggledAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void Uninitialize ()

private void Activated (bool value)
{
PintaCore.Chrome.MainToolBar.Visible = value;
if (PintaCore.Chrome.MainToolBar is not null)
PintaCore.Chrome.MainToolBar.Visible = value;
}
}
10 changes: 4 additions & 6 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,18 @@ private void CreateMainMenu (WindowShell shell)

private void CreateMainToolBar (WindowShell shell)
{
var main_toolbar = window_shell.CreateToolBar ("main_toolbar");

if (window_shell.HeaderBar is not null)
PintaCore.Actions.CreateHeaderToolBar (window_shell.HeaderBar!);
else
else {
var main_toolbar = window_shell.CreateToolBar ("main_toolbar");
PintaCore.Actions.CreateToolBar (main_toolbar);

PintaCore.Chrome.InitializeMainToolBar (main_toolbar);
}
}

private void CreateToolToolBar (WindowShell shell)
{
var tool_toolbar = window_shell.CreateToolBar ("tool_toolbar");
tool_toolbar.HeightRequest = 42;
tool_toolbar.HeightRequest = 48;

PintaCore.Chrome.InitializeToolToolBar (tool_toolbar);
}
Expand Down

0 comments on commit 3e3d3f3

Please sign in to comment.