Skip to content

Commit

Permalink
Cleaned up example & bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Mar 29, 2020
1 parent e7228c2 commit 1ba52ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 43 deletions.
4 changes: 3 additions & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ include $(DEVKITPRO)/libnx/switch_rules
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
APP_TITLE := Tesla Example

APP_TITLE := Tesla Example
VERSION_VERSION := 1.3.0

TARGET := $(notdir $(CURDIR))
BUILD := build
Expand Down
67 changes: 25 additions & 42 deletions example/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,40 @@ class GuiTest : public tsl::Gui {
GuiTest(u8 arg1, u8 arg2, bool arg3) { }

// Called when this Gui gets loaded to create the UI
// Allocate all your elements on the heap. libtesla will make sure to clean them up when not needed anymore
// Allocate all elements on the heap. libtesla will make sure to clean them up when not needed anymore
virtual tsl::elm::Element* createUI() override {
auto frame = new tsl::elm::OverlayFrame("Tesla Example", "v1.2.0");
auto list = new tsl::elm::List();
/*auto header = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer* r, u16 x, u16 y, u16 w, u16 h) {
r->drawString(std::to_string(value).c_str(), false, x + 20, y + 150, 20, 0xFFFF);
});*/

static bool set = false;
auto swapItem = new tsl::elm::ListItem("Test List Item 1");

auto callback = [this, list](u64 keys) {
if (keys & KEY_A) {
set = !set;

Gui::removeFocus();

list->clear();
list->addItem(new tsl::elm::CategoryHeader("Begin"));
list->addItem(new tsl::elm::TrackBar("\uE13C"), true);
list->addItem(new tsl::elm::ListItem("Test List Item 1"));
list->addItem(new tsl::elm::ListItem("Test List Item 2"));
list->addItem(new tsl::elm::CategoryHeader("List Items"));
list->addItem(new tsl::elm::ListItem("Test List Item 3"));

// A OverlayFrame is the base element every overlay consists of. This will draw the default Title and Subtitle.
// If you need more information in the header or want to change it's look, use a HeaderOverlayFrame.
auto frame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.0");

return true;
}

return false;
};

swapItem->setClickListener(callback);
// A list that can contain sub elements and handles scrolling
auto list = new tsl::elm::List();

// List Items
list->addItem(new tsl::elm::CategoryHeader("List items"));
list->addItem(new tsl::elm::ListItem("Default List Item"));
list->addItem(new tsl::elm::ToggleListItem("Toggle List Item", true));

// Custom Drawer, a element that gives direct access to the renderer
list->addItem(new tsl::elm::CategoryHeader("Custom Drawer", true));
list->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawCircle(x + 40, y + 40, 20, true, renderer->a(0xF00F));
renderer->drawCircle(x + 50, y + 50, 20, true, renderer->a(0xF0F0));
renderer->drawRect(x + 130, y + 30, 60, 40, renderer->a(0xFF00));
renderer->drawString("Hello :)", false, x + 250, y + 70, 20, renderer->a(0xFF0F));
renderer->drawRect(x + 40, y + 90, 300, 10, renderer->a(0xF0FF));
}), 100);

// Track bars
list->addItem(new tsl::elm::CategoryHeader("Track bars"));
list->addItem(new tsl::elm::TrackBar("\u2600"));
list->addItem(new tsl::elm::StepTrackBar("\uE13C", 20));
list->addItem(new tsl::elm::ListItem("Test List Item 1"));
list->addItem(swapItem);
list->addItem(new tsl::elm::CategoryHeader("List Items"));
list->addItem(new tsl::elm::ListItem("Test List Item 3"));
list->addItem(new tsl::elm::ListItem("Test List Item 4"));
list->addItem(new tsl::elm::ListItem("Test List Item 5"));
list->addItem(new tsl::elm::ListItem("Test List Item 6"));
list->addItem(new tsl::elm::ListItem("Test List Item 7"));
list->addItem(new tsl::elm::ListItem("Test List Item 8"));
list->addItem(new tsl::elm::ToggleListItem("Test Toggle List Item", true));
list->addItem(new tsl::elm::NamedStepTrackBar("\uE132", { "Selection 1", "Selection 2", "Selection 3" }));

// Add the list to the frame for it to be drawn
frame->setContent(list);


// Return the frame to have it become the top level element of this Gui
return frame;
}

Expand Down

0 comments on commit 1ba52ab

Please sign in to comment.