remove unused caption vertical alignment as we use all viewport height

This commit is contained in:
Andrea Blankenstijn 2021-07-20 12:29:17 +02:00
parent e884c27ccf
commit ec0d85b97a
5 changed files with 11 additions and 30 deletions

View file

@ -7,7 +7,7 @@ using widget::Caption;
int main()
{
run_example<Caption>([](Caption* w, core::Font* f, int, int) {
w->alignment.h = Caption::AlignmentH::CENTER;
w->alignment = Caption::Alignment::CENTER;
w->text("¡jello!");
w->font(f);
});

View file

@ -15,18 +15,12 @@ namespace bwidgets::widget
public TextureHandler
{
public:
enum struct AlignmentH {
enum struct Alignment {
CENTER,
LEFT,
RIGHT
};
enum struct AlignmentV {
BOTTOM,
CENTER,
TOP
};
private:
SDL_Color _color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
SDL_Color _color_bg {255, 255, 255, SDL_ALPHA_TRANSPARENT};
@ -42,10 +36,7 @@ namespace bwidgets::widget
virtual void _handle_texture_update() override;
public:
struct {
AlignmentH h;
AlignmentV v;
} alignment {AlignmentH::LEFT, AlignmentV::CENTER};
Alignment alignment {Alignment::LEFT};
core::Size margins {2, 2};
Caption(Widget* parent=nullptr) : Widget(parent) {}

View file

@ -107,8 +107,8 @@ namespace bwidgets::widget
_increment_button(this),
_decrement_button(this)
{
Input<T>::_input_caption.alignment.h =
widget::Caption::AlignmentH::RIGHT;
Input<T>::_input_caption.alignment =
widget::Caption::Alignment::RIGHT;
_increment_button.text("+");

View file

@ -10,7 +10,7 @@ widget::Button::Button(Widget* parent)
_caption(this)
{
_focus_area = _click_area = &_widget_area;
_caption.alignment.h = Caption::AlignmentH::CENTER;
_caption.alignment = Caption::Alignment::CENTER;
}
core::Size widget::Button::size() const noexcept

View file

@ -94,32 +94,22 @@ void widget::Caption::_handle_rendering()
};
SDL_Rect texture_dst {
margins.w,
core::center_rect(_widget_area.h, size_dst.h) + margins.h,
margins.h,
size_dst.w,
size_dst.h
};
switch (alignment.h)
switch (alignment)
{
case AlignmentH::CENTER:
case Alignment::CENTER:
texture_dst.x = core::center_rect(_widget_area.w, texture_dst.w)
+ _widget_area.x;
break;
case AlignmentH::LEFT:
case Alignment::LEFT:
break;
case AlignmentH::RIGHT:
case Alignment::RIGHT:
texture_dst.x = _widget_area.w - texture_dst.w - margins.w + _widget_area.x;
break;
}
switch (alignment.v)
{
case AlignmentV::BOTTOM:
texture_dst.y = _widget_area.h - texture_dst.h - margins.h + _widget_area.y;
break;
case AlignmentV::CENTER:
break;
case AlignmentV::TOP:
texture_dst.y = margins.h + _widget_area.y;
}
_renderer->copy(_text_texture, NULL, texture_dst);
}