Skip to content

Commit

Permalink
- multipage: fixed a few minor table issues
Browse files Browse the repository at this point in the history
- multipage: changed what to update based on property IDs
- multipage: added addModalPage() to scripted multipage dialog component
  • Loading branch information
christoph-hart committed Jul 9, 2024
1 parent f7bb136 commit b085387
Show file tree
Hide file tree
Showing 14 changed files with 2,438 additions and 2,152 deletions.
125 changes: 122 additions & 3 deletions hi_scripting/scripting/api/ScriptingApiContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5657,6 +5657,8 @@ struct ScriptingApi::Content::ScriptMultipageDialog::Wrapper
API_METHOD_WRAPPER_3(ScriptMultipageDialog, add);
API_METHOD_WRAPPER_2(ScriptMultipageDialog, navigate);
API_METHOD_WRAPPER_3(ScriptMultipageDialog, bindCallback);
API_METHOD_WRAPPER_0(ScriptMultipageDialog, addModalPage);
API_VOID_METHOD_WRAPPER_3(ScriptMultipageDialog, showModalPage);
API_VOID_METHOD_WRAPPER_1(ScriptMultipageDialog, setOnFinishCallback);
API_VOID_METHOD_WRAPPER_1(ScriptMultipageDialog, setOnPageLoadCallback);
API_VOID_METHOD_WRAPPER_1(ScriptMultipageDialog, show);
Expand Down Expand Up @@ -5707,11 +5709,13 @@ ScriptingApi::Content::ScriptMultipageDialog::ScriptMultipageDialog(ProcessorWit

ADD_API_METHOD_0(resetDialog);
ADD_API_METHOD_0(addPage);
ADD_API_METHOD_0(addModalPage);
ADD_API_METHOD_3(add);
ADD_API_METHOD_3(bindCallback);
ADD_API_METHOD_1(setOnFinishCallback);
ADD_API_METHOD_1(setOnPageLoadCallback);
ADD_API_METHOD_1(show);
ADD_API_METHOD_3(showModalPage);
ADD_API_METHOD_2(navigate);
ADD_API_METHOD_0(cancel);
ADD_API_METHOD_3(setElementProperty);
Expand Down Expand Up @@ -5835,6 +5839,11 @@ void ScriptingApi::Content::ScriptMultipageDialog::resetDialog()
}

int ScriptingApi::Content::ScriptMultipageDialog::addPage()
{
return addPageInternal(false);
}

int ScriptingApi::Content::ScriptMultipageDialog::addPageInternal(bool isModal)
{
using namespace multipage;

Expand All @@ -5843,12 +5852,71 @@ int ScriptingApi::Content::ScriptMultipageDialog::addPage()
no->setProperty(mpid::Type, "List");
no->setProperty(mpid::Children, Array<var>());

pages.add(var(no.get()));
if(isModal)
modalPages.add(var(no.get()));
else
pages.add(var(no.get()));

elementData.add(var(no.get()));

return elementData.size()-1;
}

int ScriptingApi::Content::ScriptMultipageDialog::addModalPage()
{
return addPageInternal(true);

}

void ScriptingApi::Content::ScriptMultipageDialog::showModalPage(int pageIndex, var modalState, var finishCallback)
{
if(isPositiveAndBelow(pageIndex, elementData.size()))
{
auto v = elementData[pageIndex];

if(modalPages.contains(v))
{
onModalFinish = new ValueCallback(this, "onModalFinish", finishCallback, dispatch::DispatchType::sendNotificationAsync);

MessageManager::callAsync([v, modalState, pageIndex, this]()
{
multipage::Factory f;

if(auto x = f.create(v))
{
x->setStateObject(modalState);

x->setCustomCheckFunction([this, modalState, pageIndex](multipage::Dialog::PageBase*, const var& obj)
{
var thisObject;
var a[2];

a[0] = var(pageIndex);
a[1] = modalState;

var::NativeFunctionArgs args(thisObject, a, 2);
this->onModalFinish->operator()(args);
return Result::ok();
});

if(auto fd = getMultipageState()->getFirstDialog())
fd->showModalPopup(true, x);
}






});
}
else
{
reportScriptError(String(pageIndex) + " is not a modal page");
}
}
}

int ScriptingApi::Content::ScriptMultipageDialog::add(int parentIndex, String type, const var& properties)
{
using namespace multipage;
Expand Down Expand Up @@ -5943,10 +6011,61 @@ void ScriptingApi::Content::ScriptMultipageDialog::setElementProperty(int elemen
{
if(isPositiveAndBelow(elementId, elementData.size()))
{
DynamicObject::Ptr obj = elementData[elementId].getDynamicObject();


auto infoObject = elementData[elementId];
DynamicObject::Ptr obj = infoObject.getDynamicObject();

obj->setProperty(propertyId, newValue);
sendRepaintMessage();

auto updateType = multipage::mpid::Helpers::getUpdateType(Identifier(propertyId));

for(auto c: getMultipageState()->currentDialogs)
{
SafeAsyncCall::call<multipage::Dialog>(*c, [infoObject, updateType](multipage::Dialog& d)
{
if(updateType == multipage::mpid::Helpers::RequiredUpdate::FullRebuild)
{
d.refreshCurrentPage();
return;
}

if(auto pb = d.findPageBaseForInfoObject(infoObject))
{
if(updateType == multipage::mpid::Helpers::RequiredUpdate::UpdateCSS)
{
pb->updateStyleSheetInfo(true);
d.css.clearCache(pb);
return;
}
if(updateType == multipage::mpid::Helpers::RequiredUpdate::UpdateVisibility)
{
if(auto c = pb->findParentComponentOfClass<multipage::factory::Container>())
{
c->updateChildVisibility();
}
return;
}
if(updateType == multipage::mpid::Helpers::RequiredUpdate::ResizeParent)
{
if(auto p = pb->findParentComponentOfClass<multipage::Dialog::PageBase>())
{
p->postInit();
}

return;
}
if(updateType == multipage::mpid::Helpers::RequiredUpdate::PostInit)
{
pb->postInit();
pb->resized();
pb->repaint();
return;
}
}
});
}

}
}

Expand Down
11 changes: 11 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,12 @@ class ScriptingApi::Content : public ScriptingObject,
/** Adds a page to the dialog and returns the element index of the page. */
int addPage();

/** Adds a modal page to the dialog that can be populated like a normal page and shown using showModalPage(). */
int addModalPage();

/** Shows a modal page with the given index and the state object. */
void showModalPage(int pageIndex, var modalState, var finishCallback);

/** Adds an element to the parent with the given type and properties. */
int add(int parentIndex, String type, const var& properties);

Expand Down Expand Up @@ -2420,10 +2426,15 @@ class ScriptingApi::Content : public ScriptingObject,
const dispatch::DispatchType n;
};

ScopedPointer<ValueCallback> onModalFinish;

OwnedArray<ValueCallback> valueCallbacks;

var createDialogData(String cssToUse={});

int addPageInternal(bool isModal);

Array<var> modalPages;
Array<var> pages;
Array<var> elementData;

Expand Down
Loading

0 comments on commit b085387

Please sign in to comment.