Button test

This commit is contained in:
2023-08-10 22:40:02 -07:00
parent 8c9fa5fd8c
commit 66fca2323e
9 changed files with 71 additions and 6 deletions

View File

@ -1,5 +1,20 @@
<prefab name="Button" type="">
<asset type="truetype" name="font_main" />
<UISimpleLabel ref="label" font="font_main" size="32" />
<UISimpleLabel ref="uiItem" font="font_main" size="32" />
<UISimpleMenuItem ref="menuItem" />
<code type="init">
useEvent([&amp;]{
uiItem->color = COLOR_RED;
}, menuItem->eventHoveredOn);
useEvent([&amp;]{
uiItem->color = COLOR_BLUE;
}, menuItem->eventHoveredOff);
useEvent([&amp;]{
uiItem->color = COLOR_GREEN;
}, menuItem->eventSelected);
</code>
</prefab>

View File

@ -24,5 +24,13 @@
/>
</child>
<UIMenuController />
<UISimpleMenu />
<item prefab="Button" ref="button0" alignment="0, 0, 0, 0" menuX="0" menuY="0" />
<item prefab="Button" ref="button1" alignment="180, 0, 0, 0" menuX="1" menuY="0" />
<item prefab="Button" ref="button2" alignment="0, 64, 0, 0" menuX="0" menuY="1" />
<item prefab="Button" ref="button3" alignment="180, 64, 0, 0" menuX="1" menuY="1" />
<VNTextboxScroller ref="textboxScroller" label="uiLabel" visibleLines="6" />
</prefab>

View File

@ -16,7 +16,7 @@ namespace Dawn {
*
* @param val Value that is to be used for this property.
*/
void setInternal(V val) {
void setInternal(const V val) {
if(val == this->_realValue) return;// TODO: can I omit this? kinda bad tbh.
// Run the teardowns

View File

@ -22,9 +22,16 @@ namespace Dawn {
*/
static struct Color fromString(std::string str);
float_t r, g, b, a;
const struct Color& operator = (const struct Color &val) {
this->r = val.r;
this->g = val.g;
this->b = val.b;
this->a = val.a;
return *this;
}
struct Color operator * (const float_t &x) {
return {
r * x,
@ -52,6 +59,10 @@ namespace Dawn {
};
}
const bool_t operator == (const struct Color &other) {
return r == other.r && g == other.g && b == other.b && a == other.a;
}
operator struct ColorU8() const {
return {
(uint8_t)(r * 255),

View File

@ -23,7 +23,6 @@ include(util/generator/CMakeLists.txt)
# Tools
add_subdirectory(prefabtool)
add_subdirectory(propertytool)
add_subdirectory(scenetool)
add_subdirectory(texturetool)
add_subdirectory(truetypetool)

View File

@ -135,6 +135,18 @@ void SceneItemGenerator::generate(
line(initBody, name + "->transform.setLocalPosition(" + item->position + ");", "");
}
if(item->alignment.size() > 0) {
line(initBody, name + "->uiItem->alignment = " + item->alignment + ";", "");
}
if(item->menuX.size() > 0) {
line(initBody, name + "->menuItem->menuX = " + item->menuX + ";", "");
}
if(item->menuY.size() > 0) {
line(initBody, name + "->menuItem->menuY = " + item->menuY + ";", "");
}
if(item->scale.size() > 0) {
line(initBody, name + "->transform.setLocalScale(" + item->scale + ");", "");
}

View File

@ -14,7 +14,6 @@ set(
${D}/SceneCodeParser.cpp
${D}/SceneItemComponentParser.cpp
${D}/SceneItemComponentRegistry.cpp
${D}/ScenePropertyParser.cpp
CACHE INTERNAL
${DAWN_CACHE_TARGET}

View File

@ -17,7 +17,10 @@ std::map<std::string, std::string> SceneItemParser::getOptionalAttributes() {
{ "position", "" },
{ "lookAt", "" },
{ "scale", "" },
{ "prefab", "" }
{ "prefab", "" },
{ "alignment", "" },
{ "menuX", "" },
{ "menuY", "" }
};
}
@ -34,6 +37,21 @@ int32_t SceneItemParser::onParse(
if(error->size() > 0) return 1;
}
if(values["alignment"].size() > 0) {
out->alignment = vec4Parser(values["alignment"], error);
if(error->size() > 0) return 1;
}
if(values["menuX"].size() > 0) {
out->menuX = intParser(values["menuX"], error);
if(error->size() > 0) return 1;
}
if(values["menuY"].size() > 0) {
out->menuY = intParser(values["menuY"], error);
if(error->size() > 0) return 1;
}
if(values["scale"].size() > 0) {
out->scale = vec3Parser(values["scale"], error);
if(error->size() > 0) return 1;

View File

@ -24,10 +24,13 @@ namespace Dawn {
struct SceneItemComponentRegistry *registry;
std::string ref;
std::string position;
std::string alignment;
std::string lookAtPosition;
std::string lookAtTarget;
std::string scale;
std::string prefab;
std::string menuX;
std::string menuY;
std::vector<struct SceneItemComponent> components;
std::vector<struct SceneItem> children;
std::vector<struct SceneAsset> assets;