Skip to content

Commit

Permalink
Feature/cla 136 control_factory and layer_factory added (#102)
Browse files Browse the repository at this point in the history
* cla-133: created control_factory

* cla-133: created layer_factory

* cla-133: fixed rebase conflicts
  • Loading branch information
ebasconp authored Jan 8, 2025
1 parent 68d3331 commit 20ba987
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 93 deletions.
5 changes: 3 additions & 2 deletions code/classeine-demo/demo_action_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "demo_main_pane.h"

#include <clsn/ui/button.h>
#include <clsn/ui/control_factory.h>
#include <clsn/ui/layer.h>
#include <clsn/ui/dynamic_content_pane.h>
#include <clsn/ui/vbox_layout_container.h>
Expand Down Expand Up @@ -35,7 +36,7 @@ namespace clsn::demo
template <typename T>
void init_action(std::string_view action_name)
{
auto btn = add(control::make<ui::button>(get_layer()));
auto btn = add(control_factory::make<ui::button>(get_layer()));
btn->set_caption(std::string{action_name});
btn->set_action_name(std::string{action_name});
btn->add_action_listener([this](auto& e)
Expand All @@ -45,7 +46,7 @@ namespace clsn::demo
{std::string{action_name}, [this]
{
m_demo_main_pane.get_content_pane().set_inner_control(
control::make<T>(this->get_layer()));
control_factory::make<T>(this->get_layer()));
}});
}

Expand Down
8 changes: 4 additions & 4 deletions code/classeine-demo/demo_box_layout_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <clsn/ui/button.h>
#include <clsn/ui/empty_control.h>
#include <clsn/ui/label.h>
#include <clsn/ui/ui_theme_manager.h>
#include <clsn/ui/ui_manager.h>

#include <clsn/ui/renderers/customizable_renderer.h>

Expand All @@ -30,7 +30,7 @@ namespace clsn::demo
explicit demo_box_layout_container(ui::layer_base& _layer)
: base{_layer}
{
m_button = this->add(ui::control::make<ui::button>(_layer));
m_button = this->add(ui::control_factory::make<ui::button>(_layer));
m_button->set_caption("Click me to toggle UI theme");
m_button->set_background_color(draw::colors::make_red());
m_button->set_foreground_color(draw::colors::make_white());
Expand All @@ -47,7 +47,7 @@ namespace clsn::demo
CLSN_ASSERT(r, "Theme does not exist");
});

m_control = this->add(ui::control::make<ui::empty_control>(_layer));
m_control = this->add(ui::control_factory::make<ui::empty_control>(_layer));
m_control->set_renderer(
std::make_unique<ui::renderers::customizable_renderer>(
[](auto& gfx, auto& ctrl)
Expand All @@ -56,7 +56,7 @@ namespace clsn::demo
ctrl.get_actual_bounds());
}));

m_label = this->add(ui::control::make<ui::label>(_layer));
m_label = this->add(ui::control_factory::make<ui::label>(_layer));
m_label->set_caption("This is a label");
m_label->set_background_color(draw::colors::make_blue());
m_label->set_foreground_color(draw::colors::make_white());
Expand Down
78 changes: 49 additions & 29 deletions code/classeine-demo/demo_control_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <clsn/ui/button.h>
#include <clsn/ui/check_box.h>
#include <clsn/ui/control_factory.h>
#include <clsn/ui/empty_control.h>
#include <clsn/ui/hbox_layout_container.h>
#include <clsn/ui/label.h>
Expand All @@ -26,39 +27,45 @@ namespace clsn::demo
{
auto& _layer = get_layer();

m_buttons = this->add(make<ui::hbox_layout_container>(_layer));
m_buttons = this->add(
ui::control_factory::make<ui::hbox_layout_container>(_layer));

auto b1 = m_buttons->add(make<ui::button>(_layer));
auto b1 = m_buttons->add(ui::control_factory::make<ui::button>(_layer));
b1->set_caption("Button");

auto b2 = m_buttons->add(make<ui::button>(_layer));
auto b2 = m_buttons->add(ui::control_factory::make<ui::button>(_layer));
b2->set_caption("Disabled");
b2->set_enabled(false);

auto b3 = m_buttons->add(make<ui::toggle_button>(_layer));
auto b3 = m_buttons->add(
ui::control_factory::make<ui::toggle_button>(_layer));
b3->set_caption("Toggle");
}

