- mark as const every pointer that can be const. - in implementation mark const args passed by value that are meant to be read-only. - wrap in a lambda complex initializations of (const) values. - argument passing: - pass by value arguments of cheap-to-copy types or meant to be copied anyway. - pass by (const) reference args not meant to outlive called function scope and not cheap-to-copy. - pass (const) pointers to (const) args when null is a valid option and pointed data aren't expected to outlive function scope. - use string_view for non-owned strings (not meant to outlive function scope). - use span for collection types like vector and arrays. - fancy pointers passing: - pass by value if a reference will be held: - pass by const reference if a reference _may_ be hell. - when no references are meant to be held: - dereference the pointer to pass the pointed data by reference if null is not an option. - pass the underlying raw pointer if null is an option. … and random subtle changes and fixes here and there that I forgot to mention.
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#ifndef BWIDGETS_CAPTION_HPP
|
|
#define BWIDGETS_CAPTION_HPP
|
|
|
|
#include <basic_widgets/w/base/widget.hpp>
|
|
#include <basic_widgets/w/feat/font_handler.hpp>
|
|
#include <basic_widgets/w/feat/texture_handler.hpp>
|
|
|
|
struct SDL_Surface;
|
|
|
|
namespace bwidgets
|
|
{
|
|
class Caption : public virtual Widget,
|
|
public virtual FontHandler,
|
|
public virtual TextureHandler
|
|
{
|
|
public:
|
|
enum struct Alignment
|
|
{
|
|
CENTER,
|
|
LEFT,
|
|
RIGHT
|
|
};
|
|
inline static const Color default_color_bg = {255, 255, 255, SDL_ALPHA_OPAQUE};
|
|
inline static const Color default_color_fg = {0, 0, 0, SDL_ALPHA_OPAQUE};
|
|
inline static const Size default_margins = {3, 3};
|
|
|
|
Alignment alignment {Alignment::LEFT};
|
|
Size margins {default_margins};
|
|
|
|
using Widget::Widget;
|
|
|
|
virtual void render_mode(Font::RenderMode) = 0;
|
|
[[nodiscard]] virtual auto text() const noexcept -> std::string_view = 0;
|
|
virtual void text(std::string) = 0;
|
|
};
|
|
}
|
|
|
|
#endif
|