bare-ui-kit 0.2.0 → 0.3.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/CMakeLists.txt +7 -1
- package/README.md +42 -1
- package/binding.m +558 -2
- package/index.d.ts +41 -0
- package/index.js +16 -0
- package/lib/activity-indicator-view.d.ts +29 -0
- package/lib/activity-indicator-view.h +181 -0
- package/lib/activity-indicator-view.js +56 -0
- package/lib/alert-action.d.ts +33 -0
- package/lib/alert-action.js +48 -0
- package/lib/alert-controller.d.ts +20 -0
- package/lib/alert-controller.h +199 -0
- package/lib/alert-controller.js +33 -0
- package/lib/attributed-string.d.ts +45 -0
- package/lib/attributed-string.h +176 -0
- package/lib/attributed-string.js +51 -0
- package/lib/attributes.js +34 -0
- package/lib/bezier-path.d.ts +26 -0
- package/lib/bezier-path.h +145 -0
- package/lib/bezier-path.js +51 -0
- package/lib/bridging.h +600 -2
- package/lib/color.d.ts +86 -0
- package/lib/color.h +286 -0
- package/lib/color.js +170 -0
- package/lib/events.js +35 -0
- package/lib/font-descriptor.d.ts +30 -0
- package/lib/font-descriptor.h +96 -0
- package/lib/font-descriptor.js +47 -0
- package/lib/font-metrics.d.ts +38 -0
- package/lib/font-metrics.h +109 -0
- package/lib/font-metrics.js +58 -0
- package/lib/font.d.ts +59 -0
- package/lib/font.h +424 -0
- package/lib/font.js +100 -0
- package/lib/handle.d.ts +5 -0
- package/lib/handle.js +6 -0
- package/lib/image-view.d.ts +15 -0
- package/lib/image-view.h +75 -0
- package/lib/image-view.js +27 -0
- package/lib/image.d.ts +37 -0
- package/lib/image.h +205 -0
- package/lib/image.js +60 -0
- package/lib/label.d.ts +51 -0
- package/lib/label.h +331 -0
- package/lib/label.js +94 -0
- package/lib/paragraph-style.d.ts +20 -0
- package/lib/paragraph-style.h +94 -0
- package/lib/paragraph-style.js +42 -0
- package/lib/pasteboard.d.ts +31 -0
- package/lib/pasteboard.h +123 -0
- package/lib/pasteboard.js +63 -0
- package/lib/retain.js +12 -0
- package/lib/runtime.m +92 -15
- package/lib/scene.d.ts +30 -0
- package/lib/scene.h +87 -0
- package/lib/scene.js +48 -0
- package/lib/scratch.js +4 -0
- package/lib/screen.d.ts +26 -0
- package/lib/screen.h +194 -0
- package/lib/screen.js +52 -0
- package/lib/scroll-view.d.ts +39 -0
- package/lib/scroll-view.h +246 -0
- package/lib/scroll-view.js +64 -0
- package/lib/switch.d.ts +22 -0
- package/lib/switch.h +166 -0
- package/lib/switch.js +42 -0
- package/lib/text-field.d.ts +103 -0
- package/lib/text-field.h +562 -0
- package/lib/text-field.js +183 -0
- package/lib/text-view.d.ts +59 -0
- package/lib/text-view.h +497 -0
- package/lib/text-view.js +138 -0
- package/lib/view-controller.d.ts +37 -0
- package/lib/view-controller.h +108 -20
- package/lib/view-controller.js +50 -5
- package/lib/view.d.ts +158 -0
- package/lib/view.h +1385 -20
- package/lib/view.js +276 -7
- package/lib/window.d.ts +44 -0
- package/lib/window.h +167 -27
- package/lib/window.js +62 -9
- package/lib/wrap.js +7 -0
- package/package.json +12 -3
- package/prebuilds/ios-arm64/bare +0 -0
- package/prebuilds/ios-arm64/bare-ui-kit.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ui-kit.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ui-kit.bare +0 -0
package/lib/font.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const registry = require('bare-foundation-registry')
|
|
3
|
+
const wrap = require('./wrap')
|
|
4
|
+
const UIKitFontDescriptor = require('./font-descriptor')
|
|
5
|
+
|
|
6
|
+
module.exports = exports = class UIKitFont {
|
|
7
|
+
constructor(opts = {}) {
|
|
8
|
+
const { tag = null } = opts
|
|
9
|
+
|
|
10
|
+
this._tag = tag
|
|
11
|
+
|
|
12
|
+
this._token = binding.claim(this._tag, this)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get [registry.tag]() {
|
|
16
|
+
return this._tag
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get [registry.handle]() {
|
|
20
|
+
return binding.handle(this._tag)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static systemFont(size, weight = binding.FONT_WEIGHT_REGULAR) {
|
|
24
|
+
return wrap(UIKitFont, binding.fontSystemFont(size, weight))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static boldSystemFont(size) {
|
|
28
|
+
return wrap(UIKitFont, binding.fontBoldSystemFont(size))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static monospacedSystemFont(size, weight = binding.FONT_WEIGHT_REGULAR) {
|
|
32
|
+
return wrap(UIKitFont, binding.fontMonospacedSystemFont(size, weight))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static withName(name, size) {
|
|
36
|
+
return wrap(UIKitFont, binding.fontWithName(name, size))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static withDescriptor(descriptor, size) {
|
|
40
|
+
return wrap(UIKitFont, binding.fontWithDescriptor(descriptor._tag, size))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get fontDescriptor() {
|
|
44
|
+
return wrap(UIKitFontDescriptor, binding.fontFontDescriptor(this._tag))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get fontName() {
|
|
48
|
+
return binding.fontFontName(this._tag)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get familyName() {
|
|
52
|
+
return binding.fontFamilyName(this._tag)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get pointSize() {
|
|
56
|
+
return binding.fontPointSize(this._tag)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get ascender() {
|
|
60
|
+
return binding.fontAscender(this._tag)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get descender() {
|
|
64
|
+
return binding.fontDescender(this._tag)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get capHeight() {
|
|
68
|
+
return binding.fontCapHeight(this._tag)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get xHeight() {
|
|
72
|
+
return binding.fontXHeight(this._tag)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get leading() {
|
|
76
|
+
return binding.fontLeading(this._tag)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get lineHeight() {
|
|
80
|
+
return binding.fontLineHeight(this._tag)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[Symbol.for('bare.inspect')]() {
|
|
84
|
+
return {
|
|
85
|
+
__proto__: { constructor: UIKitFont }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.WEIGHT = {
|
|
91
|
+
ULTRA_LIGHT: binding.FONT_WEIGHT_ULTRA_LIGHT,
|
|
92
|
+
THIN: binding.FONT_WEIGHT_THIN,
|
|
93
|
+
LIGHT: binding.FONT_WEIGHT_LIGHT,
|
|
94
|
+
REGULAR: binding.FONT_WEIGHT_REGULAR,
|
|
95
|
+
MEDIUM: binding.FONT_WEIGHT_MEDIUM,
|
|
96
|
+
SEMIBOLD: binding.FONT_WEIGHT_SEMIBOLD,
|
|
97
|
+
BOLD: binding.FONT_WEIGHT_BOLD,
|
|
98
|
+
HEAVY: binding.FONT_WEIGHT_HEAVY,
|
|
99
|
+
BLACK: binding.FONT_WEIGHT_BLACK
|
|
100
|
+
}
|
package/lib/handle.d.ts
ADDED
package/lib/handle.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
|
|
2
|
+
import UIKitView = require('./view')
|
|
3
|
+
import UIKitImage = require('./image')
|
|
4
|
+
|
|
5
|
+
/** A view that shows an image, as a `UIImageView`. */
|
|
6
|
+
interface UIKitImageView extends UIKitView {
|
|
7
|
+
get image(): UIKitImage | null
|
|
8
|
+
set image(image: Wrapper | null)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare class UIKitImageView {
|
|
12
|
+
constructor(frame?: Partial<UIKitView.Rect>)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export = UIKitImageView
|
package/lib/image-view.h
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#import <assert.h>
|
|
2
|
+
#import <bare.h>
|
|
3
|
+
#import <js.h>
|
|
4
|
+
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
#import "bridging.h"
|
|
8
|
+
|
|
9
|
+
static js_value_t *
|
|
10
|
+
bare_ui_kit_image_view_init(js_env_t *env, js_callback_info_t *info) {
|
|
11
|
+
int err;
|
|
12
|
+
|
|
13
|
+
size_t argc = 4;
|
|
14
|
+
js_value_t *argv[4];
|
|
15
|
+
|
|
16
|
+
bare_ui_kit_state_t *state;
|
|
17
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
18
|
+
assert(err == 0);
|
|
19
|
+
|
|
20
|
+
assert(argc == 4);
|
|
21
|
+
|
|
22
|
+
double x;
|
|
23
|
+
if (!bare_ui_kit__read_double(env, argv[0], "x", &x)) return NULL;
|
|
24
|
+
|
|
25
|
+
double y;
|
|
26
|
+
if (!bare_ui_kit__read_double(env, argv[1], "y", &y)) return NULL;
|
|
27
|
+
|
|
28
|
+
double width;
|
|
29
|
+
if (!bare_ui_kit__read_double(env, argv[2], "width", &width)) return NULL;
|
|
30
|
+
|
|
31
|
+
double height;
|
|
32
|
+
if (!bare_ui_kit__read_double(env, argv[3], "height", &height)) return NULL;
|
|
33
|
+
|
|
34
|
+
js_value_t *result;
|
|
35
|
+
|
|
36
|
+
@autoreleasepool {
|
|
37
|
+
UIImageView *handle = [[[UIImageView alloc]
|
|
38
|
+
initWithFrame:CGRectMake(x, y, width, height)] autorelease];
|
|
39
|
+
|
|
40
|
+
result = bare_foundation_bridge(env, state->registry, handle);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static js_value_t *
|
|
47
|
+
bare_ui_kit_image_view_image(js_env_t *env, js_callback_info_t *info) {
|
|
48
|
+
int err;
|
|
49
|
+
|
|
50
|
+
size_t argc = 2;
|
|
51
|
+
js_value_t *argv[2];
|
|
52
|
+
|
|
53
|
+
bare_ui_kit_state_t *state;
|
|
54
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
55
|
+
assert(err == 0);
|
|
56
|
+
|
|
57
|
+
assert(argc == 1 || argc == 2);
|
|
58
|
+
|
|
59
|
+
void *handle;
|
|
60
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
61
|
+
|
|
62
|
+
js_value_t *result = NULL;
|
|
63
|
+
|
|
64
|
+
@autoreleasepool {
|
|
65
|
+
UIImageView *view = (__bridge UIImageView *) handle;
|
|
66
|
+
|
|
67
|
+
if (argc == 1) {
|
|
68
|
+
result = bare_foundation_bridge(env, state->registry, view.image);
|
|
69
|
+
} else {
|
|
70
|
+
view.image = bare_foundation_to_object(env, state->registry, argv[1]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const { adopt } = require('./handle')
|
|
3
|
+
const wrap = require('./wrap')
|
|
4
|
+
const UIKitImage = require('./image')
|
|
5
|
+
const UIKitView = require('./view')
|
|
6
|
+
|
|
7
|
+
module.exports = exports = class UIKitImageView extends UIKitView {
|
|
8
|
+
_init(opts) {
|
|
9
|
+
const { x = 0, y = 0, width = 0, height = 0 } = opts
|
|
10
|
+
|
|
11
|
+
return binding.imageViewInit(x, y, width, height)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get image() {
|
|
15
|
+
return wrap(UIKitImage, binding.imageViewImage(this._tag))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
set image(image) {
|
|
19
|
+
binding.imageViewImage(this._tag, adopt(image))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[Symbol.for('bare.inspect')]() {
|
|
23
|
+
return {
|
|
24
|
+
__proto__: { constructor: UIKitImageView }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/lib/image.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
|
|
2
|
+
|
|
3
|
+
/** An image, as a `UIImage`. */
|
|
4
|
+
interface UIKitImage {
|
|
5
|
+
/** The size in points. */
|
|
6
|
+
readonly size: { width: number; height: number }
|
|
7
|
+
|
|
8
|
+
readonly scale: number
|
|
9
|
+
|
|
10
|
+
/** Whether the image is drawn as is or tinted, as a `RENDERING_MODE` constant. */
|
|
11
|
+
readonly renderingMode: number
|
|
12
|
+
|
|
13
|
+
/** The same image with another rendering mode. */
|
|
14
|
+
withRenderingMode(renderingMode: number): UIKitImage
|
|
15
|
+
|
|
16
|
+
readonly [tag]: number
|
|
17
|
+
|
|
18
|
+
readonly [handle]: Handle
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class UIKitImage {
|
|
22
|
+
protected constructor()
|
|
23
|
+
|
|
24
|
+
/** Load an image file, or return `null` if it cannot be read. */
|
|
25
|
+
static withContentsOfFile(path: string): UIKitImage | null
|
|
26
|
+
|
|
27
|
+
/** An image from the app bundle, or `null` if there is none by that name. */
|
|
28
|
+
static named(name: string): UIKitImage | null
|
|
29
|
+
|
|
30
|
+
static readonly RENDERING_MODE: {
|
|
31
|
+
readonly AUTOMATIC: number
|
|
32
|
+
readonly ALWAYS_ORIGINAL: number
|
|
33
|
+
readonly ALWAYS_TEMPLATE: number
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export = UIKitImage
|
package/lib/image.h
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#import <assert.h>
|
|
2
|
+
#import <bare.h>
|
|
3
|
+
#import <js.h>
|
|
4
|
+
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
#import "bridging.h"
|
|
8
|
+
|
|
9
|
+
static js_value_t *
|
|
10
|
+
bare_ui_kit_image_with_contents_of_file(js_env_t *env, js_callback_info_t *info) {
|
|
11
|
+
int err;
|
|
12
|
+
|
|
13
|
+
size_t argc = 1;
|
|
14
|
+
js_value_t *argv[1];
|
|
15
|
+
|
|
16
|
+
bare_ui_kit_state_t *state;
|
|
17
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
18
|
+
assert(err == 0);
|
|
19
|
+
|
|
20
|
+
assert(argc == 1);
|
|
21
|
+
|
|
22
|
+
NSString *path = bare_ui_kit__to_string(env, argv[0]);
|
|
23
|
+
|
|
24
|
+
js_value_t *result;
|
|
25
|
+
|
|
26
|
+
@autoreleasepool {
|
|
27
|
+
result = bare_foundation_bridge(env, state->registry, [UIImage imageWithContentsOfFile:path]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static js_value_t *
|
|
34
|
+
bare_ui_kit_image_named(js_env_t *env, js_callback_info_t *info) {
|
|
35
|
+
int err;
|
|
36
|
+
|
|
37
|
+
size_t argc = 1;
|
|
38
|
+
js_value_t *argv[1];
|
|
39
|
+
|
|
40
|
+
bare_ui_kit_state_t *state;
|
|
41
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
42
|
+
assert(err == 0);
|
|
43
|
+
|
|
44
|
+
assert(argc == 1);
|
|
45
|
+
|
|
46
|
+
NSString *name = bare_ui_kit__to_string(env, argv[0]);
|
|
47
|
+
|
|
48
|
+
js_value_t *result;
|
|
49
|
+
|
|
50
|
+
@autoreleasepool {
|
|
51
|
+
result = bare_foundation_bridge(env, state->registry, [UIImage imageNamed:name]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static js_value_t *
|
|
58
|
+
bare_ui_kit_image_size_into(js_env_t *env, js_callback_info_t *info) {
|
|
59
|
+
int err;
|
|
60
|
+
|
|
61
|
+
size_t argc = 3;
|
|
62
|
+
js_value_t *argv[3];
|
|
63
|
+
|
|
64
|
+
bare_ui_kit_state_t *state;
|
|
65
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
66
|
+
assert(err == 0);
|
|
67
|
+
|
|
68
|
+
assert(argc == 3);
|
|
69
|
+
|
|
70
|
+
void *handle;
|
|
71
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
72
|
+
|
|
73
|
+
uint32_t offset;
|
|
74
|
+
if (!bare_ui_kit__read_uint32(env, argv[2], "offset", &offset)) return NULL;
|
|
75
|
+
|
|
76
|
+
double *out;
|
|
77
|
+
|
|
78
|
+
if (!bare_ui_kit__buffer(env, argv[1], offset, 2, &out)) {
|
|
79
|
+
err = js_throw_type_error(env, NULL, "Expected an array buffer with room for 2 doubles");
|
|
80
|
+
assert(err == 0);
|
|
81
|
+
|
|
82
|
+
return NULL;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@autoreleasepool {
|
|
86
|
+
UIImage *image = (__bridge UIImage *) handle;
|
|
87
|
+
|
|
88
|
+
out[0] = image.size.width;
|
|
89
|
+
out[1] = image.size.height;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return NULL;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static void
|
|
96
|
+
bare_ui_kit_image_size_into_typed(js_value_t *receiver, int32_t bare_tag, js_value_t *bare_buffer, uint32_t bare_offset, js_typed_callback_info_t *info) {
|
|
97
|
+
int err;
|
|
98
|
+
|
|
99
|
+
bare_ui_kit_state_t *state;
|
|
100
|
+
|
|
101
|
+
js_env_t *env;
|
|
102
|
+
err = js_get_typed_callback_info(info, &env, (void **) &state);
|
|
103
|
+
assert(err == 0);
|
|
104
|
+
|
|
105
|
+
id bare_object = bare_foundation_object(state->registry, bare_tag);
|
|
106
|
+
|
|
107
|
+
if (bare_object == nil) return;
|
|
108
|
+
|
|
109
|
+
double *out;
|
|
110
|
+
|
|
111
|
+
if (!bare_ui_kit__buffer(env, bare_buffer, bare_offset, 2, &out)) return;
|
|
112
|
+
|
|
113
|
+
@autoreleasepool {
|
|
114
|
+
UIImage *image = (UIImage *) bare_object;
|
|
115
|
+
|
|
116
|
+
out[0] = image.size.width;
|
|
117
|
+
out[1] = image.size.height;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static js_value_t *
|
|
122
|
+
bare_ui_kit_image_scale(js_env_t *env, js_callback_info_t *info) {
|
|
123
|
+
int err;
|
|
124
|
+
|
|
125
|
+
size_t argc = 1;
|
|
126
|
+
js_value_t *argv[1];
|
|
127
|
+
|
|
128
|
+
bare_ui_kit_state_t *state;
|
|
129
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
130
|
+
assert(err == 0);
|
|
131
|
+
|
|
132
|
+
assert(argc == 1);
|
|
133
|
+
|
|
134
|
+
void *handle;
|
|
135
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
136
|
+
|
|
137
|
+
js_value_t *result;
|
|
138
|
+
|
|
139
|
+
@autoreleasepool {
|
|
140
|
+
UIImage *image = (__bridge UIImage *) handle;
|
|
141
|
+
|
|
142
|
+
err = js_create_double(env, image.scale, &result);
|
|
143
|
+
assert(err == 0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static js_value_t *
|
|
150
|
+
bare_ui_kit_image_rendering_mode(js_env_t *env, js_callback_info_t *info) {
|
|
151
|
+
int err;
|
|
152
|
+
|
|
153
|
+
size_t argc = 1;
|
|
154
|
+
js_value_t *argv[1];
|
|
155
|
+
|
|
156
|
+
bare_ui_kit_state_t *state;
|
|
157
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
158
|
+
assert(err == 0);
|
|
159
|
+
|
|
160
|
+
assert(argc == 1);
|
|
161
|
+
|
|
162
|
+
void *handle;
|
|
163
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
164
|
+
|
|
165
|
+
js_value_t *result;
|
|
166
|
+
|
|
167
|
+
@autoreleasepool {
|
|
168
|
+
UIImage *image = (__bridge UIImage *) handle;
|
|
169
|
+
|
|
170
|
+
err = js_create_int32(env, image.renderingMode, &result);
|
|
171
|
+
assert(err == 0);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static js_value_t *
|
|
178
|
+
bare_ui_kit_image_with_rendering_mode(js_env_t *env, js_callback_info_t *info) {
|
|
179
|
+
int err;
|
|
180
|
+
|
|
181
|
+
size_t argc = 2;
|
|
182
|
+
js_value_t *argv[2];
|
|
183
|
+
|
|
184
|
+
bare_ui_kit_state_t *state;
|
|
185
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
186
|
+
assert(err == 0);
|
|
187
|
+
|
|
188
|
+
assert(argc == 2);
|
|
189
|
+
|
|
190
|
+
void *handle;
|
|
191
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
192
|
+
|
|
193
|
+
int32_t rendering_mode;
|
|
194
|
+
if (!bare_ui_kit__read_int32(env, argv[1], "rendering_mode", &rendering_mode)) return NULL;
|
|
195
|
+
|
|
196
|
+
js_value_t *result;
|
|
197
|
+
|
|
198
|
+
@autoreleasepool {
|
|
199
|
+
UIImage *image = (__bridge UIImage *) handle;
|
|
200
|
+
|
|
201
|
+
result = bare_foundation_bridge(env, state->registry, [image imageWithRenderingMode:rendering_mode]);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return result;
|
|
205
|
+
}
|
package/lib/image.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const registry = require('bare-foundation-registry')
|
|
3
|
+
const scratch = require('./scratch')
|
|
4
|
+
const wrap = require('./wrap')
|
|
5
|
+
|
|
6
|
+
module.exports = exports = class UIKitImage {
|
|
7
|
+
constructor(opts = {}) {
|
|
8
|
+
const { tag = null } = opts
|
|
9
|
+
|
|
10
|
+
this._tag = tag
|
|
11
|
+
|
|
12
|
+
this._token = binding.claim(this._tag, this)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get [registry.tag]() {
|
|
16
|
+
return this._tag
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get [registry.handle]() {
|
|
20
|
+
return binding.handle(this._tag)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static withContentsOfFile(path) {
|
|
24
|
+
return wrap(UIKitImage, binding.imageWithContentsOfFile(path))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static named(name) {
|
|
28
|
+
return wrap(UIKitImage, binding.imageNamed(name))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get size() {
|
|
32
|
+
binding.imageSizeInto(this._tag, scratch.buffer, 0)
|
|
33
|
+
|
|
34
|
+
return { width: scratch[0], height: scratch[1] }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get scale() {
|
|
38
|
+
return binding.imageScale(this._tag)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get renderingMode() {
|
|
42
|
+
return binding.imageRenderingMode(this._tag)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
withRenderingMode(renderingMode) {
|
|
46
|
+
return wrap(UIKitImage, binding.imageWithRenderingMode(this._tag, renderingMode))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[Symbol.for('bare.inspect')]() {
|
|
50
|
+
return {
|
|
51
|
+
__proto__: { constructor: UIKitImage }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.RENDERING_MODE = {
|
|
57
|
+
AUTOMATIC: binding.IMAGE_RENDERING_MODE_AUTOMATIC,
|
|
58
|
+
ALWAYS_ORIGINAL: binding.IMAGE_RENDERING_MODE_ALWAYS_ORIGINAL,
|
|
59
|
+
ALWAYS_TEMPLATE: binding.IMAGE_RENDERING_MODE_ALWAYS_TEMPLATE
|
|
60
|
+
}
|
package/lib/label.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
|
|
2
|
+
import UIKitView = require('./view')
|
|
3
|
+
import UIKitAttributedString = require('./attributed-string')
|
|
4
|
+
import UIKitColor = require('./color')
|
|
5
|
+
import UIKitFont = require('./font')
|
|
6
|
+
|
|
7
|
+
/** A view that shows text, as a `UILabel`. */
|
|
8
|
+
interface UIKitLabel extends UIKitView {
|
|
9
|
+
text: string | null
|
|
10
|
+
|
|
11
|
+
get attributedText(): UIKitAttributedString | null
|
|
12
|
+
set attributedText(text: Wrapper | null)
|
|
13
|
+
|
|
14
|
+
get font(): UIKitFont | null
|
|
15
|
+
set font(font: Wrapper | null)
|
|
16
|
+
|
|
17
|
+
get textColor(): UIKitColor | null
|
|
18
|
+
set textColor(color: Wrapper | null)
|
|
19
|
+
|
|
20
|
+
/** A `TEXT_ALIGNMENT` constant. */
|
|
21
|
+
textAlignment: number
|
|
22
|
+
|
|
23
|
+
/** The most lines to show. 0 means no limit. */
|
|
24
|
+
numberOfLines: number
|
|
25
|
+
|
|
26
|
+
/** How lines wrap or are cut off, as a `LINE_BREAK_MODE` constant. */
|
|
27
|
+
lineBreakMode: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class UIKitLabel {
|
|
31
|
+
constructor(frame?: Partial<UIKitView.Rect>)
|
|
32
|
+
|
|
33
|
+
static readonly TEXT_ALIGNMENT: {
|
|
34
|
+
readonly LEFT: number
|
|
35
|
+
readonly RIGHT: number
|
|
36
|
+
readonly CENTER: number
|
|
37
|
+
readonly JUSTIFIED: number
|
|
38
|
+
readonly NATURAL: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static readonly LINE_BREAK_MODE: {
|
|
42
|
+
readonly WORD_WRAPPING: number
|
|
43
|
+
readonly CHAR_WRAPPING: number
|
|
44
|
+
readonly CLIPPING: number
|
|
45
|
+
readonly TRUNCATING_HEAD: number
|
|
46
|
+
readonly TRUNCATING_TAIL: number
|
|
47
|
+
readonly TRUNCATING_MIDDLE: number
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export = UIKitLabel
|