fix caption, add vertical align, add margins
This commit is contained in:
parent
6ddd0a5453
commit
59d4f88e3d
|
@ -14,12 +14,18 @@ namespace bwidgets::widget
|
|||
class Caption : public abstract::Widget, public abstract::FontHandler
|
||||
{
|
||||
public:
|
||||
enum struct Alignment {
|
||||
enum struct AlignmentH {
|
||||
CENTER,
|
||||
LEFT,
|
||||
RIGHT
|
||||
};
|
||||
|
||||
enum struct AlignmentV {
|
||||
BOTTOM,
|
||||
CENTER,
|
||||
TOP
|
||||
};
|
||||
|
||||
private:
|
||||
SDL_Color _color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
|
||||
std::string _text;
|
||||
|
@ -31,8 +37,12 @@ namespace bwidgets::widget
|
|||
void _render_text();
|
||||
|
||||
public:
|
||||
Alignment alignment {Alignment::LEFT};
|
||||
SDL_Color color_bg {0, 0, 0, SDL_ALPHA_TRANSPARENT};
|
||||
struct {
|
||||
AlignmentH h;
|
||||
AlignmentV v;
|
||||
} alignment {AlignmentH::LEFT, AlignmentV::CENTER};
|
||||
SDL_Color color_bg {0, 0, 0, SDL_ALPHA_TRANSPARENT};
|
||||
abstract::Widget::Size margins {3, 0};
|
||||
|
||||
~Caption();
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ namespace bwidgets::widget
|
|||
_increment_button(), // FIXME: parenthood
|
||||
_decrement_button()
|
||||
{
|
||||
abstract::Input<T>::_input_caption.alignment =
|
||||
widget::Caption::Alignment::RIGHT;
|
||||
abstract::Input<T>::_input_caption.alignment.h =
|
||||
widget::Caption::AlignmentH::RIGHT;
|
||||
_increment_button.text("+");
|
||||
_increment_button.click_handler = [this](const SDL_MouseButtonEvent&) {
|
||||
T new_value = this->value() + button_step;
|
||||
|
|
|
@ -11,7 +11,7 @@ widget::Button::Button(Widget* parent)
|
|||
: abstract::Widget(parent)
|
||||
{
|
||||
_focus_area = _click_area = &_widget_area;
|
||||
_caption.alignment = Caption::Alignment::CENTER;
|
||||
_caption.alignment.h = Caption::AlignmentH::CENTER;
|
||||
}
|
||||
|
||||
int widget::Button::height() const
|
||||
|
|
|
@ -50,24 +50,32 @@ void widget::Caption::render(SDL_Renderer* r)
|
|||
_viewport.h
|
||||
};
|
||||
SDL_Rect texture_dst {
|
||||
0,
|
||||
utils::math::center_rect(_viewport.h, _text_surface->h),
|
||||
margins.w,
|
||||
utils::math::center_rect(_viewport.h, size_dst.h),
|
||||
size_dst.w,
|
||||
size_dst.h
|
||||
};
|
||||
|
||||
switch (alignment)
|
||||
switch (alignment.h)
|
||||
{
|
||||
case Alignment::CENTER:
|
||||
case AlignmentH::CENTER:
|
||||
texture_dst.x = utils::math::center_rect(_viewport.w, texture_dst.w);
|
||||
break;
|
||||
case Alignment::LEFT:
|
||||
case AlignmentH::LEFT:
|
||||
break;
|
||||
case Alignment::RIGHT:
|
||||
texture_dst.x = _viewport.w - texture_dst.w - 3;
|
||||
case AlignmentH::RIGHT:
|
||||
texture_dst.x = _viewport.w - texture_dst.w - margins.w;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (alignment.v)
|
||||
{
|
||||
case AlignmentV::BOTTOM:
|
||||
texture_dst.y = _viewport.h - texture_dst.h - margins.h;
|
||||
break;
|
||||
case AlignmentV::CENTER:
|
||||
break;
|
||||
case AlignmentV::TOP:
|
||||
texture_dst.y = margins.h;
|
||||
}
|
||||
SDL_RenderCopy(
|
||||
r,
|
||||
_text_texture,
|
||||
|
|
Loading…
Reference in a new issue