pebble-scalable 1.6.0 → 2.0.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 +46 -30
- package/dist.zip +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# pebble-scalable
|
|
2
2
|
|
|
3
3
|
Package aiming to make it easy to make scaling layouts for different display
|
|
4
|
-
sizes by defining their dimensions only once.
|
|
4
|
+
sizes by defining their dimensions only once in an app.
|
|
5
5
|
|
|
6
6
|
- [Setting up](#setting-up)
|
|
7
7
|
- [Layout](#layout)
|
|
8
|
+
- [Constants](#constants)
|
|
8
9
|
- [Centering](#centering)
|
|
9
10
|
- [Fonts](#fonts)
|
|
10
11
|
- [Images](#images)
|
|
@@ -31,38 +32,50 @@ Get values for layout dimensions based on display size:
|
|
|
31
32
|
|
|
32
33
|
> To convert existing layouts, simply divide the raw coordinate by either the
|
|
33
34
|
> width or height of the preferred screen size to get a percentage.
|
|
34
|
-
> For example, a Y coordinate of 40px
|
|
35
|
-
> call would be `
|
|
35
|
+
> For example, a Y coordinate of 40px: 40 / 168 = 0.238 = 23.8%, so the correct
|
|
36
|
+
> call would be `scl_y(238)`.
|
|
36
37
|
|
|
37
38
|
```c
|
|
38
39
|
// Get a percentage (thousands) of the display width and height
|
|
39
|
-
const int half_w =
|
|
40
|
-
const int half_h =
|
|
40
|
+
const int half_w = scl_x(500);
|
|
41
|
+
const int half_h = scl_y(500);
|
|
41
42
|
|
|
42
43
|
// Get a GRect based only on percentage width/height
|
|
43
|
-
const GRect center_rect =
|
|
44
|
+
const GRect center_rect = scl_grect(330, 330, 330, 330);
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
If a single percentage isn't precise enough, use 'per platform' variants to
|
|
47
48
|
specify values up to 5% (50/1000 thousands) in precision for each platform
|
|
48
|
-
(order is 'regular' shape, then 'emery' shape)
|
|
49
|
+
(order is 'regular' shape, then 'emery' shape).
|
|
49
50
|
|
|
50
51
|
> In actuality, thousandths values should allow per-pixel precision until a
|
|
51
52
|
> display shape is larger than 1000px in any direction.
|
|
52
53
|
|
|
54
|
+
This is done with members of a struct for each distinct platform shape:
|
|
55
|
+
|
|
56
|
+
- `o` - "Original size": aplite, basalt, diorite, flint
|
|
57
|
+
- `c` - Chalk
|
|
58
|
+
- `e` - Emery
|
|
59
|
+
|
|
60
|
+
> This method allows transparently adding more platforms in the future without
|
|
61
|
+
> breaking existing code!
|
|
62
|
+
|
|
53
63
|
```c
|
|
54
|
-
// Larger only on Emery
|
|
55
|
-
const GRect emery =
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
// Larger only on Emery
|
|
65
|
+
const GRect emery = GRect(
|
|
66
|
+
0, 0,
|
|
67
|
+
scl_x_pp({.o = 200, .e = 250}),
|
|
68
|
+
scl_y_pp({.o = 200, .e = 250})
|
|
58
69
|
);
|
|
59
70
|
|
|
60
71
|
// Further to the right and down on Emery
|
|
61
|
-
const int x =
|
|
62
|
-
const int y =
|
|
72
|
+
const int x = scl_x_pp({.o = 110, .e = 120});
|
|
73
|
+
const int y = scl_y_pp({.o = 450, .e = 480});
|
|
63
74
|
```
|
|
64
75
|
|
|
65
|
-
|
|
76
|
+
## Constants
|
|
77
|
+
|
|
78
|
+
The library also exports constants for all platforms:
|
|
66
79
|
|
|
67
80
|
* `PS_DISP_W` - current display width.
|
|
68
81
|
* `PS_DISP_H` - current display height.
|
|
@@ -72,16 +85,16 @@ The library also exports constants:
|
|
|
72
85
|
A GRect can be centered in either the X or Y axis, or both:
|
|
73
86
|
|
|
74
87
|
```c
|
|
75
|
-
const GRect r =
|
|
88
|
+
const GRect r = scl_grect(100, 500, 200, 200);
|
|
76
89
|
|
|
77
90
|
// Center horizontally
|
|
78
|
-
const GRect centered_h =
|
|
91
|
+
const GRect centered_h = scl_center_x(r);
|
|
79
92
|
|
|
80
93
|
// Center vertically
|
|
81
|
-
const GRect centered_v =
|
|
94
|
+
const GRect centered_v = scl_center_y(r);
|
|
82
95
|
|
|
83
96
|
// Or both!
|
|
84
|
-
const GRect centered =
|
|
97
|
+
const GRect centered = scl_center(r);
|
|
85
98
|
```
|
|
86
99
|
|
|
87
100
|
## Fonts
|
|
@@ -108,33 +121,33 @@ Next, define identifiers for each of your size categories:
|
|
|
108
121
|
|
|
109
122
|
```c
|
|
110
123
|
typedef enum {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
124
|
+
FID_Small = 0,
|
|
125
|
+
FID_Medium,
|
|
126
|
+
FID_Large
|
|
127
|
+
} FontIds;
|
|
115
128
|
```
|
|
116
129
|
|
|
117
130
|
Now set which font to use per-platform shape for each category:
|
|
118
131
|
|
|
119
132
|
```c
|
|
120
133
|
// The small font - regular screens use Gothic 14, Emery uses Gothic 18
|
|
121
|
-
|
|
134
|
+
scl_set_fonts(FID_Small, {.o = s_gothic_14, .e = s_gothic_18});
|
|
122
135
|
|
|
123
136
|
// Same with larger categories
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
scl_set_fonts(FID_Medium, {.o = s_gothic_18, .e = s_gothic_24});
|
|
138
|
+
scl_set_fonts(FID_Large, {.o = s_gothic_24, .e = s_gothic_28});
|
|
126
139
|
```
|
|
127
140
|
|
|
128
141
|
During layout or drawing, simply use the font by ID:
|
|
129
142
|
|
|
130
143
|
```c
|
|
131
|
-
//
|
|
144
|
+
// Choose size ID, font is selected automatically
|
|
132
145
|
graphics_context_set_text_color(ctx, GColorBlack);
|
|
133
146
|
graphics_draw_text(
|
|
134
147
|
ctx,
|
|
135
148
|
"This text should appear in the middle third on any platform or display size",
|
|
136
|
-
|
|
137
|
-
|
|
149
|
+
scl_get_font(FID_Small),
|
|
150
|
+
scl_grect(0, 330, 1000, 330),
|
|
138
151
|
GTextOverflowModeTrailingEllipsis,
|
|
139
152
|
GTextAlignmentCenter,
|
|
140
153
|
NULL
|
|
@@ -153,7 +166,7 @@ and size. For example, `icon.png` and `icon~emery.png`.
|
|
|
153
166
|
graphics_draw_bitmap_in_rect(
|
|
154
167
|
ctx,
|
|
155
168
|
s_icon_bitmap,
|
|
156
|
-
|
|
169
|
+
scl_center_x(scl_grect(0, 850, 150, 150))
|
|
157
170
|
);
|
|
158
171
|
```
|
|
159
172
|
|
|
@@ -161,4 +174,7 @@ graphics_draw_bitmap_in_rect(
|
|
|
161
174
|
|
|
162
175
|
- [x] Support per-platform (per shape) values
|
|
163
176
|
- [x] Solution for picking bitmaps (to work with their scalable GRects)
|
|
164
|
-
- [
|
|
177
|
+
- [x] Find solution to 'ever expanding args' problem for new platforms
|
|
178
|
+
- [x] Chalk support
|
|
179
|
+
- [ ] Gabbro support
|
|
180
|
+
- [ ] Can we save devs loading all fonts when only some are used on a platform?
|
package/dist.zip
CHANGED
|
Binary file
|