Skip to content

Manipulating the Form

Alec Musasa edited this page Jul 12, 2021 · 15 revisions

According to the embedded XML documentation, the best place to manipulate the form is in an override of the on_initialize() method.

bool on_initialize(std::string& error) override {
    // manipulate form here
    return true;
}

Form Size

#include <liblec/lecui/controls.h>

To manipulate the form's size we need to use the dimensions class. It's found in the controls.h header.

lecui::dimensions dim_(*this);
dim_.set_size({ 500, 300 });
dim_.set_minimum({ 200, 200 });

This makes a form with a size of 500x300 pixels. When the form is resized, the minimum allowed size if 200x200 pixels. If we do not specify this minimum size the library sets a default for us. It is recommended that you set this explicitly for maximum control over your design.

It is generally a good idea to declare an in-class variable for this manipulation as shown in the code below.

#include <liblec/lecui/controls.h>
#include <liblec/lecui/containers/page.h>
#include <liblec/lecui/widgets/label.h>
using namespace liblec;

class sample_form : public lecui::form {
    lecui::page_manager page_man_{ *this };
    lecui::dimensions dim_{ *this };

    bool on_initialize(std::string& error) override {
        dim_.set_size({ 500, 300 });
        dim_.set_minimum({ 200, 200 });
        return true;
    }

    bool on_layout(std::string& error) override {
        auto& home = page_man_.add("home");

        lecui::widgets::label_builder label(home);
        label()
            .text("This is a simple label")
            .rect({ 10.f, home.size().width - 10.f, 10.f, 30.f });

        page_man_.show("home");
        return true;
    }

public:
    sample_form() :
        form("Sample Form") {}
};

int main() {
    sample_form form_;
    std::string error;
    if (!form_.show(error))
        form_.message(error);
    return 0;
}

The result:

screenshot

Control Buttons

#include <liblec/lecui/controls.h>

To manipulate the form's control buttons we need to use the controls class. It's found in the controls.h header.

lecui::controls ctrls_{ *this };
ctrls_.allow_minimize(false);
ctrls_.allow_resize(false);

The .allow_minimize(false); line makes a form without a minimize button on the top right. The .allow_resize(false) makes a form that cannot be resized (and so does not have a maximize button on the top right).