void demo_control_container::make_labels()
{
auto& _layer = get_layer();

m_buttons = this->add(make<ui::hbox_layout_container>(_layer));
m_buttons = this->add(
ui::control_factory::make<ui::hbox_layout_container>(_layer));

auto label1 = m_buttons->add(make<ui::label>(_layer));
auto label1 =
m_buttons->add(ui::control_factory::make<ui::label>(_layer));
label1->set_caption("Top left");
label1->set_horizontal_alignment(draw::text_horizontal_alignment::left);
label1->set_vertical_alignment(draw::text_vertical_alignment::top);
label1->set_background_color(draw::color{255, 128, 0});

auto label2 = m_buttons->add(make<ui::label>(_layer));
auto label2 =
m_buttons->add(ui::control_factory::make<ui::label>(_layer));
label2->set_caption("Middle center");
label2->set_horizontal_alignment(
draw::text_horizontal_alignment::center);
label2->set_vertical_alignment(draw::text_vertical_alignment::middle);
label2->set_background_color(draw::color{230, 150, 0});

auto label3 = m_buttons->add(make<ui::label>(_layer));
auto label3 =
m_buttons->add(ui::control_factory::make<ui::label>(_layer));
label3->set_caption("Bottom right");
label3->set_horizontal_alignment(
draw::text_horizontal_alignment::right);
Expand All @@ -71,38 +78,44 @@ namespace clsn::demo
{
auto& _layer = get_layer();

m_radio_buttons =
this->add(make<ui::hbox_layout_container>(_layer));
m_radio_buttons = this->add(
ui::control_factory::make<ui::hbox_layout_container>(_layer));

auto enabled_ones = m_radio_buttons->add(
make<ui::vbox_layout_container>(_layer));
ui::control_factory::make<ui::vbox_layout_container>(_layer));

auto rb1 = enabled_ones->add(make<ui::radio_button>(_layer));
auto rb1 = enabled_ones->add(
ui::control_factory::make<ui::radio_button>(_layer));
rb1->set_caption("Option 1");

auto rb2 = enabled_ones->add(make<ui::radio_button>(_layer));
auto rb2 = enabled_ones->add(
ui::control_factory::make<ui::radio_button>(_layer));
rb2->set_caption("Option 2");

auto rb3 = enabled_ones->add(make<ui::radio_button>(_layer));
auto rb3 = enabled_ones->add(
ui::control_factory::make<ui::radio_button>(_layer));
rb3->set_caption("Option 3");

m_toggle_control_group.add(rb1);
m_toggle_control_group.add(rb2);
m_toggle_control_group.add(rb3);

auto disabled_ones = m_radio_buttons->add(
make<ui::vbox_layout_container>(_layer));
ui::control_factory::make<ui::vbox_layout_container>(_layer));

auto db1 = disabled_ones->add(make<ui::radio_button>(_layer));
auto db1 = disabled_ones->add(
ui::control_factory::make<ui::radio_button>(_layer));
db1->set_caption("One");
db1->set_checked(true);
db1->set_enabled(false);

auto db2 = disabled_ones->add(make<ui::radio_button>(_layer));
auto db2 = disabled_ones->add(
ui::control_factory::make<ui::radio_button>(_layer));
db2->set_caption("Two");
db2->set_enabled(false);

auto db3 = disabled_ones->add(make<ui::radio_button>(_layer));
auto db3 = disabled_ones->add(
ui::control_factory::make<ui::radio_button>(_layer));
db3->set_caption("Three");
db3->set_enabled(false);
}
Expand All @@ -111,11 +124,12 @@ namespace clsn::demo
{
auto& _layer = get_layer();

m_check_boxes =
this->add(make<ui::hbox_layout_container>(_layer));
m_check_boxes = this->add(
ui::control_factory::make<ui::hbox_layout_container>(_layer));

auto padding = m_check_boxes->add(
make<ui::padding_control<ui::empty_control>>(_layer));
ui::control_factory::make<ui::padding_control<ui::empty_control>>(
_layer));
padding->set_foreground_color(draw::color{0, 240, 180});
padding->set_size(8);

