[Code Quality] Remove magic numbers #4

Open
opened 2022-01-21 15:27:15 +01:00 by CommanderRedYT · 2 comments
CommanderRedYT commented 2022-01-21 15:27:15 +01:00 (Migrated from github.com)

Would it be possible to implement enums for some magic numbers?
For example, when doing tft.setTextFont(2); could be improved by doing the following:

enum class Fonts {
	Small = 2,
	Medium = 4
}
Would it be possible to implement enums for some magic numbers? For example, when doing tft.setTextFont(2); could be improved by doing the following: ```cpp enum class Fonts { Small = 2, Medium = 4 } ```
0xFEEDC0DE64 commented 2022-01-24 17:12:43 +01:00 (Migrated from github.com)

is a Font value implicitly convertable to int (as needed in the shitty TFT_eSPI lib)

int a = Fonts::Small; // does it compile ?
is a Font value implicitly convertable to int (as needed in the shitty TFT_eSPI lib) ``` int a = Fonts::Small; // does it compile ? ```
CommanderRedYT commented 2022-01-24 18:03:50 +01:00 (Migrated from github.com)

From the TFT library:

void TFT_eSPI::setTextFont(uint8_t f)
{
  textfont = (f > 0) ? f : 1; // Don't allow font 0
}

So this should mean that we could just use a enum : uint8_t, right?

From the TFT library: ```cpp void TFT_eSPI::setTextFont(uint8_t f) { textfont = (f > 0) ? f : 1; // Don't allow font 0 } ``` So this should mean that we could just use a enum : uint8_t, right?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: feedc0de/esp-gui-lib#4
No description provided.