Skip to content

Menu structure objects

Rui Azevedo edited this page Oct 12, 2017 · 7 revisions

Menu structure objects

Menu structure objects are somehow complicated in great extent due to flash memory (PROGMEM) usage and the AVR architecture along with the bad combination of C++.

That said, you should take some caution when messing around with them, specially do not try to read pointers to flash, and there are some on menu structures, with regular reading memory functions like print or println or any other that read data from ram.

Anyway I will only present some basic aspects of the objects and its hierarchy.

Prompt (OP)

Prompts are the most basic menu structure it derives from an Action and associate it with a text.

They can be constructed by macro OP. (see menu definition)

Here is an example of initializing an option without macros for an non-AVR (PROGMEM) device.

//define "Op 1"
void op1Func();
promptShadow op1Info("Op 1",(callback)op1Func,enterEvent);
prompt op1(op1Info);

And here the same for an AVR (PROGMEM) device.

//define "Op 1"
void op1Func();
const char op1Text[] PROGMEM="Op 1";
const promptShadowRaw op1InfoRaw PROGMEM={(callback)op1Func,\_noStyle,op1Text,enterEvent,noStyle};
const promptShadow& op1Info=*(promptShadow*)&op1InfoRaw;
prompt op1(op1Info);

OP macro automates all of that, but it must be used inside a MENU macro.

navTarget

public prompt

This is an intermediate class of all menu elements that can process keys by definming:

virtual void parseInput(navNode& nav,Stream& in);

parse one character from the input in the given navigation context.

where:

nav navigation context pointing to current menu with information about selection (see navNode).

in the input stream.

virtual void doNav(navNode& nav,navCmd cmd);

execute the navigation command within the navigation context

nav navigation context pointing to current menu with information about selection (see navNode).

cmd the navigation command (see navCmds)

menuNode

public navTarget

All menu elements that contain a list of other menu elements (like: menu, toggle, choose, select).

inline prompt& operator[](idx_t i) const

access sub-element by index

where:

i the index number of the element

bool changed(const navNode &nav,const menuOut& out,bool sub=true) override;

returns true if this element needs to be redraw on the output devices

where:

nav the navigation context

out the output device

sub true to also check sub elements

inline idx_t sz() const

returns the numbers of contained elements (list size)

inline prompt* const* data() const

get the array of data, caution this might be on flash memory

prompt* seek(idx_t* uri,idx_t len) override;

experimental function for assync navigation and web interface

bool async(const char *uri,navRoot& root,idx_t lvl=0) override;

experimental function for assync navigation and web interface

menu

public menuNode

Just a raw menu implementation straight from its base class menuNode. no extra functions added.

menuField

public navTarget

interact with a ranged numeric value by changing and trimming it inside bounds.

bool tunning=false;

true if the field edition is on fine tuning phase.

T reflex

a copy of the last edited value to detect external changes and signal changed to reflect the change back to the menu user.

Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len) override;

print this element on a menu output device

return: the remaining space

where:

root the navigation root

sel is this element selected

out the output device

idx the given index in case device needs to print accelerators

len allowed length to be used

inline T& target() const

get the original target value

inline const char* units()

get units string, caution this might be on flash memory.

inline T low() const

get lower bound

inline T high() const

get upper bound

inline T step()

get the increment step

inline T tune() const

get the tuning step

## void clamp()

force value into bounds

menuValue

public prompt

represents the allowed values on enumerated fields (Toggle, Select, Choice)

menuVariant

public menuNode

base for all enumerated fields (Toggle, select, Choice)

idx_t sync()

Synchronize the selected value with the variable (assuming that the variable can not have values other than the enumerated ones)

idx_t sync(idx_t i)

Synchronize the variable value with the selection

virtual idx_t selected() const

get the selected index

select

public menuVariant<T>

enumerated field, click and scroll to select value in place.

toggle

public menuVariant<T>

enumerated field, click to change value

choose

public menuVariant<T>

enumerated field, click to select value as a sub-menu