Expand All @@ -133,30 +147,36 @@ namespace clsn::demo
}));

auto enabled_ones = m_check_boxes->add(
make<ui::vbox_layout_container>(_layer));
ui::control_factory::make<ui::vbox_layout_container>(_layer));

auto rb1 = enabled_ones->add(make<ui::check_box>(_layer));
auto rb1 =
enabled_ones->add(ui::control_factory::make<ui::check_box>(_layer));
rb1->set_caption("Option 1");

auto rb2 = enabled_ones->add(make<ui::check_box>(_layer));
auto rb2 =
enabled_ones->add(ui::control_factory::make<ui::check_box>(_layer));
rb2->set_caption("Option 2");

auto rb3 = enabled_ones->add(make<ui::check_box>(_layer));
auto rb3 =
enabled_ones->add(ui::control_factory::make<ui::check_box>(_layer));
rb3->set_caption("Option 3");

auto disabled_ones = m_check_boxes->add(
make<ui::vbox_layout_container>(_layer));
ui::control_factory::make<ui::vbox_layout_container>(_layer));

auto db1 = disabled_ones->add(make<ui::check_box>(_layer));
auto db1 = disabled_ones->add(
ui::control_factory::make<ui::check_box>(_layer));
db1->set_caption("One");
db1->set_enabled(false);

auto db2 = disabled_ones->add(make<ui::check_box>(_layer));
auto db2 = disabled_ones->add(
ui::control_factory::make<ui::check_box>(_layer));
db2->set_caption("Two");
db2->set_checked(true);
db2->set_enabled(false);

auto db3 = disabled_ones->add(make<ui::check_box>(_layer));
auto db3 = disabled_ones->add(
ui::control_factory::make<ui::check_box>(_layer));
db3->set_caption("Three");
db3->set_enabled(false);
}
Expand Down
5 changes: 3 additions & 2 deletions code/classeine-demo/demo_dual_layout_container.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "demo_dual_layout_container.h"

#include <clsn/ui/button.h>
#include <clsn/ui/control_factory.h>
#include <clsn/ui/label.h>

