Skip to content

Commit

Permalink
Feature/cla 72 normalize mono container and dynamic pane (#42)
Browse files Browse the repository at this point in the history
* cla-72: created dynamic-content-pane and static-content-pane

* cla-72: updated stats
  • Loading branch information
ebasconp authored Oct 2, 2024
1 parent 68c1005 commit d59e7eb
Show file tree
Hide file tree
Showing 25 changed files with 622 additions and 318 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGELOG #

* 20241002 added dynamic and static content panes
* 20240917 added doxygen action in github
* 20240916 created demo app
* 20240904 created clsn::ui::dynamic_pane
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ add_executable(classeine
code/classeine-lib/clsn/ui/check_box.cpp
code/classeine-lib/clsn/ui/captionable_control.cpp
code/classeine-lib/clsn/ui/clickable_control.cpp
code/classeine-lib/clsn/ui/content_pane.cpp
code/classeine-lib/clsn/ui/control.cpp
code/classeine-lib/clsn/ui/dual_layout_container.cpp
code/classeine-lib/clsn/ui/dynamic_pane.cpp
code/classeine-lib/clsn/ui/dynamic_content_pane.cpp
code/classeine-lib/clsn/ui/empty_control.cpp
code/classeine-lib/clsn/ui/flow_layout_container.cpp
code/classeine-lib/clsn/ui/hbox_layout_container.cpp
code/classeine-lib/clsn/ui/label.cpp
code/classeine-lib/clsn/ui/mono_container.h
code/classeine-lib/clsn/ui/paintable_control.cpp
code/classeine-lib/clsn/ui/radio_button.cpp
code/classeine-lib/clsn/ui/radio_button_group.cpp
Expand Down Expand Up @@ -111,8 +111,8 @@ add_executable(classeine

code/classeine-lib/clsn/ui/renderers/button_renderer.cpp
code/classeine-lib/clsn/ui/renderers/check_box_renderer.cpp
code/classeine-lib/clsn/ui/renderers/content_pane_renderer.cpp
code/classeine-lib/clsn/ui/renderers/customizable_renderer.cpp
code/classeine-lib/clsn/ui/renderers/dynamic_pane_renderer.cpp
code/classeine-lib/clsn/ui/renderers/empty_control_renderer.cpp
code/classeine-lib/clsn/ui/renderers/label_renderer.cpp
code/classeine-lib/clsn/ui/renderers/radio_button_renderer.cpp
Expand Down
1 change: 1 addition & 0 deletions code/LOC.csv
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Date,Value
2024-07-01,2925
2024-08-01,3684
2024-09-01,4388
2024-10-02,5472

2 changes: 1 addition & 1 deletion code/classeine-demo/demo_option_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "clsn/draw/dimension.h"

#include "clsn/ui/button.h"
#include "clsn/ui/dynamic_pane.h"
#include "clsn/ui/dynamic_content_pane.h"
#include "clsn/ui/hbox_layout_container.h"
#include "clsn/ui/vbox_layout_container.h"

Expand Down
6 changes: 3 additions & 3 deletions code/classeine-demo/demo_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "clsn/draw/dimension.h"

#include "clsn/ui/dual_layout_container.h"
#include "clsn/ui/dynamic_pane.h"
#include "clsn/ui/dynamic_content_pane.h"
#include "clsn/ui/label.h"

#include "demo_option_container.h"
Expand All @@ -28,7 +28,7 @@ namespace clsn::demo
init_container();
}

auto demo_window::get_content_pane() -> dynamic_pane&
auto demo_window::get_content_pane() -> dynamic_content_pane&
{
return *m_content_pane;
}
Expand All @@ -49,7 +49,7 @@ namespace clsn::demo
m_label->set_horizontal_alignment(text_horizontal_alignment::center);
set_title("Classeine Demo");

m_content_pane = right_container->make_and_add<dynamic_pane>(dual_layout_constraint::use_all_available_space);
m_content_pane = right_container->make_and_add<dynamic_content_pane>(dual_layout_constraint::use_all_available_space);
m_content_pane->set_background_color(clsn::draw::color{128, 0, 64});
}

Expand Down
4 changes: 2 additions & 2 deletions code/classeine-demo/demo_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace clsn::demo
{
std::shared_ptr<demo_option_container> m_option_container;
std::shared_ptr<label> m_label;
std::shared_ptr<dynamic_pane> m_content_pane;
std::shared_ptr<dynamic_content_pane> m_content_pane;

public:
demo_window();

void set_title(const std::string& title);

auto get_content_pane() -> dynamic_pane&;
auto get_content_pane() -> dynamic_content_pane&;

private:
void init_container();
Expand Down
175 changes: 175 additions & 0 deletions code/classeine-lib/clsn/core/optional_reference.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// This file belongs to the Classeine project
//
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: © 2024 Ernesto Bascón Pantoja

#pragma once

#include <clsn/core/system.h>

#include <functional>
#include <optional>

namespace clsn::core
{
/// A class that encapsulates an optional reference to an object of type T.
///
/// This class uses std::optional and std::reference_wrapper to manage
/// optional references to objects.
///
/// @tparam T The type of the object the reference will point to.
template <typename T>
class optional_reference
{
std::optional<std::reference_wrapper<T>> m_value;

public:
/// Constructs an optional_reference that holds a reference to the given object.
///
/// @param value The object to hold a reference to.
optional_reference(T& value)
: m_value{value}
{
}

/// Default constructor that constructs an optional_reference without a value.
optional_reference()
: optional_reference{std::nullopt}
{
}

/// Constructs an optional_reference without a value.
///
/// @param nullopt A std::nullopt_t to initialize the optional_reference without a value.
optional_reference(std::nullopt_t)
: m_value{std::nullopt}
{}

/// Copy constructor.
///
/// @param other Another optional_reference to copy from.
optional_reference(const optional_reference& other)
{
m_value = other.m_value;
}

/// Move constructor.
///
/// @param other Another optional_reference to move from.
optional_reference(optional_reference&& other) noexcept
{
m_value = std::move(other.m_value);
}

/// Copy assignment operator.
///
/// @param other Another optional_reference to copy from.
/// @return A reference to this optional_reference.
auto operator=(const optional_reference& other) -> optional_reference&
{
if (&other == this)
return *this;

m_value = other.m_value;
return *this;
}

/// Move assignment operator.
///
/// @param other Another optional_reference to move from.
/// @return A reference to this optional_reference.
auto operator=(optional_reference&& other) noexcept -> optional_reference&
{
if (&other == this)
return *this;

m_value = std::move(other.m_value);
return *this;
}

/// Checks if the optional_reference contains a value.
///
/// @return true if the optional_reference contains a value, false otherwise.
[[nodiscard]] bool has_value() const noexcept
{
return m_value.has_value();
}

/// Invokes the given procedure if the optional_reference contains a value.
///
/// @tparam Proc The type of the procedure to invoke.
/// @param proc The procedure to invoke.
/// @return The result of invoking the procedure, if the optional_reference contains a value.
template <typename Proc>
auto safe_invoke(Proc proc)
{
if (has_value())
return proc(get_ref());
}

/// Gets a reference to the value.
///
/// @return A reference to the value.
/// @throws system::panic if the optional_reference does not contain a value.
auto get_ref() -> T&
{
if (!has_value())
system::panic("optional_reference_with_no_value");

return m_value.value().get();
}

/// Gets a const reference to the value.
///
/// @return A const reference to the value.
/// @throws system::panic if the optional_reference does not contain a value.
auto get_ref() const -> const T&
{
if (!has_value())
system::panic("optional_reference_with_no_value");

return m_value.value().get();
}

/// Converts the current optional_reference to an optional_reference with a const reference.
///
/// @return An optional_reference<const T> with a const reference to the value.
auto to_const() const -> optional_reference<const T>
{
if (!has_value())
return {};

return optional_reference<const T>{get_ref()};
}

/// Equality operator.
///
/// @param other Another optional_reference to compare with.
/// @return true if both optional_references are equal, false otherwise.
bool operator==(const optional_reference& other) const
{
if (has_value() != other.has_value())
return false;

if (!has_value())
return true;

return get_ref() == other.get_ref();
}

/// Inequality operator.
///
/// @param other Another optional_reference to compare with.
/// @return true if both optional_references are not equal, false otherwise.
bool operator!=(const optional_reference& other) const
{
return !(*this == other);
}
};

/// An alias for optional_reference with a const reference.
///
/// @tparam T The type of the object the reference will point to.
template <typename T>
using const_optional_reference = optional_reference<const T>;
}
8 changes: 4 additions & 4 deletions code/classeine-lib/clsn/ui/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace clsn::ui
/// @param point The position to check.
/// @return An optional reference to the control at the position.
auto get_control_by_position(const draw::point &point) const
-> const_optional_reference<control> override
-> core::const_optional_reference<control> override
{
for (auto& c : get_controls())
{
Expand All @@ -254,13 +254,13 @@ namespace clsn::ui
return result;
}

return std::nullopt;
return {};
}

/// @brief Sets the parent window for the container and its controls.
///
/// @param pw The optional reference to the parent window.
void set_parent_window(optional_reference<window> pw) override
void set_parent_window(core::optional_reference<window> pw) override
{
control::set_parent_window(pw);

Expand All @@ -273,7 +273,7 @@ namespace clsn::ui
/// @brief Sets the parent control for the container and its controls.
///
/// @param parent_control The optional reference to the parent control.
void set_parent_control(optional_reference<control> parent_control) override
void set_parent_control(core::optional_reference<control> parent_control) override
{
control::set_parent_control(parent_control);

Expand Down
Loading

0 comments on commit d59e7eb

Please sign in to comment.