Skip to content

Commit df79811

Browse files
committed
Port a couple more widgets to the new subclass init style.
1 parent 28747b4 commit df79811

4 files changed

Lines changed: 38 additions & 28 deletions

File tree

Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,11 @@ private Gtk.Widget CreateCairoColorPicker (
338338
? c
339339
: Color.Black;
340340

341-
PintaColorButton colorButton = new () {
342-
DisplayColor = currentColorCairo,
343-
Hexpand = false,
344-
Halign = Gtk.Align.Start,
345-
WidthRequest = 80,
346-
};
341+
PintaColorButton colorButton = PintaColorButton.New ();
342+
colorButton.DisplayColor = currentColorCairo;
343+
colorButton.Hexpand = false;
344+
colorButton.Halign = Gtk.Align.Start;
345+
colorButton.WidthRequest = 80;
347346

348347
colorButton.OnClicked += async (_, _) => {
349348

Pinta.Gui.Widgets/Widgets/Canvas/CanvasWindow.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ public CanvasWindow (
9494
scrolledWindow.Vexpand = true;
9595
scrolledWindow.Child = viewPort;
9696

97-
Ruler horizontalRuler = new (Gtk.Orientation.Horizontal) {
98-
Metric = MetricType.Pixels,
99-
Visible = false,
100-
};
97+
Ruler horizontalRuler = Ruler.New (Gtk.Orientation.Horizontal);
98+
horizontalRuler.Metric = MetricType.Pixels;
99+
horizontalRuler.Visible = false;
101100

102-
Ruler verticalRuler = new (Gtk.Orientation.Vertical) {
103-
Metric = MetricType.Pixels,
104-
Visible = false,
105-
};
101+
Ruler verticalRuler = Ruler.New (Gtk.Orientation.Vertical);
102+
verticalRuler.Metric = MetricType.Pixels;
103+
verticalRuler.Visible = false;
106104

107105
Gtk.EventControllerMotion motionController = Gtk.EventControllerMotion.New ();
108106
motionController.OnMotion += HandleMotion;

Pinta.Gui.Widgets/Widgets/PintaColorButton.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
namespace Pinta.Gui.Widgets;
55

6-
internal sealed class PintaColorButton : Gtk.Button
6+
[GObject.Subclass<Gtk.Button>]
7+
internal sealed partial class PintaColorButton
78
{
89
private Color display_color = Color.Black;
910
public Color DisplayColor {
@@ -15,17 +16,18 @@ public Color DisplayColor {
1516
}
1617
}
1718

18-
private readonly Gtk.DrawingArea color_drawing_area;
19-
internal PintaColorButton ()
19+
private readonly Gtk.DrawingArea color_drawing_area = Gtk.DrawingArea.New ();
20+
21+
partial void Initialize ()
2022
{
21-
Gtk.DrawingArea colorDrawingArea = Gtk.DrawingArea.New ();
22-
colorDrawingArea.Hexpand = true;
23-
colorDrawingArea.Vexpand = true;
24-
colorDrawingArea.SetDrawFunc (OnDraw);
25-
SetChild (colorDrawingArea);
26-
color_drawing_area = colorDrawingArea;
23+
color_drawing_area.Hexpand = true;
24+
color_drawing_area.Vexpand = true;
25+
color_drawing_area.SetDrawFunc (OnDraw);
26+
SetChild (color_drawing_area);
2727
}
2828

29+
public static new PintaColorButton New () => NewWithProperties ([]);
30+
2931
private void OnDraw (
3032
Gtk.DrawingArea drawingArea,
3133
Context cr,

Pinta.Gui.Widgets/Widgets/Ruler.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public enum MetricType
4444
/// Replacement for Gtk.Ruler, which was removed in GTK3.
4545
/// Based on the original GTK2 widget and Inkscape's ruler widget.
4646
/// </summary>
47-
public sealed class Ruler : Gtk.DrawingArea
47+
[GObject.Subclass<Gtk.DrawingArea>]
48+
public sealed partial class Ruler
4849
{
4950
private double position = 0;
5051
private MetricType metric = MetricType.Pixels;
@@ -65,7 +66,7 @@ public NumberRange<double>? SelectionBounds {
6566
/// <summary>
6667
/// Whether the ruler is horizontal or vertical.
6768
/// </summary>
68-
public Gtk.Orientation Orientation { get; }
69+
public Gtk.Orientation Orientation { get; private set; }
6970

7071
/// <summary>
7172
/// Metric type used for the ruler.
@@ -101,11 +102,14 @@ public NumberRange<double> RulerRange {
101102
}
102103
}
103104

104-
public Ruler (Gtk.Orientation orientation)
105+
partial void Initialize ()
105106
{
106-
Orientation = orientation;
107-
108107
SetDrawFunc ((area, context, width, height) => Draw (context, new Size (width, height)));
108+
}
109+
110+
private void SetOrientation (Gtk.Orientation orientation)
111+
{
112+
Orientation = orientation;
109113

110114
// Determine the size request, based on the font size.
111115
int font_size = GetFontSize (GetPangoContext ().GetFontDescription ()!, ScaleFactor);
@@ -126,6 +130,13 @@ public Ruler (Gtk.Orientation orientation)
126130
HeightRequest = height;
127131
}
128132

133+
public static Ruler New (Gtk.Orientation orientation)
134+
{
135+
Ruler ruler = NewWithProperties ([]);
136+
ruler.SetOrientation (orientation);
137+
return ruler;
138+
}
139+
129140
// Invalidates cache _and_ queues redraw. Like a full refresh
130141
private void QueueFullRedraw ()
131142
{

0 commit comments

Comments
 (0)