ImageButton & change window exit to red circle.

This commit is contained in:
2025-02-08 16:03:45 -05:00
parent 2aaba5c1f7
commit fc65e9d229
5 changed files with 69 additions and 15 deletions

View File

@@ -0,0 +1,17 @@
#include <JUI/Base/ImageBase.hpp>
#include <JUI/Widgets/Button.hpp>
namespace JUI {
class ImageButton;
}
class JUI::ImageButton : public ImageBase, public Button {
public:
void Update(float delta) override;
void Draw() override;
public:
ImageButton() : ImageBase(), Button() {}
explicit ImageButton(Widget* parent) : ImageButton() { Parent(parent); }
public:
~ImageButton() override = default;
};

View File

@@ -23,6 +23,7 @@
#include <JUI/Mixins/Hoverable.hpp>
#include <JUI/Mixins/Clickable.hpp>
#include <JUI/Widgets/TextButton.hpp>
#include <JUI/Widgets/ImageButton.hpp>
namespace JUI
{
@@ -93,7 +94,7 @@ namespace JUI
/// Returns a pointer to the Rect Widget that is used to layout the contents of the window.
Rect* ViewportInstance();
/// Returns a pointer to the Exit Button Widget.
TextButton* ExitButtonInstance();
ImageButton* ExitButtonInstance();
Vector2 AbsoluteViewportPosition() const;
Vector2 AbsoluteViewportSize() const;
@@ -122,8 +123,8 @@ namespace JUI
JUI::Rect* Topbar;
JUI::Rect* Viewport;
JUI::Text* TitleLabel;
JUI::TextButton* exit_btn;
JUI::TextButton* fs_btn;
JUI::ImageButton* exit_btn;
JUI::ImageButton* fs_btn;
std::string title = "JUI Window";
bool resizable = true;
//bool resizing = false;

View File

@@ -132,7 +132,6 @@ JUI::Scene* CreateScene() {
other_window->TweenPositionTo({50_percent, 50_percent});
scroller = new JUI::ScrollingRect(other_window->ViewportInstance());
scroller->Size({100_percent, 100_percent});
scroller->BGColor(Colors::Reds::LightCoral);

View File

@@ -0,0 +1,10 @@
#include <JUI/Widgets/ImageButton.hpp>
void JUI::ImageButton::Update(float delta) {
Button::Update(delta);
}
void JUI::ImageButton::Draw() {
Button::Draw();
ImageBase::Draw(GetAbsolutePosition()+GetAbsolutePaddingTopLeft(), GetAbsoluteSize()-GetAbsolutePaddingBottomRight());
}

View File

@@ -50,16 +50,43 @@ namespace JUI
// TODO: auto* list = new HorizontalListLayout(Topbar);
// TODO: exit_btn
exit_btn = new TextButton(Topbar);
auto* exb_tex = new Texture({titlebar_height, titlebar_height });
auto* exb_rt = new RenderTarget(exb_tex);
if (exb_rt->SetMSAAEnabled(JGL::MSAA_SAMPLE_RATE::MSAA_8X)) {/* using msaa to make the circle nicer. */}
std::array<Color4, 2> exb_circle_colors
{
Color4(168, 28, 28, 255),
Color4(212, 25, 25, 255)
};
std::array<Vector2, 2> exb_circle_positions
{
Vector2(exb_rt->GetDimensions()) / 2,
Vector2(exb_rt->GetDimensions()) / 2
};
std::array<float, 2> exb_circle_radii
{
(float) (exb_rt->GetDimensions().x * 0.33),
(float) (exb_rt->GetDimensions().x * 0.28)
};
J2D::Begin(exb_rt, true);
J2D::BatchFillCircle(exb_circle_colors.data(), exb_circle_positions.data(), exb_circle_radii.data(), 24, 2);
J2D::End();
delete exb_rt;
exit_btn = new ImageButton(Topbar);
exit_btn->Content(exb_tex);
//exit_btn->AnchorPoint({1.f, 0.f});
//exit_btn->Size({30_px, 100_percent});
exit_btn->Size({titlebar_height, titlebar_height, 0, 0});
//exit_btn->BorderColor({128, 128, 128, 255});
//exit_btn->SetBaseColor({192, 64, 64, 255});
//exit_btn->SetHoverColor({255, 0, 0, 255});
//exit_btn->BGColor({192, 64, 64, 255});
exit_btn->SetContent("X");
// exit_btn->BorderColor({128, 128, 128, 255});
exit_btn->BaseBGColor({92,92,192, 255});
exit_btn->BGColor(exit_btn->BaseBGColor());
exit_btn->BorderColors({0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0});
@@ -67,9 +94,9 @@ namespace JUI
exit_btn->SetBorderWidth(0.f);
//exit_btn_text->SetFont(TitleLabel->GetFont());
exit_btn->SetTextSize(title_font_size);
exit_btn->SetTextColor({255, 0, 0});
exit_btn->Center();
//exit_btn->SetTextSize(title_font_size);
//exit_btn->SetTextColor({255, 0, 0});
//exit_btn->Center();
exit_btn->OnClickEvent += [&] (auto... _) {
this->Visible(false);
@@ -108,7 +135,7 @@ namespace JUI
void Window::SetTitleFont(const Font& f) {
TitleLabel->SetFont(f);
exit_btn->SetFont(f);
//exit_btn->SetFont(f);
}
void Window::OnClick(const Vector2& mouse_pos, const MouseButton& btn)
@@ -220,7 +247,7 @@ namespace JUI
resizable = value;
}
TextButton *Window::ExitButtonInstance() {
ImageButton* Window::ExitButtonInstance() {
return exit_btn;
}