Added uiTab to the WPF system.

This commit is contained in:
Pietro Gagliardi 2015-11-26 12:09:12 -05:00
parent 7e6c3c0abe
commit 10ec52d8db
4 changed files with 141 additions and 1 deletions

View File

@ -85,6 +85,7 @@
<CompileAsManaged>false</CompileAsManaged>
</ClCompile>
<ClCompile Include="main.cpp" />
<ClCompile Include="tab.cpp" />
<ClCompile Include="text.cpp" />
<ClCompile Include="util.c">
<CompileAsManaged>false</CompileAsManaged>

View File

@ -21,5 +21,6 @@ void uiMain(void)
void uiQuit(void)
{
// TODO this executes immediately, not later
(*app)->Shutdown();
}

125
wpf/tab.cpp Normal file
View File

@ -0,0 +1,125 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
// TODO save child alignments?
using namespace System::Collections::Generic;
ref class tabPage {
public:
TabItem ^item;
uiControl *c;
Border ^border; // see uiTabSetMargined()
int margined;
};
struct uiTab {
uiWindowsControl c;
gcroot<TabControl ^> *tab;
gcroot<List<tabPage ^> ^> *pages;
};
static void onDestroy(uiTab *);
uiWindowsDefineControlWithOnDestroy(
uiTab, // type name
uiTabType, // type function
tab, // handle
onDestroy(hthis); // on destroy
)
static void onDestroy(uiTab *t)
{
List<tabPage ^> ^pages;
pages = *(t->pages);
while (pages->Count != 0) {
pages[0]->border->Child = nullptr;
uiControlSetParent(pages[0]->c, NULL);
uiControlDestroy(pages[0]->c);
pages->RemoveAt(0);
(*(t->tab))->Items->RemoveAt(0);
}
delete t->pages;
}
void uiTabAppend(uiTab *t, const char *name, uiControl *c)
{
uiTabInsertAt(t, name, (*(t->pages))->Count, c);
}
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t before, uiControl *c)
{
tabPage ^p;
p = gcnew tabPage();
p->c = c;
p->border = gcnew Border();
p->item = gcnew TabItem();
p->border->Child = genericHandle(p->c);
p->item->Content = p->border;
p->item->Header = fromUTF8(name);
uiControlSetParent(p->c, uiControl(t));
(*(t->tab))->Items->Insert(before, p->item);
(*(t->pages))->Insert(before, p);
uiControlSetParent(p->c, NULL);
}
void uiTabDelete(uiTab *t, uintmax_t index)
{
tabPage ^p;
List<tabPage ^> ^pages;
pages = (*(t->pages));
p = pages[index];
pages->RemoveAt(index);
(*(t->tab))->Items->RemoveAt(index);
p->border->Child = nullptr;
}
uintmax_t uiTabNumPages(uiTab *t)
{
return (*(t->pages))->Count;
}
int uiTabMargined(uiTab *t, uintmax_t page)
{
List<tabPage ^> ^pages;
pages = (*(t->pages));
return pages[page]->margined;
}
void uiTabSetMargined(uiTab *t, uintmax_t page, int margined)
{
List<tabPage ^> ^pages;
pages = (*(t->pages));
pages[page]->margined = margined;
// TabItem margins/padding do NOT work the way we want them to
// we have to use a Border here too
// TODO Padding?
if (pages[page]->margined)
pages[page]->border->Margin = Thickness(10, 10, 10, 10);
else
pages[page]->border->Margin = Thickness(0, 0, 0, 0);
}
uiTab *uiNewTab(void)
{
uiTab *t;
t = (uiTab *) uiNewControl(uiTabType());
t->tab = new gcroot<TabControl ^>();
*(t->tab) = gcnew TabControl();
t->pages = new gcroot<List<tabPage ^> ^>();
*(t->pages) = gcnew List<tabPage ^>();
uiWindowsFinishNewControl(t, uiTab, tab);
return t;
}

View File

@ -14,6 +14,9 @@ var uiWindowSetMargined = libui.NewProc("uiWindowSetMargined")
var uiNewVerticalBox = libui.NewProc("uiNewVerticalBox")
var uiBoxAppend = libui.NewProc("uiBoxAppend")
var uiBoxSetPadded = libui.NewProc("uiBoxSetPadded")
var uiNewTab = libui.NewProc("uiNewTab")
var uiTabAppend = libui.NewProc("uiTabAppend")
var uiTabSetMargined = libui.NewProc("uiTabSetMargined")
var uiControlShow = libui.NewProc("uiControlShow")
var uiMain = libui.NewProc("uiMain")
var uiQuit = libui.NewProc("uiQuit")
@ -34,6 +37,7 @@ func main() {
uintptr(unsafe.Pointer(&s[0])),
320, 240, 0)
uiWindowOnClosing.Call(w, syscall.NewCallbackCDecl(onClosing), 0)
tab, _, _ := uiNewTab.Call()
box, _, _ := uiNewVerticalBox.Call()
btn, _, _ := uiNewButton.Call(
uintptr(unsafe.Pointer(&s[0])))
@ -50,7 +54,16 @@ func main() {
btn, _, _ = uiNewButton.Call(
uintptr(unsafe.Pointer(&s[0])))
uiBoxAppend.Call(box, btn, 0)
uiWindowSetChild.Call(w, box)
uiWindowSetChild.Call(w, tab)
uiTabAppend.Call(tab,
uintptr(unsafe.Pointer(&s[0])),
box)
uiTabSetMargined.Call(tab, 0, 1)
btn, _, _ = uiNewButton.Call(
uintptr(unsafe.Pointer(&s[0])))
uiTabAppend.Call(tab,
uintptr(unsafe.Pointer(&s[0])),
btn)
uiBoxSetPadded.Call(box, 1)
uiWindowSetMargined.Call(w, 1)
uiControlShow.Call(w)