Skip to content

Commit 27d9016

Browse files
committed
window can have initial width and height
1 parent f7cf2f8 commit 27d9016

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
env:
44
VERSION: 0.0.0
5-
PACKAGE_SUFFIX: '-pre.44'
5+
PACKAGE_SUFFIX: '-pre.45'
66
# PACKAGE_SUFFIX: ''
77
ASM_VERSION: 0.0.0
88
BUILD_TYPE: Release

dotnet/Grey/Native.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ internal static extern int window(
206206
int id,
207207
bool unregister,
208208
[MarshalAs(UnmanagedType.LPUTF8Str)] string title,
209+
int width, int height,
209210
ref bool is_open,
210211
RenderCallback c_callback
211212
);

dotnet/Grey/Window.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ public class Window : IDisposable {
99
private bool _isOpen = true;
1010
private GCHandle _isOpenHandle;
1111
private readonly string _title;
12+
private readonly int _initialWidth;
13+
private readonly int _initialHeight;
1214

13-
public Window(string title, bool canClose = true) {
15+
public Window(string title, bool canClose = true, int initialWidth = 0, int initialHeight = 0) {
1416
_isOpenHandle = GCHandle.Alloc(_isOpen, GCHandleType.Pinned);
1517
_title = title;
18+
_initialWidth = initialWidth;
19+
_initialHeight = initialHeight;
1620
}
1721

1822
public bool IsOpen {
@@ -21,13 +25,13 @@ public bool IsOpen {
2125
}
2226

2327
public void Run(Action renderContent) {
24-
_id = Native.window(_id, false, _title, ref _isOpen, () => {
28+
_id = Native.window(_id, false, _title, _initialWidth, _initialHeight, ref _isOpen, () => {
2529
renderContent();
2630
});
2731
}
2832

2933
public void Dispose() {
30-
Native.window(_id, true, "", ref _isOpen, () => { });
34+
Native.window(_id, true, "", 0, 0, ref _isOpen, () => { });
3135
if(_isOpenHandle.IsAllocated) {
3236
_isOpenHandle.Free();
3337
}

grey/x.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ map<int, unique_ptr<w::window>> window_map;
283283

284284
EXPORTED int32_t window(int32_t id, bool unregister,
285285
const char* title,
286+
int32_t width, int32_t height,
286287
bool* p_open,
287288
RenderCallback c_render_callback) {
288289

@@ -293,7 +294,9 @@ EXPORTED int32_t window(int32_t id, bool unregister,
293294
// create new window
294295
id = w::generate_int_id();
295296
string t{title};
296-
window_map[id] = make_unique<w::window>(t, p_open);
297+
auto wnd = make_unique<w::window>(t, p_open);
298+
wnd->size(width, height);
299+
window_map[id] = std::move(wnd);
297300
} else if(unregister) {
298301
// delete window from map
299302
window_map.erase(it);

grey/x.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extern "C" {
119119
EXPORTED int32_t window(int32_t id,
120120
bool unregister,
121121
const char* title,
122+
int32_t width, int32_t height,
122123
bool* p_open,
123124
RenderCallback c_render_callback);
124125

0 commit comments

Comments
 (0)