Skip to content
Calvin Hass edited this page Jan 7, 2021 · 5 revisions

Tips & Tricks with GUIslice

This page is under development. Please check back again later!

External GUI control

Navigating pages with an Encoder

The following code snippet is intended to support the Teensy encoder library; others should be similar.

  // Detect encoder transition events
  bool bInc = false;
  bool bDec = false;  
  int32_t newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    if (newPosition > oldPosition) { bInc = true; }
    else { bDec = true; }
    oldPosition = newPosition;
  }
  // Advance the GUI page
  if (bInc) { // Increment
    m_nCurPage = (m_nCurPage < MAX_PAGE-1)? m_nCurPage+1 : m_nCurPage;
    gslc_SetPageCur(&m_gui,m_nCurPage);    
  } else if (bDec) { // Decrement
    m_nCurPage = (m_nCurPage > 0)? m_nCurPage-1 : m_nCurPage;
    gslc_SetPageCur(&m_gui,m_nCurPage);    
  }

Reusing Elements between Pages

If you have elements that you would like to appear on every page (eg. a navigation bar, a clock, etc.), then creating a "Base Page" might be the simplest solution. Base Page elements have the advantage that they have the most minimal memory consumption as there is only ever a single element defined.

Element Alias

Alternately, it is also possible to reuse specific elements by creating an "Element Alias". An element alias allows you to share all of the current state of an element (eg. listbox contents, selection and memory associated with it), which may also reduce the associated memory consumption.

To create an element alias, add the following line:

gslc_ElemAdd(&m_gui,E_PG3,gslc_GetElemFromRef(&m_gui,m_pElemListbox1),GSLC_ELEMREF_DEFAULT);
  • In the above, E_PG3 is the page enum where you would like the alias to be placed, and m_pElemListBox1 is the element reference you would like to copy.
  • Note that the total element count on the destination page needs to be increased by one (eg. MAX_ELEM_PG3) to accommodate the element alias.

Further reference: Issue #225

Enabling background updates with popup windows

When a popup window has been created, the background controls can still receive updates from the user code, but the redraws associated with them are disabled by default. This disabling was done to avoid redrawing any elements that are partially obscured by the popup.

In some cases it may be desirable to enable background updates (eg. a clock) for the underlying pages while a popup is active. This can be done by inserting the gslc_SetStackState() command:

gslc_PopupShow(&m_gui, E_PG_POPUP, true); // Show the popup
gslc_SetStackState(pGui, GSLC_STACK_CUR, false, true); // Re-enable background updates on current page

Further reference: Issue #227

Font Handling

TBD - list of font support options per driver / platform

  • Pconti31 has written a utility TTF2GFX that can be used in converting TTF fonts to the Adafruit-GFX format (and selecting individual glyphs to import)

Platform-specific Requirements

ESP32

  • All examples require #include "Arduino.h" in their header in order for ESP32 to work. (Thanks to @shafr)
Clone this wiki locally