Skip to content

Commit 2619340

Browse files
committed
Split placement into dedicated C API files
Add auto-generated `placement_c.h/.cpp` for `native_placement_t` and conversion helpers, and remove placement enum definitions from `geometry_c.h` so geometry only contains point/size/rectangle types. Update `menu_c.h` to include `placement_c.h` where placement is used, and add generated boilerplate/interop setup to `geometry_c.h/.cpp`.
1 parent e040cd8 commit 2619340

5 files changed

Lines changed: 131 additions & 73 deletions

File tree

‎src/capi/geometry_c.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
#include "geometry_c.h"
5+
6+
#include "../foundation/geometry.h"
7+
8+
namespace {
9+
10+
native_point_t ToCPoint(const nativeapi::Point& value) {
11+
native_point_t result = {};
12+
result.x = value.x;
13+
result.y = value.y;
14+
return result;
15+
}
16+
17+
native_size_t ToCSize(const nativeapi::Size& value) {
18+
native_size_t result = {};
19+
result.width = value.width;
20+
result.height = value.height;
21+
return result;
22+
}
23+
24+
native_rectangle_t ToCRectangle(const nativeapi::Rectangle& value) {
25+
native_rectangle_t result = {};
26+
result.x = value.x;
27+
result.y = value.y;
28+
result.width = value.width;
29+
result.height = value.height;
30+
return result;
31+
}
32+
33+
} // namespace
34+

‎src/capi/geometry_c.h‎

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,37 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
14
#pragma once
25

3-
/**
4-
* Representation of a point
5-
*/
6+
#include <stdbool.h>
7+
8+
#if _WIN32
9+
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
10+
#else
11+
#define FFI_PLUGIN_EXPORT
12+
#endif
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
618
typedef struct {
719
double x;
820
double y;
921
} native_point_t;
1022

11-
/**
12-
* Representation of a point
13-
*/
1423
typedef struct {
1524
double width;
1625
double height;
1726
} native_size_t;
1827

19-
/**
20-
* Representation of a rectangle
21-
*/
2228
typedef struct {
2329
double x;
2430
double y;
2531
double width;
2632
double height;
2733
} native_rectangle_t;
2834

29-
/**
30-
* Placement options for positioning UI elements relative to an anchor.
31-
*/
32-
typedef enum {
33-
/**
34-
* Position above the anchor, horizontally centered.
35-
*/
36-
NATIVE_PLACEMENT_TOP,
37-
38-
/**
39-
* Position above the anchor, aligned to the start (left).
40-
*/
41-
NATIVE_PLACEMENT_TOP_START,
42-
43-
/**
44-
* Position above the anchor, aligned to the end (right).
45-
*/
46-
NATIVE_PLACEMENT_TOP_END,
47-
48-
/**
49-
* Position to the right of the anchor, vertically centered.
50-
*/
51-
NATIVE_PLACEMENT_RIGHT,
52-
53-
/**
54-
* Position to the right of the anchor, aligned to the start (top).
55-
*/
56-
NATIVE_PLACEMENT_RIGHT_START,
57-
58-
/**
59-
* Position to the right of the anchor, aligned to the end (bottom).
60-
*/
61-
NATIVE_PLACEMENT_RIGHT_END,
62-
63-
/**
64-
* Position below the anchor, horizontally centered.
65-
*/
66-
NATIVE_PLACEMENT_BOTTOM,
67-
68-
/**
69-
* Position below the anchor, aligned to the start (left).
70-
*/
71-
NATIVE_PLACEMENT_BOTTOM_START,
72-
73-
/**
74-
* Position below the anchor, aligned to the end (right).
75-
*/
76-
NATIVE_PLACEMENT_BOTTOM_END,
77-
78-
/**
79-
* Position to the left of the anchor, vertically centered.
80-
*/
81-
NATIVE_PLACEMENT_LEFT,
82-
83-
/**
84-
* Position to the left of the anchor, aligned to the start (top).
85-
*/
86-
NATIVE_PLACEMENT_LEFT_START,
87-
88-
/**
89-
* Position to the left of the anchor, aligned to the end (bottom).
90-
*/
91-
NATIVE_PLACEMENT_LEFT_END
92-
} native_placement_t;
35+
#ifdef __cplusplus
36+
}
37+
#endif

‎src/capi/menu_c.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stddef.h>
55
#include <stdint.h>
66
#include "geometry_c.h"
7+
#include "placement_c.h"
78

89
#if _WIN32
910
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
@@ -17,6 +18,7 @@ extern "C" {
1718

1819
#include "geometry_c.h"
1920
#include "image_c.h"
21+
#include "placement_c.h"
2022
#include "positioning_strategy_c.h"
2123

2224
/**

‎src/capi/placement_c.cpp‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
#include "placement_c.h"
5+
6+
#include "../placement.h"
7+
8+
namespace {
9+
10+
native_placement_t ToCPlacement(nativeapi::Placement value) {
11+
switch (value) {
12+
case nativeapi::Placement::Top:
13+
return NATIVE_PLACEMENT_TOP;
14+
case nativeapi::Placement::TopStart:
15+
return NATIVE_PLACEMENT_TOP_START;
16+
case nativeapi::Placement::TopEnd:
17+
return NATIVE_PLACEMENT_TOP_END;
18+
case nativeapi::Placement::Right:
19+
return NATIVE_PLACEMENT_RIGHT;
20+
case nativeapi::Placement::RightStart:
21+
return NATIVE_PLACEMENT_RIGHT_START;
22+
case nativeapi::Placement::RightEnd:
23+
return NATIVE_PLACEMENT_RIGHT_END;
24+
case nativeapi::Placement::Bottom:
25+
return NATIVE_PLACEMENT_BOTTOM;
26+
case nativeapi::Placement::BottomStart:
27+
return NATIVE_PLACEMENT_BOTTOM_START;
28+
case nativeapi::Placement::BottomEnd:
29+
return NATIVE_PLACEMENT_BOTTOM_END;
30+
case nativeapi::Placement::Left:
31+
return NATIVE_PLACEMENT_LEFT;
32+
case nativeapi::Placement::LeftStart:
33+
return NATIVE_PLACEMENT_LEFT_START;
34+
case nativeapi::Placement::LeftEnd:
35+
return NATIVE_PLACEMENT_LEFT_END;
36+
default:
37+
return NATIVE_PLACEMENT_TOP;
38+
}
39+
}
40+
41+
} // namespace
42+

‎src/capi/placement_c.h‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
#pragma once
5+
6+
#include <stdbool.h>
7+
8+
#if _WIN32
9+
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
10+
#else
11+
#define FFI_PLUGIN_EXPORT
12+
#endif
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
typedef enum {
19+
NATIVE_PLACEMENT_TOP = 0,
20+
NATIVE_PLACEMENT_TOP_START = 1,
21+
NATIVE_PLACEMENT_TOP_END = 2,
22+
NATIVE_PLACEMENT_RIGHT = 3,
23+
NATIVE_PLACEMENT_RIGHT_START = 4,
24+
NATIVE_PLACEMENT_RIGHT_END = 5,
25+
NATIVE_PLACEMENT_BOTTOM = 6,
26+
NATIVE_PLACEMENT_BOTTOM_START = 7,
27+
NATIVE_PLACEMENT_BOTTOM_END = 8,
28+
NATIVE_PLACEMENT_LEFT = 9,
29+
NATIVE_PLACEMENT_LEFT_START = 10,
30+
NATIVE_PLACEMENT_LEFT_END = 11,
31+
} native_placement_t;
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif

0 commit comments

Comments
 (0)