Skip to content

Commit 5f8adea

Browse files
author
Gin
committed
comment while learning UI
1 parent 0554834 commit 5f8adea

File tree

9 files changed

+56
-18
lines changed

9 files changed

+56
-18
lines changed

SerialPrograms/Scripts/CodeTemplates/Program/GameName_ProgramName.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace NintendoSwitch{
1616
namespace GameName{
1717

1818

19-
2019
class ProgramName_Descriptor : public SingleSwitchProgramDescriptor{
2120
public:
2221
ProgramName_Descriptor();

SerialPrograms/Source/CommonFramework/Panels/PanelInstance.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class PanelInstance{
3131
void save_settings() const;
3232

3333
public:
34+
// The implmentation is defined in "UI/PanelWidget.h" to avoid circular dependency
35+
// Returns a UI/PanelWidget.h:PanelWidget
3436
virtual QWidget* make_widget(QWidget& parent, PanelHolder& holder);
3537

3638
public:

SerialPrograms/Source/CommonFramework/Panels/PanelTools.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ class JsonValue;
1717
class PanelInstance;
1818
class PanelDescriptor;
1919

20-
20+
// Abstract base class of a panel holder.
21+
// It is named as the owner of all the panel instances.
22+
// A panel instance, CommonFramework/Panels/PanelInstance.h:PanelInstance holds
23+
// both the program panel UI and the implementation of the actual program logic.
24+
//
25+
// Currently the main window is the only class that implements PanelHolder.
26+
// The reference of this panel holder is passed to various UI objects so that
27+
// when they do sth they can call back to the main window. e.g. when the progra
28+
// start button is pressed by user, the button code needs to lock the program
29+
// list UI. This is achieved by letting the button code calls PanelHolder::on_busy()
30+
// which is implemented by the main window
2131
struct PanelHolder{
2232
// Returns true if ready for new panel.
2333
virtual bool report_new_panel_intent(const PanelDescriptor& descriptor) = 0;
@@ -27,7 +37,9 @@ struct PanelHolder{
2737
std::unique_ptr<PanelInstance> panel
2838
) = 0;
2939
virtual Logger& raw_logger() = 0;
40+
// called when an automation program is running
3041
virtual void on_busy() = 0;
42+
// called when no automation program is not running
3143
virtual void on_idle() = 0;
3244
};
3345

@@ -52,16 +64,18 @@ struct PanelEntry{
5264
template <typename Descriptor, typename Instance>
5365
class PanelDescriptorWrapper : public Descriptor{
5466
public:
67+
// Instance must be an inherited class of PanelInstance and its constructor must be
68+
// Instance(const Descriptor&)
5569
virtual std::unique_ptr<PanelInstance> make_panel() const override{
56-
return std::unique_ptr<PanelInstance>(new Instance(*this));
70+
return std::make_unique<Instance>(*this);
5771
}
5872
};
5973

6074
// Called by a program panel list factory to create a panel descriptor.
6175
// A panel descriptor holds various info (title, title color, etc.) about a program panel
6276
// and can also create the corresponding panel.
6377
//
64-
// template type `Descriptor` a derived class of CommonFramework/Panels/PanelDescriptor.h:PanelDescriptor
78+
// template type `Descriptor` is a derived class of CommonFramework/Panels/PanelDescriptor.h:PanelDescriptor
6579
// and `Instance` is the program panel UI instance, derived class of
6680
// CommonFramework/Panels/PanelInstance.h:Panelnstance.
6781
//

SerialPrograms/Source/CommonFramework/Panels/UI/PanelWidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ namespace PokemonAutomation{
1414

1515
class CollapsibleGroupBox;
1616

17+
// A base class to define the UI widgets of a program panel.
18+
// A PanelInstance can call make_widget() to create it.
19+
// Its derived classes can call make_header() to create a collabspile program header
20+
// that shows program title, link to online documentation and others.
1721
class PanelWidget : public QWidget{
1822
public:
1923
PanelWidget(
@@ -23,6 +27,7 @@ class PanelWidget : public QWidget{
2327
);
2428
virtual ~PanelWidget() = default;
2529

30+
// return the panel instance
2631
PanelInstance& instance(){ return m_instance; }
2732

2833
protected:

SerialPrograms/Source/CommonFramework/Windows/MainWindow.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,22 @@ class MainWindow :
4040

4141
void close_panel() noexcept;
4242

43+
// implements PanelHolder::report_new_panel_intent()
4344
virtual bool report_new_panel_intent(const PanelDescriptor& descriptor) override;
45+
// implements PanelHolder::load_panel()
4446
virtual void load_panel(
4547
std::shared_ptr<const PanelDescriptor> descriptor,
4648
std::unique_ptr<PanelInstance> panel
4749
) override;
50+
// implements PanelHolder::raw_logger()
4851
virtual Logger& raw_logger() override{ return global_logger_raw(); }
4952

5053
private:
54+
// implements PanelHolder::on_busy()
55+
// called when an automation program is running
5156
virtual void on_busy() override;
57+
// implements PanelHolder::on_idle()
58+
// called when no automation program is not running
5259
virtual void on_idle() override;
5360
virtual void on_config_value_changed(void* object) override;
5461
virtual void sleep_suppress_state_changed(SleepSuppress new_state) override;

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Color pick_color(
3434
);
3535

3636

37+
// options to control and monitor a Switch. It inlcudes
38+
// what micro-controller and what video source to use and
39+
// what video overlay display option to set.
3740
class SwitchSystemOption{
3841
static const std::string JSON_CONTROLLER;
3942
static const std::string JSON_CAMERA;

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SingleSwitchProgramDescriptor::SingleSwitchProgramDescriptor(
4040
, m_allow_commands_while_running(allow_commands_while_running == AllowCommandsWhenRunning::ENABLE_COMMANDS)
4141
{}
4242
std::unique_ptr<PanelInstance> SingleSwitchProgramDescriptor::make_panel() const{
43-
return std::unique_ptr<PanelInstance>(new SingleSwitchProgramOption(*this));
43+
return std::make_unique<SingleSwitchProgramOption>(*this);
4444
}
4545

4646

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_VirtualConsole.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ VirtualConsole_Descriptor::VirtualConsole_Descriptor()
2828

2929
VirtualConsole::VirtualConsole(const VirtualConsole_Descriptor& descriptor)
3030
: PanelInstance(descriptor)
31-
, m_switch({}, false)
31+
, m_switch_control_option({}, false)
3232
{}
3333
void VirtualConsole::from_json(const JsonValue& json){
34-
m_switch.load_json(json);
34+
m_switch_control_option.load_json(json);
3535
}
3636
JsonValue VirtualConsole::to_json() const{
37-
return m_switch.to_json();
37+
return m_switch_control_option.to_json();
3838
}
3939
QWidget* VirtualConsole::make_widget(QWidget& parent, PanelHolder& holder){
4040
return VirtualConsole_Widget::make(parent, *this, holder);
@@ -52,15 +52,15 @@ VirtualConsole_Widget* VirtualConsole_Widget::make(
5252
return widget;
5353
}
5454
VirtualConsole_Widget::~VirtualConsole_Widget(){
55-
delete m_switch;
55+
delete m_switch_widget;
5656
}
5757
VirtualConsole_Widget::VirtualConsole_Widget(
5858
QWidget& parent,
5959
VirtualConsole& instance,
6060
PanelHolder& holder
6161
)
6262
: PanelWidget(parent, instance, holder)
63-
, m_session(instance.m_switch, 0, 0)
63+
, m_session(instance.m_switch_control_option, 0, 0)
6464
{}
6565
void VirtualConsole_Widget::construct(){
6666
QVBoxLayout* layout = new QVBoxLayout(this);
@@ -76,8 +76,8 @@ void VirtualConsole_Widget::construct(){
7676
QVBoxLayout* scroll_layout = new QVBoxLayout(scroll_inner);
7777
scroll_layout->setAlignment(Qt::AlignTop);
7878

79-
m_switch = new SwitchSystemWidget(*this, m_session, 0);
80-
scroll_layout->addWidget(m_switch);
79+
m_switch_widget = new SwitchSystemWidget(*this, m_session, 0);
80+
scroll_layout->addWidget(m_switch_widget);
8181
}
8282

8383

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_VirtualConsole.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ namespace NintendoSwitch{
1818
class SwitchSystemWidget;
1919

2020

21-
21+
// Descriptor for the program "Virtual Console".
22+
// It defines basic info such as title name and color of the program on the program list panel.
23+
// It inherits abstract base class PanelDescriptor but is still an abstract class as it does
24+
// not define `make_panel()`, which functionality is simply to instantiate the PanelInstance, the
25+
// program panel.
26+
// Call CommonFramework/Panels/PanelTools.h:make_panel<VirtualConsole_Descriptor, VirtualConsole>()
27+
// to create a wrapper class that implements `make_panel()` to instantiate the descriptor.
2228
class VirtualConsole_Descriptor : public PanelDescriptor{
2329
public:
2430
VirtualConsole_Descriptor();
2531
};
2632

2733

28-
34+
// The program panel of Virtual Console.
35+
// It calls make_widget() to create a VirtualConsole_Widget that holds the UI wideget.
2936
class VirtualConsole : public PanelInstance{
3037
public:
3138
VirtualConsole(const VirtualConsole_Descriptor& descriptor);
@@ -38,12 +45,13 @@ class VirtualConsole : public PanelInstance{
3845

3946
private:
4047
friend class VirtualConsole_Widget;
41-
42-
SwitchSystemOption m_switch;
48+
// switch control options like what micro-controller
49+
// and what video source to use
50+
SwitchSystemOption m_switch_control_option;
4351
};
4452

4553

46-
54+
// The UI of the prgoram Virtual Console
4755
class VirtualConsole_Widget : public PanelWidget{
4856
public:
4957
static VirtualConsole_Widget* make(
@@ -63,7 +71,7 @@ class VirtualConsole_Widget : public PanelWidget{
6371

6472
private:
6573
SwitchSystemSession m_session;
66-
SwitchSystemWidget* m_switch;
74+
SwitchSystemWidget* m_switch_widget;
6775
};
6876

6977

0 commit comments

Comments
 (0)