Added uiCheckbox to the WPF test.

This commit is contained in:
Pietro Gagliardi 2015-11-26 16:34:34 -05:00
parent 77c3e83821
commit 70205d0248
3 changed files with 75 additions and 2 deletions

71
wpf/checkbox.cpp Normal file
View File

@ -0,0 +1,71 @@
// 26 november 2015
#include "uipriv_wpf.hpp"
struct uiCheckbox {
uiWindowsControl c;
gcroot<CheckBox ^> *checkbox;
void (*onToggled)(uiCheckbox *, void *);
void *onToggledData;
};
uiWindowsDefineControl(
uiCheckbox, // type name
uiCheckboxType, // type function
checkbox // handle
)
static void defaultOnToggled(uiCheckbox *c, void *data)
{
// do nothing
}
char *uiCheckboxText(uiCheckbox *c)
{
String ^text;
// TOOD bad cast?
text = (String ^) ((*(c->checkbox))->Content);
return uiWindowsCLRStringToText(text);
}
void uiCheckboxSetText(uiCheckbox *c, const char *text)
{
(*(c->checkbox))->Content = fromUTF8(text);
}
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *c, void *data), void *data)
{
c->onToggled = f;
c->onToggledData = data;
}
int uiCheckboxChecked(uiCheckbox *c)
{
return (*(c->checkbox))->IsChecked.Value != false;
}
void uiCheckboxSetChecked(uiCheckbox *c, int checked)
{
bool value;
value = checked != 0;
// TODO does this trigger an event?
(*(c->checkbox))->IsChecked = value;
}
uiCheckbox *uiNewCheckbox(const char *text)
{
uiCheckbox *c;
c = (uiCheckbox *) uiNewControl(uiCheckboxType());
c->checkbox = new gcroot<CheckBox ^>();
*(c->checkbox) = gcnew CheckBox();
(*(c->checkbox))->Content = fromUTF8(text);
uiCheckboxOnToggled(c, defaultOnToggled, NULL);
uiWindowsFinishNewControl(c, uiCheckbox, checkbox);
return c;
}

View File

@ -77,6 +77,7 @@
</ClCompile> </ClCompile>
<ClCompile Include="box.cpp" /> <ClCompile Include="box.cpp" />
<ClCompile Include="button.cpp" /> <ClCompile Include="button.cpp" />
<ClCompile Include="checkbox.cpp" />
<ClCompile Include="control.cpp" /> <ClCompile Include="control.cpp" />
<ClCompile Include="debug.c"> <ClCompile Include="debug.c">
<CompileAsManaged>false</CompileAsManaged> <CompileAsManaged>false</CompileAsManaged>

View File

@ -18,6 +18,7 @@ var uiNewTab = libui.NewProc("uiNewTab")
var uiTabAppend = libui.NewProc("uiTabAppend") var uiTabAppend = libui.NewProc("uiTabAppend")
var uiTabSetMargined = libui.NewProc("uiTabSetMargined") var uiTabSetMargined = libui.NewProc("uiTabSetMargined")
var uiNewLabel = libui.NewProc("uiNewLabel") var uiNewLabel = libui.NewProc("uiNewLabel")
var uiNewCheckbox = libui.NewProc("uiNewCheckbox")
var uiControlShow = libui.NewProc("uiControlShow") var uiControlShow = libui.NewProc("uiControlShow")
var uiMain = libui.NewProc("uiMain") var uiMain = libui.NewProc("uiMain")
var uiQuit = libui.NewProc("uiQuit") var uiQuit = libui.NewProc("uiQuit")
@ -40,7 +41,7 @@ func main() {
uiWindowOnClosing.Call(w, syscall.NewCallbackCDecl(onClosing), 0) uiWindowOnClosing.Call(w, syscall.NewCallbackCDecl(onClosing), 0)
tab, _, _ := uiNewTab.Call() tab, _, _ := uiNewTab.Call()
box, _, _ := uiNewVerticalBox.Call() box, _, _ := uiNewVerticalBox.Call()
btn, _, _ := uiNewButton.Call( btn, _, _ := uiNewCheckbox.Call(
uintptr(unsafe.Pointer(&s[0]))) uintptr(unsafe.Pointer(&s[0])))
uiBoxAppend.Call(box, btn, 0) uiBoxAppend.Call(box, btn, 0)
btn, _, _ = uiNewButton.Call( btn, _, _ = uiNewButton.Call(
@ -65,7 +66,7 @@ func main() {
uiTabAppend.Call(tab, uiTabAppend.Call(tab,
uintptr(unsafe.Pointer(&s[0])), uintptr(unsafe.Pointer(&s[0])),
btn) btn)
uiBoxSetPadded.Call(box, 1) // uiBoxSetPadded.Call(box, 1)
uiWindowSetMargined.Call(w, 1) uiWindowSetMargined.Call(w, 1)
uiControlShow.Call(w) uiControlShow.Call(w)
uiMain.Call(w) uiMain.Call(w)