Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ebasconp committed Sep 26, 2024
1 parent 8959b2f commit 4b940ab
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 40 deletions.
2 changes: 1 addition & 1 deletion code/classeine-lib/clsn/core/lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include <<clsn/core/entity.h>
#include <clsn/core/entity.h>

#include <functional>
#include <optional>
Expand Down
68 changes: 57 additions & 11 deletions code/classeine-lib/clsn/draw/color.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,80 @@
// This file belongs to the Classeine project
//
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: © 2024 Ernesto Bascón Pantoja
/// @file
/// @brief Defines the color class for the Classeine project, providing color manipulation utilities.
/// This file belongs to the Classeine project.
/// @details This class encapsulates color properties and provides methods to manipulate
/// and retrieve color information. Various constructors are offered to initialize
/// the color in different ways.
/// @license BSD-3-Clause
/// @copyright © 2024 Ernesto Bascón Pantoja

#pragma once

namespace clsn::draw
{
/// @brief Class representing a color with red, green, blue, and alpha components.
class color final
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
unsigned char r; ///< Red component of the color.
unsigned char g; ///< Green component of the color.
unsigned char b; ///< Blue component of the color.
unsigned char a; ///< Alpha (transparency) component of the color, where 255 is fully opaque.

public:
/// @brief Default constructor initializing the color to black (rgba: 0, 0, 0, 255).
color();

/// @brief Constructor initializing the color with red, green, and blue values. Alpha is set to 255.
/// @param r Red component.
/// @param g Green component.
/// @param b Blue component.
color(int r, int g, int b);

/// @brief Constructor initializing the color with red, green, blue, and alpha values.
/// @param r Red component.
/// @param g Green component.
/// @param b Blue component.
/// @param a Alpha component.
color(int r, int g, int b, int a);

/// @brief Constructor initializing the color with a hexadecimal code.
/// @param hexaCode Hexadecimal value representing the color.
explicit color(int hexaCode);

/// @brief Gets the color as an integer in ARGB format.
/// @return Integer representing the ARGB color.
[[nodiscard]] auto get_color() const noexcept -> int;

/// @brief Gets the red component of the color.
/// @return Integer representing the red component.
[[nodiscard]] auto get_red() const noexcept -> int;

/// @brief Gets the green component of the color.
/// @return Integer representing the green component.
[[nodiscard]] auto get_green() const noexcept -> int;

/// @brief Gets the blue component of the color.
/// @return Integer representing the blue component.
[[nodiscard]] auto get_blue() const noexcept -> int;

/// @brief Gets the alpha component of the color.
/// @return Integer representing the alpha component.
[[nodiscard]] auto get_alpha() const noexcept -> int;

auto operator==(const color& ) const noexcept -> bool;
/// @brief Equality operator to compare two color objects.
/// @param other The color to compare with.
/// @return True if colors are equal, false otherwise.
auto operator==(const color& other) const noexcept -> bool;

/// @brief Converts the color to its grayscale equivalent.
/// @return A new color object representing the grayscale color.
[[nodiscard]] auto to_gray() const noexcept -> color;

auto to_gray() const noexcept -> color;
auto to_gray_if(bool ) const noexcept -> color;
/// @brief Converts the color to grayscale if the specified condition is true.
/// @details This method helps simplify color decision logic by embedding the condition check
/// and the conversion in a single method. If the condition is true, the color is converted
/// to its grayscale equivalent.
/// @param condition Boolean condition to trigger the grayscale conversion.
/// @return A new color object in grayscale if condition is true, otherwise the original color.
[[nodiscard]] auto to_gray_if(bool condition) const noexcept -> color;
};
}
25 changes: 22 additions & 3 deletions code/classeine-lib/clsn/draw/dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,41 @@

