-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Skyler84:combined-demos
Add all_example combined demo
- Loading branch information
Showing
5 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "examples/all_view.hpp" | ||
|
||
#include "gui/view_controller.hpp" | ||
|
||
#include "drivers/button.hpp" | ||
#include "buttons.hpp" | ||
|
||
|
||
AllView::AllView(gui::View *parent) : | ||
View(parent), | ||
tv{this}, | ||
dv{this}, | ||
lv{this}, | ||
qv{this}{ | ||
ui.div.addWidget(&ui.header); | ||
ui.header.setText("All Examples"); | ||
ui.header.setFontSize(3); | ||
ui.div.addWidget(&ui.list); | ||
|
||
ui.list.addItem(&ui.li_text); | ||
ui.li_text.setText("Text example"); | ||
ui.li_text.setFontSize(2); | ||
ui.li_text.setUserData(&tv); | ||
|
||
ui.list.addItem(&ui.li_dividier); | ||
ui.li_dividier.setText("Divider example"); | ||
ui.li_dividier.setFontSize(2); | ||
ui.li_dividier.setUserData(&dv); | ||
|
||
ui.list.addItem(&ui.li_list); | ||
ui.li_list.setText("List example"); | ||
ui.li_list.setFontSize(2); | ||
ui.li_list.setUserData(&lv); | ||
|
||
ui.list.addItem(&ui.li_qrcode); | ||
ui.li_qrcode.setText("QR code example"); | ||
ui.li_qrcode.setFontSize(2); | ||
ui.li_qrcode.setUserData(&qv); | ||
|
||
setWidget(&ui.div); | ||
} | ||
|
||
void AllView::handleInput(InputEvent ev){ | ||
bool handled = false; | ||
MyButton *b = (MyButton*)ev.data; | ||
switch(ev.type){ | ||
case InputEvent::ButtonClick:{ | ||
switch(b->get_pin()){ | ||
case Buttons::A:{ | ||
if(ui.list.getSelectedRow() != -1); | ||
selectApplication(ui.list.getSelectedRow()); | ||
break; | ||
} | ||
case Buttons::B:{ | ||
if(ui.list.getSelectedRow() >= 0){ | ||
ui.list.setFocused(false); | ||
ui.list.setSelectedRow(-1); | ||
} | ||
else | ||
close(); | ||
break; | ||
} | ||
case Buttons::X:{ | ||
ui.list.setSelectedRow(std::max<int>(ui.list.getSelectedRow()-1, -1)); | ||
ui.list.setFocused(ui.list.getSelectedRow() != -1); | ||
break; | ||
} | ||
case Buttons::Y:{ | ||
ui.list.setSelectedRow(std::min<int>(ui.list.getSelectedRow()+1, ui.list.getNumItems()-1)); | ||
ui.list.setFocused(ui.list.getSelectedRow() != -1); | ||
break; | ||
} | ||
} | ||
handled = true; | ||
break; | ||
} | ||
} | ||
if(!handled) | ||
View::handleInput(ev); | ||
} | ||
|
||
void AllView::selectApplication(size_t idx) | ||
{ | ||
Widget *w = ui.list.getItemAt(idx); | ||
if (!w){ | ||
printf("No item\n"); | ||
return; | ||
} | ||
void *d = w->getUserData(); | ||
if (!d){ | ||
printf("No user data\n"); | ||
return; | ||
} | ||
setChildView((gui::View*)d); | ||
auto &controller = gui::ViewController::get(); | ||
controller.set_view((gui::View*)d); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "gui/view.hpp" | ||
#include "gui/widgets/divider_widget.hpp" | ||
#include "gui/widgets/text_widget.hpp" | ||
#include "gui/widgets/list_widget.hpp" | ||
|
||
#include "examples/text_view.hpp" | ||
#include "examples/divider_view.hpp" | ||
#include "examples/list_view.hpp" | ||
#include "examples/qrcode_view.hpp" | ||
|
||
class AllView : public gui::View{ | ||
public: | ||
AllView(gui::View *parent); | ||
protected: | ||
void handleInput(InputEvent ev); | ||
private: | ||
struct{ | ||
gui::VDividerWidget div; | ||
gui::TextWidget header; | ||
gui::ListWidget list; | ||
gui::TextWidget li_text, li_dividier, li_list, li_qrcode; | ||
}ui; | ||
|
||
TextView tv; | ||
DividerView dv; | ||
ListView lv; | ||
QRCodeView qv; | ||
|
||
void selectApplication(size_t idx); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters