[Docs] Refactor code examples (#18003)

This commit is contained in:
Albert Y 2022-08-13 08:27:24 +08:00 committed by GitHub
parent 1a4a278251
commit 70c6b183df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 31 deletions

View File

@ -125,34 +125,37 @@ Layer conditions can also be used with the callback function like the following:
```c ```c
bool encoder_update_user(uint8_t index, bool clockwise) { bool encoder_update_user(uint8_t index, bool clockwise) {
if (get_highest_layer(layer_state|default_layer_state) > 0) { switch(get_highest_layer(layer_state|default_layer_state)) {
if (index == 0) { case 0:
if (clockwise) { if (index == 0) {
tap_code(KC_WH_D); if (clockwise) {
} else { tap_code(KC_PGDN);
tap_code(KC_WH_U); } else {
tap_code(KC_PGUP);
}
} else if (index == 1) {
if (clockwise) {
rgb_matrix_increase_speed();
} else {
rgb_matrix_decrease_speed();
}
} }
} else if (index == 1) { break;
if (clockwise) { case 1:
tap_code_delay(KC_VOLU, 10); if (index == 0) {
} else { if (clockwise) {
tap_code_delay(KC_VOLD, 10); tap_code(KC_WH_D);
} else {
tap_code(KC_WH_U);
}
} else if (index == 1) {
if (clockwise) {
tap_code_delay(KC_VOLU, 10);
} else {
tap_code_delay(KC_VOLD, 10);
}
} }
} break;
} else { /* Layer 0 */
if (index == 0) {
if (clockwise) {
tap_code(KC_PGDN);
} else {
tap_code(KC_PGUP);
}
} else if (index == 1) {
if (clockwise) {
rgb_matrix_increase_speed();
} else {
rgb_matrix_decrease_speed();
}
}
} }
return false; return false;
} }

View File

@ -889,15 +889,15 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
} }
``` ```
Layer indicator on all flagged keys: Layer indicator on all keys:
```c ```c
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
for (uint8_t i = led_min; i <= led_max; i++) { for (uint8_t i = led_min; i <= led_max; i++) {
switch(get_highest_layer(layer_state|default_layer_state)) { switch(get_highest_layer(layer_state|default_layer_state)) {
case RAISE: case 2:
rgb_matrix_set_color(i, RGB_BLUE); rgb_matrix_set_color(i, RGB_BLUE);
break; break;
case LOWER: case 1:
rgb_matrix_set_color(i, RGB_YELLOW); rgb_matrix_set_color(i, RGB_YELLOW);
break; break;
default: default:
@ -907,7 +907,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
} }
``` ```
Layer indicator with only configured keys: Layer indicator only on keys with configured keycodes:
```c ```c
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if (get_highest_layer(layer_state) > 0) { if (get_highest_layer(layer_state) > 0) {

View File

@ -20,7 +20,6 @@ Not sure which text editor to use?
Editors specifically made for code: Editors specifically made for code:
* [Sublime Text](https://www.sublimetext.com/) * [Sublime Text](https://www.sublimetext.com/)
* [VS Code](https://code.visualstudio.com/) * [VS Code](https://code.visualstudio.com/)
* [Atom](https://atom.io/)
### Git resources ### Git resources