Change Window default style, implement Window::TitlebarHeight

This commit is contained in:
2025-02-11 18:33:30 -05:00
parent 2579b587c4
commit bfd898b4f6
2 changed files with 51 additions and 41 deletions

View File

@@ -29,7 +29,6 @@ namespace JUI
{
using J3ML::LinearAlgebra::Vector2;
class DockingStation {};
/// A container widget class, with title bar and buttons,
@@ -40,7 +39,7 @@ namespace JUI
/// The default constructor sets a default style for this Window.
Window();
/// Construct a window widget by specifying it's parent.
Window(Widget* parent);
explicit Window(Widget* parent);
/// Returns the current size (in x,y pixels) of the Window widget.
[[nodiscard]] Vector2 CurrentSize() const;
@@ -54,10 +53,11 @@ namespace JUI
/// Sets the maximum size (in x,y pixels) that the Window widget is allowed to be.
void MaxSize(const Vector2& constraint);
/// Returns the height (in pixels) of the Window's titlebar.
// TODO: Decide if this will auto-scale with the titlebar's text height, or the other way around.
int TitlebarHeight() const;
[[nodiscard]] int TitlebarHeight() const;
void TitlebarHeight(int height);
/// Returns the text displayed as the Window's title.
[[nodiscard]] std::string Title() const;
@@ -66,7 +66,6 @@ namespace JUI
/// @see class Draggable.
bool IsDraggable() const;
void SetDraggable(bool value);
/// Returns whether this Window is able to be 'Docked' into another widget.
@@ -87,6 +86,13 @@ namespace JUI
void SetResizable(bool value);
void CornerRounding(float radius) override
{
RectBase::CornerRounding(radius);
}
/// Returns a pointer to the Text Widget that is used to render the title bar's text.
Text* TitleInstance();
/// Returns a pointer to the Rect Widget that is used to layout the title bar contents.
@@ -100,17 +106,11 @@ namespace JUI
Vector2 AbsoluteViewportSize() const;
AABB2D AbsoluteViewportBounds() const;
/// Sets the font used by the title-bar text on this Window.
void SetTitleFont(const Font& f);
/// Toggles whether this window is actively being dragged by the mouse.
/// @see class Draggable.
void SetDrag(bool d) override;
/// @see class Widget.
void Update(float delta) override;
/// @see class Widget.
@@ -120,6 +120,9 @@ namespace JUI
/// @see class Clickable.
void OnRelease(const Vector2& m_pos, const MouseButton& m_btn, bool still_hovering) override;
protected:
void UpdateInternalWidgetsTitlebarHeight();
protected:
JUI::Rect* Topbar;
JUI::Rect* Viewport;
JUI::Text* TitleLabel;

View File

@@ -3,17 +3,17 @@
#include <cstdlib>
namespace JUI
{
namespace JUI {
Window::Window() : Widget(), Clickable(), Hoverable(), RectBase(), Draggable(), Resizable(), Dockable() {
this->Position({200, 200, 0, 0});
this->Size({400, 200, 0, 0});
min_size = {400, 200};
this->BGColor({64,64,64,255});
this->BGColor({92,92,192, 255});
this->BorderColor({92,92,192});
this->SetBorderWidth(2);
this->BorderMode(BorderMode::Middle);
// TODO: Move out of Event callback
this->OnReleaseEvent += [&] (Vector2 dummy, MouseButton btn, bool dummy3) {
if (dragging) {
@@ -23,10 +23,9 @@ namespace JUI
Viewport = new Rect(this);
Viewport->Name("Viewport");
Viewport->BGColor({64,64,64, 0});
Viewport->Size({0, -20, 1, 1});
Viewport->Position({0, 20, 0, 0});
Viewport->BGColor({64,64,64, 255});
Viewport->Size({0, -titlebar_height, 1, 1});
Viewport->Position({0, titlebar_height, 0, 0});
// TODO: Viewport->AnchorPoint({0.f, 0.f});
Viewport->BorderColor({128, 128, 128, 255});
Viewport->SetBorderWidth(0);
@@ -37,7 +36,8 @@ namespace JUI
Topbar = new Rect(this);
Topbar->Position({0_px, 0_px});
Topbar->Size({100_percent, UDim(titlebar_height, 0)});
Topbar->BGColor({92,92,192, 255});
//Topbar->BGColor({92,92,192, 255});
Topbar->BGColor(Colors::Transparent);
Topbar->BorderColor({128, 128, 128, 0});
Topbar->SetBorderWidth(0);
@@ -46,30 +46,26 @@ namespace JUI
TitleLabel->SetContent(title);
TitleLabel->SetTextSize(title_font_size);
// TODO: Pull out this circle image generation code, make a Circle widget.
// TODO: auto* list = new HorizontalListLayout(Topbar);
// TODO: exit_btn
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<Color4, 2> exb_circle_colors {
Colors::White,//Color4(168, 28, 28, 255),
Colors::White//Color4(212, 25, 25, 255)
};
std::array<Vector2, 2> exb_circle_positions
{
std::array<Vector2, 2> exb_circle_positions {
Vector2(exb_rt->GetDimensions()) / 2,
Vector2(exb_rt->GetDimensions()) / 2
};
std::array<float, 2> exb_circle_radii
{
std::array<float, 2> exb_circle_radii {
(float) (exb_rt->GetDimensions().x * 0.33),
(float) (exb_rt->GetDimensions().x * 0.28)
};
@@ -85,20 +81,14 @@ namespace JUI
//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->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});
exit_btn->BorderColor({0,0,0,0});
exit_btn->BGColor(Colors::Transparent);
exit_btn->BGColors(Colors::Transparent, Colors::Transparent, Colors::Transparent, Colors::Transparent);
exit_btn->SetBorderWidth(0.f);
exit_btn->BaseImageColor(Colors::Reds::LightCoral);
exit_btn->HoveredImageColor(Colors::Red);
exit_btn->PressedImageColor(Colors::Reds::DarkRed);
//exit_btn_text->SetFont(TitleLabel->GetFont());
//exit_btn->SetTextSize(title_font_size);
//exit_btn->SetTextColor({255, 0, 0});
//exit_btn->Center();
exit_btn->OnClickEvent += [&] (auto... _) {
exit_btn->OnReleaseEvent += [&] (auto... _) {
this->Visible(false);
};
@@ -272,4 +262,21 @@ namespace JUI
AABB2D Window::AbsoluteViewportBounds() const {
return {AbsoluteViewportPosition(), AbsoluteViewportSize()};
}
void Window::UpdateInternalWidgetsTitlebarHeight() {
Viewport->Size({0, -titlebar_height, 1, 1});
Viewport->Position({0, titlebar_height, 0, 0});
Topbar->Size({100_percent, UDim(titlebar_height, 0)});
exit_btn->Size({titlebar_height, titlebar_height, 0, 0});
}
void Window::TitlebarHeight(int height) {
titlebar_height = height;
UpdateInternalWidgetsTitlebarHeight();
}
int Window::TitlebarHeight() const {
return titlebar_height;
}
}