Skip to content

Commit 8f182da

Browse files
committed
Core,Controls: made events work with Frame
Frame now can handle events. For this to work, I had to inherit FrameView from EventBox, not actual Frame, as Frame is on of the widgets that don't have window and therefore can't handle events, see [1]. [1] https://docs.gtk.org/gtk3/input-handling.html#event-masks
1 parent ec9321f commit 8f182da

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/Core/src/Platform/Gtk/ContentView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Microsoft.Maui.Platform
66
{
77

8-
public class ContentView : Bin, ICrossPlatformLayoutBacking
8+
public class ContentView : EventBox, ICrossPlatformLayoutBacking
99
{
1010
public ContentView() : base() { }
1111

src/Core/src/Platform/Gtk/FrameExtensions.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class FrameExtensions
1111

1212
static (string mainNode, string subNode)? _borderCssNode = default;
1313

14-
public static (string mainNode, string subNode) BorderCssNode(this Gtk.Frame platformView)
14+
public static (string mainNode, string subNode) BorderCssNode(this Gtk.Container platformView)
1515
{
1616
if (_borderCssNode is { })
1717
return _borderCssNode.Value;
@@ -23,19 +23,18 @@ public static (string mainNode, string subNode) BorderCssNode(this Gtk.Frame pla
2323
return _borderCssNode.Value;
2424
}
2525

26-
public static void UpdateBorderColor(this Gtk.Frame platformView, Color? color)
26+
public static void UpdateBorderColor(this Gtk.Container platformView, Color? color)
2727
{
28-
var (mainNode, subNode) = platformView.BorderCssNode();
29-
platformView.SetStyleColor(color, mainNode, "border-color", subNode);
28+
platformView.SetStyleValueNode($"1px solid {color.ToGdkRgba().ToString()}", platformView.CssMainNode(), "border");
3029
}
3130

32-
public static void UpdateBorderWidth(this Gtk.Frame platformView, int width)
31+
public static void UpdateBorderWidth(this Gtk.Container platformView, int width)
3332
{
3433
var (mainNode, subNode) = platformView.BorderCssNode();
35-
platformView.SetStyleValueNode($"{width}px", mainNode, "border-width", subNode);
34+
platformView.SetStyleValueNode($"{width}px", mainNode, "border-width");
3635
}
3736

38-
public static void UpdateDashPattern(this Gtk.Frame platformView, float[]? strokeDashPattern)
37+
public static void UpdateDashPattern(this Gtk.Container platformView, float[]? strokeDashPattern)
3938
{
4039
var (mainNode, subNode) = platformView.BorderCssNode();
4140

@@ -54,22 +53,22 @@ public static void UpdateDashPattern(this Gtk.Frame platformView, float[]? strok
5453
}
5554

5655
// border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius
57-
public static void UpdateBorderRadius(this Gtk.Frame platformView, float radius, float? tr = default, float? br = default, float? bl = default)
56+
public static void UpdateBorderRadius(this Gtk.Container platformView, float radius, float? tr = default, float? br = default, float? bl = default)
5857
{
5958
int Clamp(float r) => (int)(r < 0 ? 0 : r);
6059

6160
var (mainNode, subNode) = platformView.BorderCssNode();
6261
if (tr is not { } || br is not { } || bl is not { } ||
6362
(radius == tr && radius == br && radius == bl))
6463
{
65-
platformView.SetStyleValueNode($"{Clamp(radius)}px", mainNode, "border-radius", subNode);
64+
platformView.SetStyleValueNode($"{Clamp(radius)}px", mainNode, "border-radius");
6665
return;
6766
}
6867

69-
platformView.SetStyleValueNode($"{Clamp(radius)}px", mainNode, "border-top-left-radius", subNode);
70-
platformView.SetStyleValueNode($"{Clamp(tr.Value)}px", mainNode, "border-top-right-radius", subNode);
71-
platformView.SetStyleValueNode($"{Clamp(br.Value)}px", mainNode, "border-bottom-right-radius", subNode);
72-
platformView.SetStyleValueNode($"{Clamp(bl.Value)}px", mainNode, "border-bottom-left-radius", subNode);
68+
platformView.SetStyleValueNode($"{Clamp(radius)}px", mainNode, "border-top-left-radius");
69+
platformView.SetStyleValueNode($"{Clamp(tr.Value)}px", mainNode, "border-top-right-radius");
70+
platformView.SetStyleValueNode($"{Clamp(br.Value)}px", mainNode, "border-bottom-right-radius");
71+
platformView.SetStyleValueNode($"{Clamp(bl.Value)}px", mainNode, "border-bottom-left-radius");
7372

7473
// no effect:
7574
platformView.SetStyleValueNode("padding-box", mainNode, "background-clip");
@@ -122,7 +121,7 @@ static float[] Radii((PointF from, PointF to)[] corners)
122121
return [cornerOffset(0), cornerOffset(1), cornerOffset(2), cornerOffset(3)];
123122
}
124123

125-
public static void UpdateShape(this Gtk.Frame platformView, IShape? shape)
124+
public static void UpdateShape(this Gtk.Container platformView, IShape? shape)
126125
{
127126
if (platformView is not { })
128127
return;

src/Core/src/Platform/Gtk/FrameView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Microsoft.Maui.Platform;
44

55
// https://docs.gtk.org/gtk3/class.Frame.html
66

7-
public class FrameView : Frame, ICrossPlatformLayoutBacking
7+
public class FrameView : EventBox, ICrossPlatformLayoutBacking
88
{
99

1010
public ICrossPlatformLayout? CrossPlatformLayout { get; set; }

0 commit comments

Comments
 (0)