-
-
Notifications
You must be signed in to change notification settings - Fork 5
Manipulating the Form
According to the embedded XML documentation, the best place to manipulate the form is in the form's initialize event.
events().initialize = [this](std::string& error) {
// manipulate form here
return true;
};
#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(lecui::size().width(500.f).height(300.f))
.set_minimum(lecui::size().width(200.f).height(200.f));
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 the manipulation classes 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::lecui;
class sample_form : public form {
page_manager _page_man{ *this };
dimensions _dim{ *this };
public:
sample_form() :
form("Sample Form") {
events().initialize = [this](std::string& error) {
_dim
.set_size(size().width(500.f).height(300.f))
.set_minimum(size().width(200.f).height(200.f));
return true;
};
events().layout = [this](std::string& error) {
auto& home = _page_man.add("home");
auto& label = widgets::label::add(home);
label
.text("This is a simple label")
.rect()
.left(10.f)
.right(home.size().get_width() - 10.f)
.top(10.f)
.bottom(30.f);
_page_man.show("home");
return true;
};
}
};
int main() {
sample_form form;
std::string error;
if (!form.create(error))
form.message(error);
return 0;
}
The result:
#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)
.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).
#include <liblec/lecui/appearance.h>
To manipulate the form's appearance we use the appearance class in the appearance.h header.
lecui::appearance _apprnc{ *this };
_apprnc
.theme(lecui::themes::dark)
.shadow(false);
In this code we set the form to the built-in dark theme (the default is light theme). We also remove the form's drop-shadow.
#include <liblec/lecui/controls.h>
#include <liblec/lecui/containers/page.h>
#include <liblec/lecui/widgets/label.h>
#include <liblec/lecui/appearance.h>
using namespace liblec::lecui;
class sample_form : public form {
page_manager _page_man{ *this };
dimensions _dim{ *this };
controls _ctrls{ *this };
appearance _apprnc{ *this };
public:
sample_form() :
form("Sample Form") {
events().initialize = [this](std::string& error) {
_dim
.set_size(size().width(500.f).height(300.f))
.set_minimum(size().width(200.f).height(200.f));
_ctrls
.allow_minimize(false)
.allow_resize(false);
_apprnc
.theme(themes::dark)
.shadow(false);
return true;
};
events().layout = [this](std::string& error) {
auto& home = _page_man.add("home");
auto& label = widgets::label::add(home);
label
.text("This is a simple label")
.rect()
.left(10.f)
.right(home.size().get_width() - 10.f)
.top(10.f)
.bottom(30.f);
_page_man.show("home");
return true;
};
}
};
int main() {
sample_form form;
std::string error;
if (!form.create(error))
form.message(error);
return 0;
}
The result:
To see all the form properties that can be manipulated refer to the lecui html documentation or the in-code XML documentation.
lecui - rapidly develop modern, efficient and easy to maintain C++ GUI applications for Windows