Skip to content

Commit 6ed94d4

Browse files
committed
eto: trying to work around weird rendering bugs
- grid shows up as black bar rows in certain areas if we do this before showing the form
1 parent e144c57 commit 6ed94d4

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

Diz.App.Eto/DizEtoApp.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1-
using System.Diagnostics;
1+
// #define DIZ_WINFORMS
2+
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
25
using Diz.Controllers.interfaces;
36
using Eto.Forms;
47

58
namespace Diz.App.Eto;
69

710
public class DizEtoApp(IViewFactory viewFactory) : IDizApp
811
{
12+
#if DIZ_WINFORMS
13+
//hack
14+
[DllImport("user32.dll")]
15+
private static extern bool SetProcessDPIAware();
16+
#endif
17+
918
public void Run(string initialProjectFileToOpen = "")
1019
{
1120
var application = new Application();
21+
22+
#if DIZ_WINFORMS
23+
// hack
24+
if (application.Platform.IsWinForms)
25+
{
26+
if (Environment.OSVersion.Version.Major >= 6) {
27+
SetProcessDPIAware();
28+
}
29+
System.Windows.Forms.Application.EnableVisualStyles();
30+
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
31+
}
32+
// end hack
33+
#endif
1234

1335
var mainWindow = viewFactory.GetMainGridWindowView();
1436

Diz.Ui.Eto/ui/EtoMainGridForm.cs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ private void CreateMenu()
9797
};
9898
}
9999

100+
private GridView gridView;
101+
100102
private void CreateGui()
101103
{
102104
Title = "Diz";
@@ -105,11 +107,10 @@ private void CreateGui()
105107
CreateMenu();
106108

107109
// Create the grid view
108-
var gridView = new GridView
110+
gridView = new GridView
109111
{
110112
AllowMultipleSelection = false,
111113
ShowHeader = true,
112-
DataStore = GetGridData(),
113114
};
114115

115116
// Add columns to the grid
@@ -212,8 +213,6 @@ private void CreateGui()
212213
Size = new Size {Height = 20}
213214
};
214215

215-
// ------------
216-
// var layout = TableLayout.AutoSized(gridView); // works pretty good too.
217216

218217
var layout = new DynamicLayout();
219218
layout.BeginVertical(yscale: true);
@@ -224,19 +223,40 @@ private void CreateGui()
224223
layout.AddRow (bottomFooter);
225224
layout.EndVertical ();
226225

226+
gridView.Invalidate(true);
227+
gridView.UpdateLayout();
228+
229+
UpdateLayout();
230+
231+
// gridView.DataStore = GetGridData();
232+
Invalidate(true);
233+
UpdateLayout();
227234

228-
this.BackgroundColor = Colors.Lime; // tmp
229-
layout.BackgroundColor = Colors.Chocolate; //. tmp
230-
231235
// Apply the container as the content of the form
232236
Content = layout;
233-
234-
gridView.Invalidate(true);
235-
gridView.UpdateLayout();
236-
Content.Invalidate(true);
237237
Content.UpdateLayout();
238-
238+
Content.Invalidate(true);
239+
240+
Visible = false;
241+
Visible = true;
242+
243+
Application.Instance.AsyncInvoke(() =>
244+
{
245+
gridView.Invalidate(true);
246+
});
247+
248+
Width = 1000;
249+
Height = 600;
250+
}
251+
252+
protected override void OnShown(EventArgs e)
253+
{
254+
// for some reason, this is better done here or we get weird rendering bugs on first showing that are impossible to figure out
255+
gridView.DataStore = GetGridData();
256+
239257
UpdateLayout();
258+
Invalidate(true);
259+
base.OnShown(e);
240260
}
241261

242262
private IEnumerable<object> GetGridData()

0 commit comments

Comments
 (0)