namespace clsn::draw
{
/// @brief Class representing 2D dimensions with width and height.
class dimension final
{
int m_width;
int m_height;
int m_width; ///< Width of the dimension.
int m_height; ///< Height of the dimension.

public:
/// @brief Default constructor initializing dimensions to zero.
dimension();

/// @brief Constructor initializing dimensions with specific width and height values.
/// @param width Width of the dimension.
/// @param height Height of the dimension.
dimension(int width, int height);

/// @brief Gets the width of the dimension.
/// @return Integer representing the width.
[[nodiscard]] auto get_width() const noexcept -> int;

/// @brief Gets the height of the dimension.
/// @return Integer representing the height.
[[nodiscard]] auto get_height() const noexcept -> int;

/// @brief Equality operator to compare two dimension objects.
/// @param other The dimension to compare with.
/// @return True if dimensions are equal, false otherwise.
auto operator==(const dimension& other) const noexcept -> bool;

/// @brief Addition operator to add two dimension objects.
/// @param other The dimension to add.
/// @return A new dimension object representing the sum of both dimensions.
auto operator+(const dimension& other) const noexcept -> dimension;

auto to_string() const -> std::string;
/// @brief Converts the dimension to a string representation.
/// @return A std::string representing the dimension.
[[nodiscard]] auto to_string() const -> std::string;
};
}
2 changes: 1 addition & 1 deletion code/classeine-lib/clsn/draw/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: © 2024 Ernesto Bascón Pantoja

#include "font.h"
#include <clsn/draw/font.h>

#include <tuple>

Expand Down
8 changes: 4 additions & 4 deletions code/classeine-lib/clsn/draw/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ namespace clsn::draw
{
}

auto get_name() const noexcept -> const std::string&;
auto get_size() const noexcept -> int;
auto get_style() const noexcept -> font_style;
[[nodiscard]] auto get_name() const noexcept -> const std::string&;
[[nodiscard]] auto get_size() const noexcept -> int;
[[nodiscard]] auto get_style() const noexcept -> font_style;

auto add_size(int size) const noexcept -> font;
[[nodiscard]] auto add_size(int size) const noexcept -> font;

bool operator==(const font& font) const noexcept;
};
Expand Down
2 changes: 1 addition & 1 deletion code/classeine-lib/clsn/draw/font_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: © 2024 Ernesto Bascón Pantoja

#include "font_info.h"
#include <clsn/draw/font_info.h>

namespace clsn::draw
{
Expand Down
6 changes: 3 additions & 3 deletions code/classeine-lib/clsn/draw/font_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include "font_style.h"
#include <clsn/draw/font_style.h>

#include <string>
#include <string_view>
Expand All @@ -22,8 +22,8 @@ namespace clsn::draw

auto operator==(const font_info& oth) const -> bool;

auto get_style() const noexcept -> font_style;
auto get_name() const noexcept -> const std::string&;
[[nodiscard]] auto get_style() const noexcept -> font_style;
[[nodiscard]] auto get_name() const noexcept -> const std::string&;
};
}

Expand Down
4 changes: 2 additions & 2 deletions code/classeine-lib/clsn/draw/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#pragma once

#include "text_horizontal_alignment.h"
#include "text_vertical_alignment.h"
#include <clsn/draw/text_horizontal_alignment.h>
#include <clsn/draw/text_vertical_alignment.h>

namespace clsn::draw
{
Expand Down
2 changes: 1 addition & 1 deletion code/classeine-lib/clsn/draw/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ namespace clsn::draw

auto operator+(const point& other) const noexcept -> point;

auto to_string() const -> std::string;
[[nodiscard]] auto to_string() const -> std::string;
};
}
2 changes: 1 addition & 1 deletion code/classeine-lib/clsn/draw/region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace clsn::draw
&& py > ty && py < (ty + height);
}

