Day 12/100 100 Days of Code

Info Hunter

Today, I worked on the application's graphical interface. I added a static text and 2 buttons to the run panel of the application. This way, the user can start or end the operation at will.


 content->SetFont(wxFontInfo(35).FaceName("Helvetica Neue").Bold());
    wxSize getPanelSize = content->GetSize();

    runContentHolder = new wxBoxSizer(wxVERTICAL);
    runInstructionsholder = new wxBoxSizer(wxVERTICAL);
    buttonsHolder = new wxBoxSizer(wxHORIZONTAL);
    startButtonHolder = new wxBoxSizer(wxVERTICAL);
    stopButtonHolder = new wxBoxSizer(wxVERTICAL);

    std::string instructionsText = std::string("Press start the scraping operation.\n") +
                                    std::string("Press stop to cancel the scraping operation.");

    runInstructions = new wxStaticText(content, eID_Instructions, instructionsText,
                                       wxDefaultPosition, wxDefaultSize, 0);
    runInstructionsholder->Add(runInstructions, 1, wxCENTER);

    content->SetFont(wxFontInfo(wxDefaultSize).FaceName("Helvetica Neue").Bold());

    startButton = new wxButton(content, eID_StartButton, "Start", wxDefaultPosition, wxDefaultSize,
                                     0, wxDefaultValidator);
    startButtonHolder->Add(startButton, 1, wxEXPAND|wxCENTER|wxALL,
                           getPanelSize.GetWidth() * 0.012);
    stopButton = new wxButton(content, eID_StartButton, "Stop", wxDefaultPosition, wxDefaultSize,
                               0, wxDefaultValidator);
    stopButtonHolder->Add(stopButton, 1, wxEXPAND|wxCENTER|wxALL,
                          getPanelSize.GetWidth() * 0.012);

    buttonsHolder->Add(startButtonHolder, 1, wxALIGN_TOP|wxTOP,
                       getPanelSize.GetHeight() * 0.05);
    buttonsHolder->Add(stopButtonHolder, 1, wxALIGN_TOP|wxTOP,
                       getPanelSize.GetHeight() * 0.05);

    runContentHolder->Add(runInstructionsholder, 0, wxEXPAND|wxTOP,
                          getPanelSize.GetHeight() * 0.065);
    runContentHolder->Add(buttonsHolder, 1, wxCENTER);


    currentState = ST_Run;

That's a lot of stuff! Creating a layout with the sizers can be quite confusing at first, but they are very useful and not that bad once you learn how to use them. There is also wxFormBuilder which is an extremely useful tool to the GUI.

There are sizers for each element because it lets them be responsive to the size of the panel. Their options, wxEXPAND or wxCenter make their positioning quite simple.

The buttonsHolder sizer exists because both buttons need to be next to each other and it lets me insert them into the panel layout as one non-separatable element.

This is the result:

Going back to the beginning of the development, many things have changed. Many features have been removed as they were going to make the application development very long. I might add those removed features later.