pebble-scalable 1.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 +103 -0
- package/dist.zip +0 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# pebble-scalable
|
|
2
|
+
|
|
3
|
+
Package aiming to make it easy to make scaling layouts for different screen
|
|
4
|
+
sizes by defining their dimension only one.
|
|
5
|
+
|
|
6
|
+
- [Setting up](#setting-up)
|
|
7
|
+
- [Dimensions](#dimensions)
|
|
8
|
+
- [Centering](#centering)
|
|
9
|
+
- [Fonts](#fonts)
|
|
10
|
+
|
|
11
|
+
See `include/pebble-scalable.h` for function documentation.
|
|
12
|
+
|
|
13
|
+
## Setting up
|
|
14
|
+
|
|
15
|
+
Install the Pebble packages:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ pebble package install pebble-scalable
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Add the includes at the top of your source.
|
|
22
|
+
|
|
23
|
+
```c
|
|
24
|
+
#include <pebble-scalable/pebble-scalable.h>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Dimensions
|
|
28
|
+
|
|
29
|
+
Get values for layout dimensions based on screen size:
|
|
30
|
+
|
|
31
|
+
```c
|
|
32
|
+
// Get a percentage of the screen width and height
|
|
33
|
+
const int half_w = scalable_x(50);
|
|
34
|
+
const int half_h = scalable_y(50);
|
|
35
|
+
|
|
36
|
+
// Get a GRect based only on percentage width/height
|
|
37
|
+
const GRect center_rect = scalable_grect(33, 33, 33, 33);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If a percentage isn't precise enough, the x/y or w/h can be nudged by some pixels:
|
|
41
|
+
|
|
42
|
+
```c
|
|
43
|
+
// A rect nudged by 5px in x and 2px in y
|
|
44
|
+
const GRect precise = scalable_nudge_xy(scalable_grect(10, 10, 20, 20), 5, 2);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Centering
|
|
48
|
+
|
|
49
|
+
A GRect can be centered in either the X or Y axis, or both:
|
|
50
|
+
|
|
51
|
+
```c
|
|
52
|
+
const GRect r = scalable_grect(10, 50, 20, 20);
|
|
53
|
+
|
|
54
|
+
// Center horizontally
|
|
55
|
+
const GRect centered_h = scalable_center_x(r);
|
|
56
|
+
|
|
57
|
+
// Center vertically
|
|
58
|
+
const GRect centered_v = scalable_center_y(r);
|
|
59
|
+
|
|
60
|
+
// Or both!
|
|
61
|
+
const GRect centered = scalable_center(r);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Fonts
|
|
65
|
+
|
|
66
|
+
Use different fonts for different screen sizes, based on a category of 'small',
|
|
67
|
+
'medium', or 'large'.
|
|
68
|
+
|
|
69
|
+
```c
|
|
70
|
+
// Load fonts to use in each case
|
|
71
|
+
static GFont s_gothic_18, s_gothic_24;
|
|
72
|
+
|
|
73
|
+
// During init
|
|
74
|
+
s_gothic_18 = fonts_get_system_font(FONT_KEY_GOTHIC_18);
|
|
75
|
+
s_gothic_24 = fonts_get_system_font(FONT_KEY_GOTHIC_24);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Specify which screen sizes should use which fonts for each size
|
|
79
|
+
|
|
80
|
+
```c
|
|
81
|
+
// Regular screens use Gothic 18, Chalk is N/A, Emery uses Gothic 24
|
|
82
|
+
scalable_set_medium_fonts(&s_gothic_18, NULL, &s_gothic_24);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
During layout or drawing, simply use the font by its size:
|
|
86
|
+
|
|
87
|
+
```c
|
|
88
|
+
// Text in the vertical middle third!
|
|
89
|
+
graphics_context_set_text_color(ctx, GColorBlack);
|
|
90
|
+
graphics_draw_text(
|
|
91
|
+
ctx,
|
|
92
|
+
"This text should appear in the middle third on any platform or screen size",
|
|
93
|
+
scalable_get_medium_font(),
|
|
94
|
+
scalable_grect(0, 33, 100, 33),
|
|
95
|
+
GTextOverflowModeTrailingEllipsis,
|
|
96
|
+
GTextAlignmentCenter,
|
|
97
|
+
NULL
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## TODO
|
|
102
|
+
|
|
103
|
+
- [ ] What other things need to be set based on size and/or platform aside from position and font size?
|
package/dist.zip
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pebble-scalable",
|
|
3
|
+
"author": "Chris Lewis",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist.zip"
|
|
7
|
+
],
|
|
8
|
+
"keywords": [
|
|
9
|
+
"pebble-package"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {},
|
|
12
|
+
"pebble": {
|
|
13
|
+
"projectType": "package",
|
|
14
|
+
"sdkVersion": "3",
|
|
15
|
+
"targetPlatforms": [
|
|
16
|
+
"aplite",
|
|
17
|
+
"basalt",
|
|
18
|
+
"chalk",
|
|
19
|
+
"diorite",
|
|
20
|
+
"emery",
|
|
21
|
+
"flint"
|
|
22
|
+
],
|
|
23
|
+
"resources": {
|
|
24
|
+
"media": []
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|