option search improvements

1. Top-level menu names are now properly handled.
2. Changing "Any or All terms" option now immediately updates the results.
3. Reformatted menu.zs to have tabs instead of spaces.
This commit is contained in:
Alexander 2019-03-17 16:17:12 +07:00 committed by Christoph Oelckers
parent b515ac662e
commit dbb93d6c08
5 changed files with 194 additions and 158 deletions

View file

@ -256,6 +256,7 @@ version "3.8"
#include "zscript/ui/menu/search/menu.zs"
#include "zscript/ui/menu/search/searchfield.zs"
#include "zscript/ui/menu/search/query.zs"
#include "zscript/ui/menu/search/anyoralloption.zs"
#include "zscript/ui/statscreen/statscreen.zs"
#include "zscript/ui/statscreen/statscreen_coop.zs"

View file

@ -0,0 +1,33 @@
//=============================================================================
//
// os_AnyOrAllOption class represents an Option Item for Option Search menu.
// Changing the value of this option causes the menu to refresh the search
// results.
//
//=============================================================================
class os_AnyOrAllOption : OptionMenuItemOption
{
os_AnyOrAllOption Init(os_Menu menu)
{
Super.Init("", "os_isanyof", "os_isanyof_values");
mMenu = menu;
return self;
}
override bool MenuEvent(int mkey, bool fromcontroller)
{
bool result = Super.MenuEvent(mkey, fromcontroller);
if (mKey == Menu.MKEY_Left || mKey == Menu.MKEY_Right)
{
mMenu.search();
}
return result;
}
private os_Menu mMenu;
}

View file

@ -21,15 +21,17 @@ class os_Menu : OptionMenu
mDesc.CalcIndent();
}
void search(os_Query query)
void search()
{
string text = mSearchField.GetText();
let query = os_Query.fromString(text);
bool isAnyTermMatches = mIsAnyOfItem.mCVar.GetBool();
mDesc.mItems.clear();
addSearchField(query.getText());
addSearchField(text);
string path = StringTable.Localize("$OPTMNU_TITLE");
bool isAnyTermMatches = mIsAnyOfItem.mCVar.GetBool();
bool found = listOptions(mDesc, "MainMenu", query, path, isAnyTermMatches);
bool found = listOptions(mDesc, "MainMenu", query, "", isAnyTermMatches);
if (!found) { addNoResultsItem(mDesc); }
@ -39,11 +41,11 @@ class os_Menu : OptionMenu
private void addSearchField(string query = "")
{
string searchLabel = StringTable.Localize("$OS_LABEL");
let searchField = new("os_SearchField").Init(searchLabel, self, query);
mIsAnyOfItem = new("OptionMenuItemOption").Init("", "os_isanyof", "os_isanyof_values");
mSearchField = new("os_SearchField").Init(searchLabel, self, query);
mIsAnyOfItem = new("os_AnyOrAllOption").Init(self);
mDesc.mItems.push(searchField);
mDesc.mItems.push(mSearchField);
mDesc.mItems.push(mIsAnyOfItem);
addEmptyLine(mDesc);
}
@ -85,9 +87,10 @@ class os_Menu : OptionMenu
{
let item = sourceDesc.mItems[i];
string actionN = item.GetAction();
string newPath = (actionN == "Optionsmenu")
? StringTable.Localize("$OPTMNU_TITLE")
: StringTable.Localize("$OS_MAIN");
let textItem = ListMenuItemTextItem(item);
string newPath = textItem
? makePath(path, textItem.mText)
: path;
found |= listOptions(targetDesc, actionN, query, newPath, isAnyTermMatches);
}
@ -158,6 +161,8 @@ class os_Menu : OptionMenu
private static string makePath(string path, string label)
{
if (path.length() == 0) { return label; }
int pathWidth = SmallFont.StringWidth(path .. "/" .. label);
int screenWidth = Screen.GetWidth();
bool isTooWide = (pathWidth > screenWidth / 3);
@ -208,5 +213,6 @@ class os_Menu : OptionMenu
desc.mItems.push(text);
}
private OptionMenuItemOption mIsAnyOfItem;
private os_AnyOrAllOption mIsAnyOfItem;
private os_SearchField mSearchField;
}

View file

@ -19,8 +19,6 @@ class os_Query
str.Split(query.mQueryParts, " ", TOK_SKIPEMPTY);
query.mText = str;
return query;
}
@ -31,8 +29,6 @@ class os_Query
: matchesAll(text);
}
string getText() { return mText; }
// private: //////////////////////////////////////////////////////////////////
private bool matchesAny(string text)
@ -73,6 +69,5 @@ class os_Query
return contains;
}
private string mText;
private Array<String> mQueryParts;
}

View file

@ -30,10 +30,9 @@ class os_SearchField : OptionMenuItemTextField
}
if (mkey == Menu.MKEY_Input)
{
string text = mEnter.GetText();
let query = os_Query.fromString(text);
mtext = mEnter.GetText();
mMenu.search(query);
mMenu.search();
}
return Super.MenuEvent(mkey, fromcontroller);
@ -46,6 +45,8 @@ class os_SearchField : OptionMenuItemTextField
: mText;
}
String GetText() { return mText; }
private os_Menu mMenu;
private string mText;
}