namespace clsn::demo
Expand All @@ -9,13 +10,13 @@ namespace clsn::demo
ui::layer_base& _layer)
: base{_layer}
{
auto _label = control::make<ui::label>(_layer);
auto _label = ui::control_factory::make<ui::label>(_layer);
_label->set_caption("Using all available space");
this->add(_label,
ui::layouts::dual_layout_constraint::use_all_available_space);

m_button =
this->add(control::make<ui::button>(_layer),
this->add(ui::control_factory::make<ui::button>(_layer),
ui::layouts::dual_layout_constraint::use_preferred_size);
m_button->set_preferred_size(draw::dimension{200, 0});
m_button->set_caption("Using preferred size");
Expand Down
13 changes: 7 additions & 6 deletions code/classeine-demo/demo_flow_layout_container.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "demo_flow_layout_container.h"

#include <clsn/ui/button.h>
#include <clsn/ui/control_factory.h>

namespace clsn::demo
{
Expand All @@ -9,22 +10,22 @@ namespace clsn::demo
{
set_background_color(draw::color{128, 0, 192});

m_file = this->add(control::make<ui::button>(_layer));
m_file = this->add(ui::control_factory::make<ui::button>(_layer));
m_file->set_caption("File");

m_edit = this->add(control::make<ui::button>(_layer));
m_edit = this->add(ui::control_factory::make<ui::button>(_layer));
m_edit->set_caption("Edit");

m_view = this->add(control::make<ui::button>(_layer));
m_view = this->add(ui::control_factory::make<ui::button>(_layer));
m_view->set_caption("View");

m_tools = this->add(control::make<ui::button>(_layer));
m_tools = this->add(ui::control_factory::make<ui::button>(_layer));
m_tools->set_caption("Tools");

m_window = this->add(control::make<ui::button>(_layer));
m_window = this->add(ui::control_factory::make<ui::button>(_layer));
m_window->set_caption("Window");

m_help = this->add(control::make<ui::button>(_layer));
m_help = this->add(ui::control_factory::make<ui::button>(_layer));
m_help->set_caption("Help");
m_help->set_background_color(draw::color{255, 128, 64});
}
Expand Down
15 changes: 7 additions & 8 deletions code/classeine-demo/demo_layers_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <clsn/draw/colors.h>

#include <clsn/ui/button.h>
#include <clsn/ui/control_factory.h>
#include <clsn/ui/label.h>
#include <clsn/ui/ui_layer_manager.h>
#include <clsn/ui/ui_manager.h>
Expand All @@ -15,7 +16,7 @@ namespace clsn::demo
: base{_layer}
{
auto create_normal_layer_btn =
this->add(control::make<ui::button>(_layer), draw::point{100, 100});
this->add(ui::control_factory::make<ui::button>(_layer), draw::point{100, 100});

create_normal_layer_btn->set_caption("Normal layer");
create_normal_layer_btn->set_preferred_size(draw::dimension{200, 40});
Expand All @@ -27,7 +28,7 @@ namespace clsn::demo
create_normal_layer_btn->get_actual_font().add_size(6));

auto create_destroyable_layer_btn =
this->add(control::make<ui::button>(_layer), draw::point{300, 100});
this->add(ui::control_factory::make<ui::button>(_layer), draw::point{300, 100});

create_destroyable_layer_btn->set_caption("Destroyable layer");
create_destroyable_layer_btn->set_preferred_size(draw::dimension{200, 40});
Expand All @@ -43,9 +44,8 @@ namespace clsn::demo
{
static int n = 0;

auto b = get_ui_manager()
.get_layer_manager()
.make_and_add<ui::button>(ui::layer_mode::normal);
auto b = ui::layer_factory::make_and_add<ui::button>
(get_ui_manager(), ui::layer_mode::normal);

b->get_typed_control()
.set_caption(
Expand Down Expand Up @@ -79,9 +79,8 @@ namespace clsn::demo
{
static int n = 0;

auto b = get_ui_manager()
.get_layer_manager()
.make_and_add<ui::label>(
auto b = ui::layer_factory::make_and_add<ui::label>(
get_ui_manager(),
ui::layer_mode::self_destroyable);

b->get_typed_control().set_caption(
Expand Down
13 changes: 6 additions & 7 deletions code/classeine-demo/demo_main_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ namespace clsn::demo
auto& _layer = get_layer();

m_action_container =
control::make<demo_action_container>(_layer, *this);
control_factory::make<demo_action_container>(_layer, *this);

add(m_action_container,
dual_layout_constraint::use_preferred_size);
add(m_action_container, dual_layout_constraint::use_preferred_size);

auto right_container =
add(control::make<dual_layout_container>(_layer),
dual_layout_constraint::use_all_available_space);
add(control_factory::make<dual_layout_container>(_layer),
dual_layout_constraint::use_all_available_space);
right_container->set_orientation(dual_layout_orientation::vertical);

m_label =
right_container->add(control::make<label>(_layer),
right_container->add(control_factory::make<label>(_layer),
dual_layout_constraint::use_preferred_size);
m_label->set_preferred_size(dimension{0, 40});
m_label->set_font(
Expand All @@ -57,7 +56,7 @@ namespace clsn::demo
set_title("Classeine Demo");

m_content_pane = right_container->add(
control::make<dynamic_content_pane>(_layer),
control_factory::make<dynamic_content_pane>(_layer),
dual_layout_constraint::use_all_available_space);
m_content_pane->set_background_color(clsn::draw::color{128, 0, 64});
}
Expand Down
Loading

0 comments on commit 20ba987

Please sign in to comment.