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