pebble-scalable 1.5.1 → 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 +79 -29
- package/dist.zip +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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)
|
|
11
|
+
- [Images](#images)
|
|
10
12
|
|
|
11
13
|
See `include/pebble-scalable.h` for function documentation.
|
|
12
14
|
|
|
@@ -24,50 +26,75 @@ Add the includes at the top of your source.
|
|
|
24
26
|
#include <pebble-scalable/pebble-scalable.h>
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
##
|
|
29
|
+
## Layout
|
|
28
30
|
|
|
29
31
|
Get values for layout dimensions based on display size:
|
|
30
32
|
|
|
33
|
+
> To convert existing layouts, simply divide the raw coordinate by either the
|
|
34
|
+
> width or height of the preferred screen size to get a percentage.
|
|
35
|
+
> For example, a Y coordinate of 40px: 40 / 168 = 0.238 = 23.8%, so the correct
|
|
36
|
+
> call would be `scl_y(238)`.
|
|
37
|
+
|
|
31
38
|
```c
|
|
32
39
|
// Get a percentage (thousands) of the display width and height
|
|
33
|
-
const int half_w =
|
|
34
|
-
const int half_h =
|
|
40
|
+
const int half_w = scl_x(500);
|
|
41
|
+
const int half_h = scl_y(500);
|
|
35
42
|
|
|
36
43
|
// Get a GRect based only on percentage width/height
|
|
37
|
-
const GRect center_rect =
|
|
44
|
+
const GRect center_rect = scl_grect(330, 330, 330, 330);
|
|
38
45
|
```
|
|
39
46
|
|
|
40
47
|
If a single percentage isn't precise enough, use 'per platform' variants to
|
|
41
48
|
specify values up to 5% (50/1000 thousands) in precision for each platform
|
|
42
|
-
(order is 'regular' shape, then 'emery' shape)
|
|
49
|
+
(order is 'regular' shape, then 'emery' shape).
|
|
50
|
+
|
|
51
|
+
> In actuality, thousandths values should allow per-pixel precision until a
|
|
52
|
+
> display shape is larger than 1000px in any direction.
|
|
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!
|
|
43
62
|
|
|
44
63
|
```c
|
|
45
|
-
// Larger only on Emery
|
|
46
|
-
const GRect emery =
|
|
47
|
-
|
|
48
|
-
|
|
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})
|
|
49
69
|
);
|
|
50
70
|
|
|
51
71
|
// Further to the right and down on Emery
|
|
52
|
-
const int x =
|
|
53
|
-
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});
|
|
54
74
|
```
|
|
55
75
|
|
|
76
|
+
## Constants
|
|
77
|
+
|
|
78
|
+
The library also exports constants for all platforms:
|
|
79
|
+
|
|
80
|
+
* `PS_DISP_W` - current display width.
|
|
81
|
+
* `PS_DISP_H` - current display height.
|
|
82
|
+
|
|
56
83
|
## Centering
|
|
57
84
|
|
|
58
85
|
A GRect can be centered in either the X or Y axis, or both:
|
|
59
86
|
|
|
60
87
|
```c
|
|
61
|
-
const GRect r =
|
|
88
|
+
const GRect r = scl_grect(100, 500, 200, 200);
|
|
62
89
|
|
|
63
90
|
// Center horizontally
|
|
64
|
-
const GRect centered_h =
|
|
91
|
+
const GRect centered_h = scl_center_x(r);
|
|
65
92
|
|
|
66
93
|
// Center vertically
|
|
67
|
-
const GRect centered_v =
|
|
94
|
+
const GRect centered_v = scl_center_y(r);
|
|
68
95
|
|
|
69
96
|
// Or both!
|
|
70
|
-
const GRect centered =
|
|
97
|
+
const GRect centered = scl_center(r);
|
|
71
98
|
```
|
|
72
99
|
|
|
73
100
|
## Fonts
|
|
@@ -75,6 +102,10 @@ const GRect centered = scalable_center(r);
|
|
|
75
102
|
Use different fonts for different display sizes, based on a category of your
|
|
76
103
|
choosing. First, load the fonts, or use system fonts:
|
|
77
104
|
|
|
105
|
+
> For custom fonts, scaling up the raw font size by the corresponding increase
|
|
106
|
+
> in display size (such as 14% for basalt > emery) may not be enough.
|
|
107
|
+
> Experiment!
|
|
108
|
+
|
|
78
109
|
```c
|
|
79
110
|
// Load fonts to use in each case
|
|
80
111
|
static GFont s_gothic_14, s_gothic_18, s_gothic_24, s_gothic_28;
|
|
@@ -90,41 +121,60 @@ Next, define identifiers for each of your size categories:
|
|
|
90
121
|
|
|
91
122
|
```c
|
|
92
123
|
typedef enum {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
124
|
+
FID_Small = 0,
|
|
125
|
+
FID_Medium,
|
|
126
|
+
FID_Large
|
|
127
|
+
} FontIds;
|
|
97
128
|
```
|
|
98
129
|
|
|
99
130
|
Now set which font to use per-platform shape for each category:
|
|
100
131
|
|
|
101
132
|
```c
|
|
102
133
|
// The small font - regular screens use Gothic 14, Emery uses Gothic 18
|
|
103
|
-
|
|
134
|
+
scl_set_fonts(FID_Small, {.o = s_gothic_14, .e = s_gothic_18});
|
|
104
135
|
|
|
105
136
|
// Same with larger categories
|
|
106
|
-
|
|
107
|
-
|
|
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});
|
|
108
139
|
```
|
|
109
140
|
|
|
110
141
|
During layout or drawing, simply use the font by ID:
|
|
111
142
|
|
|
112
143
|
```c
|
|
113
|
-
//
|
|
144
|
+
// Choose size ID, font is selected automatically
|
|
114
145
|
graphics_context_set_text_color(ctx, GColorBlack);
|
|
115
146
|
graphics_draw_text(
|
|
116
147
|
ctx,
|
|
117
148
|
"This text should appear in the middle third on any platform or display size",
|
|
118
|
-
|
|
119
|
-
|
|
149
|
+
scl_get_font(FID_Small),
|
|
150
|
+
scl_grect(0, 330, 1000, 330),
|
|
120
151
|
GTextOverflowModeTrailingEllipsis,
|
|
121
152
|
GTextAlignmentCenter,
|
|
122
153
|
NULL
|
|
123
154
|
);
|
|
124
155
|
```
|
|
125
156
|
|
|
157
|
+
## Images
|
|
158
|
+
|
|
159
|
+
Images can be selected per-platform using the SDK's
|
|
160
|
+
[resource tagging](https://developer.rebble.io/guides/app-resources/platform-specific/)
|
|
161
|
+
system. From there, scalable layout functions can be used to set the position
|
|
162
|
+
and size. For example, `icon.png` and `icon~emery.png`.
|
|
163
|
+
|
|
164
|
+
```c
|
|
165
|
+
// Draw image centered at the bottom - image is 24x24px as a base size, so about 15% width
|
|
166
|
+
graphics_draw_bitmap_in_rect(
|
|
167
|
+
ctx,
|
|
168
|
+
s_icon_bitmap,
|
|
169
|
+
scl_center_x(scl_grect(0, 850, 150, 150))
|
|
170
|
+
);
|
|
171
|
+
```
|
|
172
|
+
|
|
126
173
|
## TODO
|
|
127
174
|
|
|
128
175
|
- [x] Support per-platform (per shape) values
|
|
129
|
-
- [
|
|
130
|
-
- [
|
|
176
|
+
- [x] Solution for picking bitmaps (to work with their scalable GRects)
|
|
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
|