Skip to content

Commit

Permalink
Finish the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
vczh committed Apr 3, 2017
1 parent d10136c commit dedd932
Show file tree
Hide file tree
Showing 8 changed files with 683 additions and 15 deletions.
15 changes: 12 additions & 3 deletions Import/VlppWorkflowCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,11 @@ ContextFreeModuleDesugar

void Traverse(WfCastResultInterfaceDeclaration* node)override
{
if (node->expandedDeclarations.Count() > 0)
{
return;
}

auto decl = MakePtr<WfClassDeclaration>();
node->expandedDeclarations.Add(decl);
decl->kind = WfClassKind::Interface;
Expand Down Expand Up @@ -5876,11 +5881,15 @@ GenerateFlowChart
void Visit(WfReferenceExpression* node)override
{
copy_visitor::ExpressionVisitor::Visit(node);
auto resolvingResult = manager->expressionResolvings[node];
vint index = referenceRenaming.Keys().IndexOf(resolvingResult.symbol.Obj());
vint index = manager->expressionResolvings.Keys().IndexOf(node);
if (index != -1)
{
result.Cast<WfReferenceExpression>()->name.value = referenceRenaming.Values()[index];
auto resolvingResult = manager->expressionResolvings.Values()[index];
vint index = referenceRenaming.Keys().IndexOf(resolvingResult.symbol.Obj());
if (index != -1)
{
result.Cast<WfReferenceExpression>()->name.value = referenceRenaming.Values()[index];
}
}
}
};
Expand Down
Binary file modified Tools/GacGen.exe
Binary file not shown.
27 changes: 26 additions & 1 deletion Tutorial/GacUI_Controls/ProgressAndAsync/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,39 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
return SetupWindowsDirect2DRenderer();
}

class ViewModel : public Object, public demo::IViewModel
{
public:
void BeginDownload(const ::vl::Func<void(::vl::vint32_t)>& progress, const ::vl::Func<void(const ::vl::WString&)>& callback)override
{
GetApplication()->InvokeAsync([=]()
{
HttpRequest request;
request.SetHost(L"http://www.microsoft.com/");

HttpResponse response;
HttpQuery(request, response);

// This is a fake progress, it is just for demo
progress(1);
for (vint i = 2; i <= 10; i++)
{
Sleep(500);
progress(i);
}
callback(response.GetBodyUtf8());
});
}
};

void GuiMain()
{
{
FileStream fileStream(L"../UIRes/ProgressAndAsync.bin", FileStream::ReadOnly);
auto resource = GuiResource::LoadPrecompiledBinary(fileStream);
GetResourceManager()->SetResource(L"Resource", resource);
}
demo::MainWindow window;
demo::MainWindow window(new ViewModel);
window.MoveToScreenCenter();
GetApplication()->Run(&window);
}
75 changes: 74 additions & 1 deletion Tutorial/GacUI_Controls/ProgressAndAsync/UI/Resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,84 @@
<Text name="Name">Demo</Text>
</Folder>
</Folder>
<Script name="ViewModelResource">
<Workflow>
<![CDATA[
module viewmodel;
using system::*;
namespace demo
{
$interface IStringAsync : Async<string>;
interface IViewModel
{
func BeginDownload(progress:func(int):void, callback:func(string):void) : void;
static func DownloadAsync(viewModel : IViewModel^, progress:func(int):void) : IStringAsync^
{
var future = Future::Create();
var promise = future.Promise;
viewModel.BeginDownload(progress, func(result : string):void
{
promise.SendResult(result);
});
return new IStringAsync^(using future of Async^);
}
}
}
]]>
</Workflow>
</Script>
<Folder name="MainWindow">
<Instance name="MainWindowResource">
<Instance ref.CodeBehind="false" ref.Class="demo::MainWindow">
<Window Text="ProgressAndAsync" ClientSize="x:480 y:320">
<ref.Parameter Name="ViewModel" Class="demo::IViewModel"/>
<Window ref.Name="self" Text="ProgressAndAsync" ClientSize="x:480 y:320">
<att.BoundsComposition-set PreferredMinSize="x:480 y:320"/>
<Table CellPadding="5" AlignmentToParent="left:0 top:0 right:0 bottom:0">
<att.Rows>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
</att.Rows>
<att.Columns>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
<CellOption>composeType:MinSize</CellOption>
</att.Columns>

<Cell Site="row:0 column:0">
<ProgressBar ref.Name="progressBar" TotalSize="10">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</ProgressBar>
</Cell>

<Cell Site="row:0 column:1">
<Button ref.Name="buttonDownload" Text="Begin Download!">
<ev.Clicked-eval>
<![CDATA[
$Async{
buttonDownload.Enabled = false;
var text = $Await demo::IViewModel::DownloadAsync(ViewModel, func(progress : int):void
{
Application::GetApplication().InvokeInMainThreadAndWait(func():void
{
progressBar.Position = progress;
}, -1);
});
textResult.Text = text;
textResult.Select({row:0 column:0}, {row:0 column:0});
}
]]>
</ev.Clicked-eval>
</Button>
</Cell>

<Cell Site="row:1 column:0 columnSpan:2">
<MultilineTextBox ref.Name="textResult" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" Readonly="true">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</MultilineTextBox>
</Cell>
</Table>
</Window>
</Instance>
</Instance>
Expand Down
12 changes: 12 additions & 0 deletions Tutorial/GacUI_Controls/ProgressAndAsync/UI/Source/Demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ namespace vl
namespace description
{
#ifndef VCZH_DEBUG_NO_REFLECTION
DECL_TYPE_INFO(::demo::IStringAsync)
DECL_TYPE_INFO(::demo::IViewModel)
DECL_TYPE_INFO(::demo::MainWindow)
DECL_TYPE_INFO(::demo::MainWindowConstructor)

BEGIN_INTERFACE_PROXY_SHAREDPTR(::demo::IStringAsync, ::vl::reflection::description::IAsync)
END_INTERFACE_PROXY(::demo::IStringAsync)

BEGIN_INTERFACE_PROXY_NOPARENT_SHAREDPTR(::demo::IViewModel)
void BeginDownload(const ::vl::Func<void(::vl::vint32_t)>& progress, const ::vl::Func<void(const ::vl::WString&)>& callback) override
{
INVOKE_INTERFACE_PROXY(BeginDownload, progress, callback);
}
END_INTERFACE_PROXY(::demo::IViewModel)
#endif

extern bool LoadDemoTypes();
Expand Down
Loading

0 comments on commit dedd932

Please sign in to comment.