auto region::to_string() noexcept -> std::string
auto region::to_string() const noexcept -> std::string
{
return clsn::core::strings::format("Region. Position: [{}], Size: [{}]",
m_position, m_size);
Expand Down
2 changes: 1 addition & 1 deletion code/classeine-lib/clsn/draw/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace clsn::draw

[[nodiscard]] auto operator+(const region& r) const noexcept -> region;

auto to_string() noexcept -> std::string;
[[nodiscard]] auto to_string() const noexcept -> std::string;

};
}
36 changes: 30 additions & 6 deletions code/classeine-lib/clsn/ui/layouts/layout.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// This file belongs to the Classeine project
//
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: © 2024 Ernesto Bascón Pantoja
/// @file
/// @brief Base class for UI layouts in the Classeine project.
/// This file belongs to the Classeine project.
/// @copyright © 2024 Ernesto Bascón Pantoja
/// @license BSD-3-Clause

#pragma once

#include <clsn/draw/region.h>

#include <vector>

namespace clsn::ui::layouts
{
/// @brief Template base class for UI layouts.
/// @tparam Constraint The type of constraint used in the layout.
template <typename Constraint>
class layout
{
public:
/// @brief Information about a layout element.
class layout_element_info final
{
draw::region m_output_region;
Expand All @@ -23,6 +26,10 @@ namespace clsn::ui::layouts
bool m_visible;

public:
/// @brief Constructs a layout_element_info object.
/// @param input_region The input region of the element.
/// @param constraint The constraint associated with the element.
/// @param visible The visibility status of the element.
layout_element_info(const draw::region& input_region, const Constraint& constraint, bool visible)
: m_output_region{0, 0, 0, 0}
, m_input_region{input_region}
Expand All @@ -31,19 +38,36 @@ namespace clsn::ui::layouts
{
}

/// @brief Gets the output region of the element.
/// @return A constant reference to the output region.
auto get_output_region() const -> const draw::region& { return m_output_region; }

/// @brief Sets the output region of the element.
/// @param output_region The new output region to set.
void set_output_region(const draw::region& output_region) { m_output_region = output_region; }

/// @brief Gets the input region of the element.
/// @return A constant reference to the input region.
auto get_input_region() const -> const draw::region& { return m_input_region; }

/// @brief Gets the constraint of the element.
/// @return A constant reference to the constraint.
auto get_constraint() const -> const Constraint& { return m_constraint; }

/// @brief Checks if the element is visible.
/// @return True if the element is visible, false otherwise.
auto is_visible() const -> bool { return m_visible; }
};

/// @brief A vector of layout_element_info objects.
using layout_element_info_vector = std::vector<layout_element_info>;

/// @brief Virtual destructor.
virtual ~layout() = default;

virtual void do_layout(const draw::region& rgn, layout_element_info_vector&) const = 0;
/// @brief Performs layout in the specified region using the provided element info vector.
/// @param rgn The region in which to perform the layout.
/// @param layout_element_info_vec The vector of layout element info.
virtual void do_layout(const draw::region& rgn, layout_element_info_vector& layout_element_info_vec) const = 0;
};
}
18 changes: 13 additions & 5 deletions code/classeine-lib/clsn/ui/layouts/layout_utils.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// This file belongs to the Classeine project
//
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: © 2024 Ernesto Bascón Pantoja
/// @file
/// @brief Utility functions related to UI layouts.
/// This file belongs to the Classeine project.
/// @copyright © 2024 Ernesto Bascón Pantoja
/// @license BSD-3-Clause

#pragma once

#include <clsn/core/non_instantiable.h>

#include <algorithm>

namespace clsn::ui
Expand All @@ -17,9 +17,17 @@ namespace clsn::ui

namespace clsn::ui::layouts
{
/// @brief Utility class for managing UI layout information.
class layout_utils : public clsn::core::non_instantiable
{
public:
/// @brief Converts the elements of a layout container to layout info.
/// This function maps the elements of a layout container to elements
/// that can be processed by a layout.
///
/// @tparam LayoutType The type of the layout.
/// @param container The layout container whose elements need to be converted.
/// @return A vector of layout element info specific to the layout type.
template <typename LayoutType>
static auto to_layout_info(layout_container<LayoutType>& container)
-> typename LayoutType::layout_element_info_vector
Expand Down

0 comments on commit 4b940ab

Please sign in to comment.