Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports setting single one menu attributes #58

Closed
TimonPeng opened this issue Aug 27, 2022 · 2 comments
Closed

Supports setting single one menu attributes #58

TimonPeng opened this issue Aug 27, 2022 · 2 comments

Comments

@TimonPeng
Copy link

When I want to setting only one or a a little attributes, it need to fill complete instance here. Do you want to support a set function like setMenuItemHeight etc.?

before:

GEM_u8g2 menu(u8g2, /*menuPointerType_=*/GEM_POINTER_ROW,
              /*menuItemsPerScreen_=*/GEM_ITEMS_COUNT_AUTO,
              /*menuItemHeight_=*/12,
              /*menuPageScreenTopOffset_=*/10, /*menuValuesLeftOffset_=*/86);

after:

GEM_u8g2 menu(u8g2);
menu.setMenuItemHeight(12);
@Spirik
Copy link
Owner

Spirik commented Aug 27, 2022

I can see that being convenient way of adjusting menu appearance on per parameter basis, but since the memory footprint is of a high concern (Example-03 barely fits on Arduino UNO in some versions of GEM) and this is generally done only once in the sketch, I figured that managing appearance simply through constructor arguments is a better way to go about it. So adding this is not of a high priority as of now, unfortunately. But at least I can run some tests to check how adding these new methods impacts compile size.

@Spirik
Copy link
Owner

Spirik commented Dec 28, 2023

Digging up this thread=)

Recently (1.5.0), added GEMAppearance struct and ::setAppearance() methods which allow to set appearance of menu pages individually (and even change at runtime).

Among other things, this makes it possible to change appearance parameters individually by editing corresponding properties of GEMAppearance object, like so:

// Create menu object (its appearance settings will be populated with default values)
GEM menu(glcd);

...

void setupMenu() {
  ...
  // Create GEMAppearance object with general values (that will be used for every menu page if not overridden)
  GEMAppearance appearanceGeneral;
  appearanceGeneral.menuPointerType = GEM_POINTER_DASH;
  appearanceGeneral.menuItemsPerScreen = GEM_ITEMS_COUNT_AUTO;
  appearanceGeneral.menuItemHeight = 10;
  appearanceGeneral.menuPageScreenTopOffset = 10;
  appearanceGeneral.menuValuesLeftOffset = 86;

  // Set appearanceGeneral as a general appearance of the menu
  menu.setAppearance(appearanceGeneral);
  ...
}

Note though, that GEMAppearance doesn't have default values, so it is necessary to set each property explicitly.

Also it is possible to call GEMPage::setAppearance() method on each page individually, passing pointer to GEMAppearance object (rather than object itself in case of GEM::setAppearance() method).

// Create empty GEMAppearance object (its values can be populated later in sketch).
// Note that it should be created in a global scope of the sketch (in order to be passed as a pointer to menu page)
GEMAppearance appearanceSettings;

// Create menu object (its appearance settings will be populated with default values)
GEM menu(glcd);

...

// Later in sketch, e.g. in setupMenu()
void setupMenu() {
  ...
  // Create GEMAppearance object with general values (that will be used for every menu page if not overridden)
  GEMAppearance appearanceGeneral;
  appearanceGeneral.menuPointerType = GEM_POINTER_ROW;
  appearanceGeneral.menuItemsPerScreen = GEM_ITEMS_COUNT_AUTO;
  appearanceGeneral.menuItemHeight = 10;
  appearanceGeneral.menuPageScreenTopOffset = 10;
  appearanceGeneral.menuValuesLeftOffset = 86;

  // Set appearanceGeneral as a general appearance of the menu
  menu.setAppearance(appearanceGeneral); // Note there is no `&` operator when setting general (or global) appearance of the menu

  // Copy values from appearanceGeneral object to appearanceSettings for further customization
  appearanceSettings = appearanceGeneral;
  appearanceSettings.menuValuesLeftOffset = 70;
  menuPageSettings.setAppearance(&appearanceSettings); // Note `&` operator
  ...
}

That's basically it. Readme and wiki may provide additional information.

@Spirik Spirik closed this as completed Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants