@windowkit/appkit 0.15.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/addon.mm +5 -3
- package/src/backend.mm +49 -3
package/README.md
CHANGED
|
@@ -412,7 +412,7 @@ and returns a `CGImage` for `layer.contents`:
|
|
|
412
412
|
|
|
413
413
|
```js
|
|
414
414
|
const img = ca.controls.render({
|
|
415
|
-
kind: 'push', // 'push' | 'checkbox' | 'radio' | 'popup' | 'slider' | 'switch'
|
|
415
|
+
kind: 'push', // 'push' | 'flexiblePush' | 'checkbox' | 'radio' | 'popup' | 'slider' | 'switch'
|
|
416
416
|
title: 'Click me',
|
|
417
417
|
pressed: false, // drive this from your own mouse events
|
|
418
418
|
state: 1, // on/off for checkbox/radio/switch
|
|
@@ -436,6 +436,12 @@ Two render paths inside `drawControl`:
|
|
|
436
436
|
at all, so these render a real unparented `NSControl` via
|
|
437
437
|
`displayRectIgnoringOpacity:inContext:`.
|
|
438
438
|
|
|
439
|
+
A `push` bezel is one height: drawn into a taller frame, AppKit draws its own 22pt bezel
|
|
440
|
+
centred in it. `flexiblePush` is `NSBezelStyleFlexiblePush`, the same button stretched to
|
|
441
|
+
its frame — the bezel AppKit gives a title that wraps, and what WebKit and Gecko draw a
|
|
442
|
+
push button taller than a push button with. At the push's height the two are the same
|
|
443
|
+
pixels, except that the default button's accent fill is flat in the flexible bezel.
|
|
444
|
+
|
|
439
445
|
The demo re-renders a control's image on each state change; a real renderer would cache
|
|
440
446
|
per `(kind, size, state, appearance)` and nine-slice-stretch bezels with
|
|
441
447
|
`layer.contentsCenter`. Menus/popovers are deliberately *not* painted — their
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
|
|
5
5
|
"author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"install": "node scripts/install.js",
|
|
44
44
|
"build": "node-gyp rebuild",
|
|
45
45
|
"demo": "node demo/demo.js",
|
|
46
|
-
"test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js && node test/text-features.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js"
|
|
46
|
+
"test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js && node test/round-rect-xy.js && node test/control-bezels.js && node test/text-features.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"node-addon-api": "^8.3.0"
|
|
Binary file
|
|
Binary file
|
package/src/addon.mm
CHANGED
|
@@ -1401,7 +1401,7 @@ static NSView* DummyDrawView() {
|
|
|
1401
1401
|
|
|
1402
1402
|
// drawControl({kind, title, state, pressed, enabled, isDefault, value,
|
|
1403
1403
|
// controlSize, appearance, width, height, scale})
|
|
1404
|
-
// kind: 'push' | 'checkbox' | 'radio' | 'popup' | 'slider'
|
|
1404
|
+
// kind: 'push' | 'flexiblePush' | 'checkbox' | 'radio' | 'popup' | 'slider'
|
|
1405
1405
|
// -> { image: External<CGImage>, width, height, scale } (points)
|
|
1406
1406
|
// width/height default to the cell's natural cellSize (slider must pass them).
|
|
1407
1407
|
static Napi::Value DrawControl(const Napi::CallbackInfo& info) {
|
|
@@ -1418,7 +1418,7 @@ static Napi::Value DrawControl(const Napi::CallbackInfo& info) {
|
|
|
1418
1418
|
|
|
1419
1419
|
NSCell* cell = nil;
|
|
1420
1420
|
if ([kind isEqualToString:@"checkbox"] || [kind isEqualToString:@"radio"] ||
|
|
1421
|
-
[kind isEqualToString:@"push"]) {
|
|
1421
|
+
[kind isEqualToString:@"push"] || [kind isEqualToString:@"flexiblePush"]) {
|
|
1422
1422
|
NSButtonCell* c = [[NSButtonCell alloc] initTextCell:title];
|
|
1423
1423
|
if ([kind isEqualToString:@"checkbox"]) {
|
|
1424
1424
|
c.buttonType = NSButtonTypeSwitch;
|
|
@@ -1426,7 +1426,9 @@ static Napi::Value DrawControl(const Napi::CallbackInfo& info) {
|
|
|
1426
1426
|
c.buttonType = NSButtonTypeRadio;
|
|
1427
1427
|
} else {
|
|
1428
1428
|
c.buttonType = NSButtonTypeMomentaryPushIn;
|
|
1429
|
-
|
|
1429
|
+
// one height, or stretched to the frame (src/backend.mm, BuildBezel)
|
|
1430
|
+
c.bezelStyle = [kind isEqualToString:@"flexiblePush"] ? NSBezelStyleFlexiblePush
|
|
1431
|
+
: NSBezelStylePush;
|
|
1430
1432
|
if (BoolOr(o, "isDefault", false)) c.keyEquivalent = @"\r"; // accent fill
|
|
1431
1433
|
}
|
|
1432
1434
|
c.state = state == 1 ? NSControlStateValueOn : NSControlStateValueOff;
|
package/src/backend.mm
CHANGED
|
@@ -3479,7 +3479,7 @@ static bool ParseBezelSpec(Napi::Env env, Napi::Value v, BezelSpec* s) {
|
|
|
3479
3479
|
}
|
|
3480
3480
|
Napi::Object o = v.As<Napi::Object>();
|
|
3481
3481
|
s->kind = BStrOr(o, "kind", @"push");
|
|
3482
|
-
if (![@[ @"push", @"checkbox", @"radio", @"popup", @"slider", @"switch" ]
|
|
3482
|
+
if (![@[ @"push", @"flexiblePush", @"checkbox", @"radio", @"popup", @"slider", @"switch" ]
|
|
3483
3483
|
containsObject:s->kind]) {
|
|
3484
3484
|
Napi::Error::New(env, "unknown control kind").ThrowAsJavaScriptException();
|
|
3485
3485
|
return false;
|
|
@@ -3500,7 +3500,7 @@ static BezelControl BuildBezel(const BezelSpec& s) {
|
|
|
3500
3500
|
BezelControl out;
|
|
3501
3501
|
NSString* kind = s.kind;
|
|
3502
3502
|
if ([kind isEqualToString:@"checkbox"] || [kind isEqualToString:@"radio"] ||
|
|
3503
|
-
[kind isEqualToString:@"push"]) {
|
|
3503
|
+
[kind isEqualToString:@"push"] || [kind isEqualToString:@"flexiblePush"]) {
|
|
3504
3504
|
NSButtonCell* c = [[NSButtonCell alloc] initTextCell:s.title];
|
|
3505
3505
|
if ([kind isEqualToString:@"checkbox"]) {
|
|
3506
3506
|
c.buttonType = NSButtonTypeSwitch;
|
|
@@ -3508,7 +3508,12 @@ static BezelControl BuildBezel(const BezelSpec& s) {
|
|
|
3508
3508
|
c.buttonType = NSButtonTypeRadio;
|
|
3509
3509
|
} else {
|
|
3510
3510
|
c.buttonType = NSButtonTypeMomentaryPushIn;
|
|
3511
|
-
|
|
3511
|
+
// A push bezel is one height, whatever frame it is drawn into: asked
|
|
3512
|
+
// for a taller one it draws its own, centred. The flexible push is the
|
|
3513
|
+
// same button stretched to the frame — the bezel AppKit gives a title
|
|
3514
|
+
// that wraps, and the one WebKit and Gecko draw a tall button with.
|
|
3515
|
+
c.bezelStyle = [kind isEqualToString:@"flexiblePush"] ? NSBezelStyleFlexiblePush
|
|
3516
|
+
: NSBezelStylePush;
|
|
3512
3517
|
// the Return key equivalent is what makes AppKit fill it with the
|
|
3513
3518
|
// user's accent — the "default button" look
|
|
3514
3519
|
if (s.isDefault) c.keyEquivalent = @"\r";
|
|
@@ -3740,6 +3745,46 @@ static Napi::Value CtxRoundRect(const Napi::CallbackInfo& info) {
|
|
|
3740
3745
|
CGPathRelease(p);
|
|
3741
3746
|
return info.Env().Undefined();
|
|
3742
3747
|
}
|
|
3748
|
+
// roundRectXY(surface, x, y, w, h, tlx, tly, trx, try, brx, bry, blx, bly)
|
|
3749
|
+
// — a rounded rect whose corners are elliptical, each with its own pair of
|
|
3750
|
+
// radii: canvas's roundRect with `{ x, y }` radii, and CSS's
|
|
3751
|
+
// `border-radius: 40px / 20px`. The caller has scaled them to fit, as
|
|
3752
|
+
// canvas scales them. A corner with no extent on one of its axes is no curve
|
|
3753
|
+
// at all, and is square — drawn as two lines it would cut the corner off
|
|
3754
|
+
// diagonally. Each quarter ellipse is one cubic, its handles a KAPPA of the
|
|
3755
|
+
// radius along each tangent, as WebKit draws an elliptical corner.
|
|
3756
|
+
static Napi::Value CtxRoundRectXY(const Napi::CallbackInfo& info) {
|
|
3757
|
+
CALSurface* s = SurfaceFrom(info[0]);
|
|
3758
|
+
if (!s) return info.Env().Undefined();
|
|
3759
|
+
double v[12];
|
|
3760
|
+
for (int i = 0; i < 12; i++) v[i] = info[i + 1].As<Napi::Number>().DoubleValue();
|
|
3761
|
+
const double x = v[0], y = v[1], r = v[0] + v[2], b = v[1] + v[3];
|
|
3762
|
+
double c[8];
|
|
3763
|
+
for (int i = 0; i < 4; i++) {
|
|
3764
|
+
const bool curved = v[4 + i * 2] > 0 && v[5 + i * 2] > 0;
|
|
3765
|
+
c[i * 2] = curved ? v[4 + i * 2] : 0;
|
|
3766
|
+
c[i * 2 + 1] = curved ? v[5 + i * 2] : 0;
|
|
3767
|
+
}
|
|
3768
|
+
const double tlx = c[0], tly = c[1], trx = c[2], trY = c[3];
|
|
3769
|
+
const double brx = c[4], brY = c[5], blx = c[6], blY = c[7];
|
|
3770
|
+
// how far in from the corner's own point a handle sits, as a fraction of
|
|
3771
|
+
// the radius along it
|
|
3772
|
+
const double k = 1 - 0.5522847498307936;
|
|
3773
|
+
CGMutablePathRef p = CGPathCreateMutable();
|
|
3774
|
+
CGPathMoveToPoint(p, NULL, x + tlx, y);
|
|
3775
|
+
CGPathAddLineToPoint(p, NULL, r - trx, y);
|
|
3776
|
+
if (trx > 0) CGPathAddCurveToPoint(p, NULL, r - trx * k, y, r, y + trY * k, r, y + trY);
|
|
3777
|
+
CGPathAddLineToPoint(p, NULL, r, b - brY);
|
|
3778
|
+
if (brx > 0) CGPathAddCurveToPoint(p, NULL, r, b - brY * k, r - brx * k, b, r - brx, b);
|
|
3779
|
+
CGPathAddLineToPoint(p, NULL, x + blx, b);
|
|
3780
|
+
if (blx > 0) CGPathAddCurveToPoint(p, NULL, x + blx * k, b, x, b - blY * k, x, b - blY);
|
|
3781
|
+
CGPathAddLineToPoint(p, NULL, x, y + tly);
|
|
3782
|
+
if (tlx > 0) CGPathAddCurveToPoint(p, NULL, x, y + tly * k, x + tlx * k, y, x + tlx, y);
|
|
3783
|
+
CGPathCloseSubpath(p);
|
|
3784
|
+
CGContextAddPath(s->ctx, p);
|
|
3785
|
+
CGPathRelease(p);
|
|
3786
|
+
return info.Env().Undefined();
|
|
3787
|
+
}
|
|
3743
3788
|
static Napi::Value CtxArc(const Napi::CallbackInfo& info) {
|
|
3744
3789
|
// arc(surface, x, y, r, a0, a1, anticlockwise). Angles live in user
|
|
3745
3790
|
// space, where canvas's y-down "clockwise" sweep is the INCREASING-angle
|
|
@@ -7135,6 +7180,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
7135
7180
|
BFN("ctxLineTo", CtxLineTo);
|
|
7136
7181
|
BFN("ctxRect", CtxRect);
|
|
7137
7182
|
BFN("ctxRoundRect", CtxRoundRect);
|
|
7183
|
+
BFN("ctxRoundRectXY", CtxRoundRectXY);
|
|
7138
7184
|
BFN("ctxArc", CtxArc);
|
|
7139
7185
|
BFN("ctxEllipse", CtxEllipse);
|
|
7140
7186
|
BFN("ctxCurveTo", CtxCurveTo);
|