control_datagrid_plaintext

This commit is contained in:
Zihan Chen
2021-06-24 10:17:36 -07:00
parent 5133fd8e16
commit a4002da85c
12 changed files with 234 additions and 10 deletions

View File

@@ -24,4 +24,6 @@ http://vczh-libraries.github.io/doc/current/gacui/home.html
- Open GacUI.sln
- Build the solution
- Run project `RunResource`
- If you want to load `XmlRes\kb_elements\Resource.xml`, set the command line arguments to `kb_elements`
- If you want to load `XmlRes\kb_elements\Resource.xml`, set the command line arguments to `kb_elements`.
- Multiple resource names are separated by `;`, not by multiple arguments. Resources will be loaded in the specified order.
- For example: `control_datagrid_base;control_datagrid_plaintext`.

View File

@@ -3,6 +3,7 @@
#include "resource.h"
using namespace vl;
using namespace vl::regex;
using namespace vl::filesystem;
using namespace vl::reflection::description;
using namespace vl::presentation;
@@ -27,22 +28,30 @@ void GuiMain()
{
{
// expected to executed like "RunResource.exe kb-elements"
WString resourceName;
WString resourceNameList;
{
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(GetCommandLine(), &argc);
CHECK_ERROR(argc == 2, L"Command line arguments are missing."); \
resourceName = argv[1];
resourceNameList = argv[1];
LocalFree(argv);
}
#ifdef VCZH_64
FilePath resourcePath = FilePath(L"../UIRes/64bits") / (resourceName + L".bin");
#else
FilePath resourcePath = FilePath(L"../UIRes/32bits") / (resourceName + L".bin");
#endif
stream::FileStream resourceStream(resourcePath.GetFullPath(), stream::FileStream::ReadOnly);
GetResourceManager()->LoadResourceOrPending(resourceStream, GuiResourceUsage::InstanceClass);
Regex splitter(L";");
RegexMatch::List names;
splitter.Split(resourceNameList, false, names);
FOREACH(RegexMatch::Ref, name, names)
{
auto resourceName = name->Result().Value();
#ifdef VCZH_64
FilePath resourcePath = FilePath(L"../UIRes/64bits") / (resourceName + L".bin");
#else
FilePath resourcePath = FilePath(L"../UIRes/32bits") / (resourceName + L".bin");
#endif
stream::FileStream resourceStream(resourcePath.GetFullPath(), stream::FileStream::ReadOnly);
GetResourceManager()->LoadResourceOrPending(resourceStream, GuiResourceUsage::InstanceClass);
}
}
auto window = UnboxValue<GuiWindow*>(Value::Create(L"sample::MainWindow"));

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -0,0 +1,187 @@
<?xml version="1.0" encoding="utf-8"?>
<Resource>
<Folder name="GacGenConfig">
<Xml name="Metadata">
<ResourceMetadata Name="DataGridBase" Version="1.0"/>
</Xml>
<Folder name="ResX86">
<Text name="Resource">..\..\UIRes\32bits\control_datagrid_base.bin</Text>
</Folder>
<Folder name="ResX64">
<Text name="Resource">..\..\UIRes\64bits\control_datagrid_base.bin</Text>
</Folder>
</Folder>
<Image content="File">Book16.png</Image>
<Image content="File">Book32.png</Image>
<Image content="File">Open16.png</Image>
<Image content="File">Open32.png</Image>
<Folder name="MainWindow">
<Script name="ViewModel">
<Workflow><![CDATA[
module viewmodel;
using system::*;
using presentation::*;
namespace sample
{
class BookItem
{
prop Title : string = Sys::LoremIpsumTitle(24) {not observe}
prop Author : string = Sys::LoremIpsumTitle(16) {not observe}
prop DatePublished : DateTime = {} {not observe}
prop Summary : string = Sys::LoremIpsumTitle(64) {not observe}
prop Content : string = Sys::LoremIpsumTitle(512) {not observe}
prop SmallImage : GuiImageData^ = null {not observe}
prop LargeImage : GuiImageData^ = null {not observe}
}
}
]]></Workflow>
</Script>
<Instance name="MainWindowResource">
<Instance ref.Class="sample::DataGridWindowBase">
<ref.Members><![CDATA[
@cpp:Private
var books: observe BookItem^[] = {};
@cpp:Private
var lastSelectedItem: int = -1;
@cpp:Private
var iconBook16: ImageData^ = null;
@cpp:Private
var iconBook32: ImageData^ = null;
@cpp:Private
var iconOpen16: ImageData^ = null;
@cpp:Private
var iconOpen32: ImageData^ = null;
func FormatDate(date: DateTime): string
{
var locale = Application::GetApplication().Locale;
var formats = Localization::GetLongDateFormats(locale).CreateEnumerator();
formats.Next();
var format = cast string formats.Current;
return Localization::FormatDate(locale, format, date);
}
]]></ref.Members>
<ref.Ctor><![CDATA[
{
self.iconBook16 = cast (ImageData^) self.ResolveResource("res", "Book16.png", true);
self.iconBook32 = cast (ImageData^) self.ResolveResource("res", "Book32.png", true);
self.iconOpen16 = cast (ImageData^) self.ResolveResource("res", "Open16.png", true);
self.iconOpen32 = cast (ImageData^) self.ResolveResource("res", "Open32.png", true);
for (i in range [0, 24))
{
var book = new BookItem^();
book.DatePublished = Sys::CreateDateTime(2010 + i / 3, 1 + i / 2, 1 + i);
book.SmallImage = self.iconBook16;
book.LargeImage = self.iconBook32;
self.books.Add(book);
}
}
]]></ref.Ctor>
<Window ref.Name="self" ClientSize="x:800 y:600">
<Table AlignmentToParent="left:0 top:0 right:0 bottom:0" CellPadding="5" BorderVisible="false" MinSizeLimitation="LimitToElementAndChildren">
<att.Rows>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
</att.Rows>
<att.Columns>
<CellOption>composeType:Absolute absolute:540</CellOption>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
</att.Columns>
<ColumnSplitter ColumnsToTheLeft ="1"/>
<Cell Site="row:0 column:0 rowSpan:5">
<BindableDataGrid ref.Name="datagrid" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" env.ItemType="sample::BookItem^" env.ItemName="item">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
<att.ItemSource-eval>self.books</att.ItemSource-eval>
<att.LargeImageProperty>SmallImage</att.LargeImageProperty>
<att.SmallImageProperty>LargeImage</att.SmallImageProperty>
<att.Columns>
<DataColumn ref.Name="columnTitle" Text="Title" TextProperty="Title"/>
<DataColumn ref.Name="columnAuthor" Text="Author" TextProperty="Author"/>
<DataColumn ref.Name="columnDatePublished" Text="Date Published" TextProperty="self.FormatDate(item.DatePublished)"/>
<DataColumn ref.Name="columnSummary" Text="Summary" TextProperty="Summary"/>
</att.Columns>
<att.DataColumns>
<_>0</_>
<_>1</_>
</att.DataColumns>
<ev.SelectionChanged-eval><![CDATA[
{
var last = self.lastSelectedItem;
var current = datagrid.SelectedItemIndex;
self.lastSelectedItem = current;
Application::GetApplication().InvokeInMainThread(self, func():void
{
if (last != -1)
{
self.books[last].SmallImage = self.iconBook16;
self.books[last].LargeImage = self.iconBook32;
self.books.ItemChanged(last, 1, 1);
}
if (current != -1)
{
self.books[current].SmallImage = self.iconOpen16;
self.books[current].LargeImage = self.iconOpen32;
self.books.ItemChanged(current, 1, 1);
}
});
}
]]></ev.SelectionChanged-eval>
</BindableDataGrid>
</Cell>
<Cell Site="row:0 column:1">
<Label Text-eval="columnTitle.Text"/>
</Cell>
<Cell Site="row:1 column:1">
<Label Text-eval="columnAuthor.Text"/>
</Cell>
<Cell Site="row:2 column:1">
<Label Text-eval="columnDatePublished.Text"/>
</Cell>
<Cell Site="row:3 column:1">
<Label Text-eval="columnSummary.Text"/>
</Cell>
<Cell Site="row:0 column:2">
<DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Title ?? ''">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</DocumentTextBox>
</Cell>
<Cell Site="row:1 column:2">
<DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Author ?? ''">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</DocumentTextBox>
</Cell>
<Cell Site="row:2 column:2">
<DocumentTextBox EditMode="Selectable" Text-bind="self.FormatDate((cast (BookItem^) datagrid.SelectedRowValue).DatePublished) ?? ''">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</DocumentTextBox>
</Cell>
<Cell Site="row:3 column:2">
<DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Summary ?? ''">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</DocumentTextBox>
</Cell>
<Cell Site="row:4 column:1 columnSpan:2">
<DocumentViewer EditMode="Selectable" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Content ?? ''">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
</DocumentViewer>
</Cell>
</Table>
</Window>
</Instance>
</Instance>
</Folder>
</Resource>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Resource>
<Folder name="GacGenConfig">
<Xml name="Metadata">
<ResourceMetadata Name="DataGridPlainText" Version="1.0">
<Dependencies>
<Resource Name="DataGridBase"/>
</Dependencies>
</ResourceMetadata>
</Xml>
<Folder name="ResX86">
<Text name="Resource">..\..\UIRes\32bits\control_datagrid_plaintext.bin</Text>
</Folder>
<Folder name="ResX64">
<Text name="Resource">..\..\UIRes\64bits\control_datagrid_plaintext.bin</Text>
</Folder>
</Folder>
<Folder name="MainWindow">
<Instance name="MainWindowResource">
<Instance ref.Class="sample::MainWindow" xmlns:sample="sample::*">
<sample:DataGridWindowBase ref.Name="self" Text="control_datagrid_plaintext">
</sample:DataGridWindowBase>
</Instance>
</Instance>
</Folder>
</Resource>