Skip to content

Commit

Permalink
Refactored control creation ReseedButtonWidget (PintaProject#842)
Browse files Browse the repository at this point in the history
* Refactored control creation `ReseedButtonWidget`

* We don't need to keep the reference to the reseed button
  • Loading branch information
Lehonti authored Jun 3, 2024
1 parent 718accb commit 19485c0
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions Pinta.Gui.Widgets/Widgets/ReseedButtonWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,62 @@
// THE SOFTWARE.

using System;
using Gtk;
using Pinta.Core;

namespace Pinta.Gui.Widgets;

public sealed class ReseedButtonWidget : Box
public sealed class ReseedButtonWidget : Gtk.Box
{
private readonly Label label;
private readonly Button button;
private readonly Gtk.Label section_label;

public event EventHandler? Clicked;

public ReseedButtonWidget ()
{
const int spacing = 6;

// Section label + line
label = new ();
label.AddCssClass (AdwaitaStyles.Title4);
label.Hexpand = false;
label.Halign = Align.Start;
Gtk.Label sectionLabel = CreateSectionLabel ();
Gtk.Button reseedButton = CreateReseedButton ();

// Reseed button
button = new Button {
// Main layout
SetOrientation (Gtk.Orientation.Vertical);
Spacing = spacing;
Append (sectionLabel);
Append (reseedButton);

// --- References to keep

section_label = sectionLabel;
}

private Gtk.Button CreateReseedButton ()
{
Gtk.Button result = new () {
WidthRequest = 88,
CanFocus = true,
UseUnderline = true,
Label = Pinta.Core.Translations.GetString ("Reseed"),
Label = Translations.GetString ("Reseed"),
Hexpand = false,
Halign = Align.Start
Halign = Gtk.Align.Start,
};

// Main layout
SetOrientation (Orientation.Vertical);
Spacing = spacing;
Append (label);
Append (button);
result.OnClicked += (_, _) => Clicked?.Invoke (this, EventArgs.Empty);

button.OnClicked += (_, _) => Clicked?.Invoke (this, EventArgs.Empty);
return result;
}

private static Gtk.Label CreateSectionLabel ()
{
Gtk.Label result = new ();
result.AddCssClass (AdwaitaStyles.Title4);
result.Hexpand = false;
result.Halign = Gtk.Align.Start;
return result;
}

public string Label {
get => label.GetText ();
set => label.SetText (value);
get => section_label.GetText ();
set => section_label.SetText (value);
}
}

0 comments on commit 19485c0

Please sign in to comment.