Incremental Improvements
This commit is contained in:
@@ -102,15 +102,15 @@ namespace JUI
|
||||
|
||||
protected:
|
||||
std::string content = "Sample Text";
|
||||
Color4 text_color = {255,255,255,255};
|
||||
Color4 text_color = {255,255,255};
|
||||
float text_outline = 1.f;
|
||||
Color4 outline_color = {255,255,255,255};
|
||||
Color4 outline_color = {255,255,255};
|
||||
bool word_wrap = false;
|
||||
TextAlign::H h_align = TextAlign::H::Left;
|
||||
TextAlign::V v_align = TextAlign::V::Top;
|
||||
TextOverflowMode overflow_mode;
|
||||
JGL::Font set_font;
|
||||
u32 text_size;
|
||||
u32 text_size = 12;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -307,8 +307,13 @@ namespace JUI
|
||||
Vector2 viewport_size{0,0};
|
||||
|
||||
|
||||
Vector2 GetAbsolutePaddingTopLeft() const;
|
||||
|
||||
Vector2 GetAbsolutePaddingBottomRight() const;
|
||||
|
||||
Vector2 GetAbsoluteMarginTopLeft();
|
||||
|
||||
Vector2 GetAbsoluteMarginBottomRight();
|
||||
};
|
||||
|
||||
|
||||
|
@@ -83,6 +83,10 @@ namespace JUI
|
||||
/// Sets the border color of this object when it is disabled.
|
||||
void DisabledBorderColor(const Color4& color);
|
||||
|
||||
void BGColors(const Color4& base, const Color4& hover, const Color4& pressed, const Color4& disabled = Colors::Gray);
|
||||
|
||||
void BorderColors(const Color4& base, const Color4& hover, const Color4& pressed, const Color4& disabled = Colors::Gray);
|
||||
|
||||
/// Returns whether is button is interactable. If enabled, it will listen to mouse events and react accordingly.
|
||||
bool Enabled() const;
|
||||
/// Returns whether is button is interactable. If enabled, it will listen to mouse events and react accordingly.
|
||||
|
@@ -18,7 +18,8 @@ namespace JUI
|
||||
|
||||
}
|
||||
|
||||
void SetFont(JGL::Font use_my_font)
|
||||
|
||||
void SetFont(const JGL::Font& use_my_font)
|
||||
{
|
||||
font = use_my_font;
|
||||
}
|
||||
@@ -39,7 +40,6 @@ namespace JUI
|
||||
|
||||
};
|
||||
|
||||
|
||||
class UtilityBar : public Rect
|
||||
{
|
||||
public:
|
||||
@@ -66,7 +66,7 @@ namespace JUI
|
||||
btn->SetContent(name);
|
||||
return btn;
|
||||
}
|
||||
void SetFont(JGL::Font use_my_font)
|
||||
void SetFont(const JGL::Font& use_my_font)
|
||||
{
|
||||
font = use_my_font;
|
||||
}
|
||||
|
81
main.cpp
81
main.cpp
@@ -57,8 +57,50 @@ JUI::Scene* CreateScene() {
|
||||
|
||||
topbar->AddButton("Edit");
|
||||
topbar->AddButton("This Dick");
|
||||
|
||||
//auto* horizontal = new HorizontalListLayout(root);
|
||||
//horizontal->ZIndex(1);
|
||||
|
||||
auto* sizer_1 = new Rect(root);
|
||||
sizer_1->ZIndex(1);
|
||||
sizer_1->Size({0,-24,0.2f, 1.f});
|
||||
sizer_1->Position({0, 24, 0, 0});
|
||||
sizer_1->BGColor(Colors::Grays::Gainsboro);
|
||||
|
||||
auto* s1_vert = new VerticalListLayout(sizer_1);
|
||||
|
||||
auto* button = new TextButton(s1_vert);
|
||||
//button->Position({5, 105, 0, 0});
|
||||
button->Size({0, 35, 1, 0});
|
||||
button->SetFont(FreeSans);
|
||||
button->SetTextColor(Colors::Black);
|
||||
button->SetContent("Button");
|
||||
button->AlignLeft();
|
||||
button->Padding(5_px);
|
||||
|
||||
auto* button2 = new TextButton(s1_vert);
|
||||
//button2->Position({5, 105, 0, 0});
|
||||
button2->Size({0, 35, 1, 0});
|
||||
button2->SetFont(FreeSans);
|
||||
button2->SetTextColor(Colors::Black);
|
||||
button2->SetContent("Button");
|
||||
button2->AlignCenterHorizontally();
|
||||
|
||||
auto* button3 = new TextButton(s1_vert);
|
||||
//button2->Position({5, 105, 0, 0});
|
||||
button3->Size({0, 35, 1, 0});
|
||||
button3->SetFont(FreeSans);
|
||||
button3->SetTextColor(Colors::Black);
|
||||
button3->SetContent("Button");
|
||||
button3->AlignRight();
|
||||
|
||||
|
||||
auto* main_wnd = new Window(root);
|
||||
//auto* left = new HorizontalListLayout();
|
||||
|
||||
|
||||
|
||||
|
||||
//auto* btn = new TextButton(root);
|
||||
|
||||
|
||||
@@ -165,13 +207,13 @@ JUI::Scene* CreateScene() {
|
||||
btntext->SetTextSize(8);
|
||||
btntext->SetTextColor({255, 0, 0});
|
||||
// End Button //
|
||||
|
||||
*/
|
||||
// Window //
|
||||
JUI::Window* win_element = new JUI::Window(root);
|
||||
win_element->SetTitleFont(FreeSans);
|
||||
win_element->CornerRounding(5);
|
||||
win_element->Size({50_percent, 50_percent});
|
||||
win_element->SetTitle("JUI Example Window Widget");
|
||||
win_element->SetTitle("Window Widget");
|
||||
//win_element->Padding(1_px);
|
||||
// End Window //
|
||||
|
||||
@@ -190,50 +232,19 @@ JUI::Scene* CreateScene() {
|
||||
a->Size({0, 20, 1, 0});
|
||||
//a->FitText(true);
|
||||
a->Center();
|
||||
a->SetContent("Greetings. This is the JUI demo program!");
|
||||
a->SetContent("This is a virtual window.");
|
||||
|
||||
|
||||
TextRect* b = new TextRect(list);
|
||||
b->SetTextSize(16);
|
||||
b->SetContent("JUI is my home-coded game menu building toolkit.");
|
||||
b->SetContent("You can drag it around via left-click, and resize via right-click.");
|
||||
//b->FitText(true);
|
||||
b->Size({0, 20, 1, 0});
|
||||
b->Center();
|
||||
b->SetFont(FreeSans);
|
||||
|
||||
TextRect* c = new TextRect(list);
|
||||
c->SetTextSize(16);
|
||||
c->SetContent("Settings");
|
||||
//c->FitText(true);
|
||||
c->Size({0, 20, 1, 0});
|
||||
c->Center();
|
||||
c->SetFont(FreeSans);
|
||||
|
||||
TextRect* d = new TextRect(list);
|
||||
d->SetTextSize(16);
|
||||
d->SetContent("Exit");
|
||||
//d->FitText(true);
|
||||
d->Size({0, 20, 1, 0});
|
||||
d->Center();
|
||||
d->SetFont(FreeSans);
|
||||
|
||||
|
||||
|
||||
|
||||
Text *text = new Text(rect_element);
|
||||
text->SetContent("YO MAMA");
|
||||
text->SetFont(FreeSans);
|
||||
text->SetTextSize(48);
|
||||
text->SetTextColor({255, 0, 0});*/
|
||||
|
||||
|
||||
|
||||
root->SetViewportSize({800, 600});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@@ -177,6 +177,81 @@ namespace JUI {
|
||||
return ancestors;
|
||||
}
|
||||
|
||||
/*float Widget::GetAbsoluteMarginLeft()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsoluteMarginRight()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsoluteMarginTop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsoluteMarginBottom()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingLeft()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingRight()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingTop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingBottom()
|
||||
{
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
Vector2 Widget::GetAbsolutePaddingTopLeft() const {
|
||||
auto parent_abs_size = this->GetParent()->GetAbsoluteSize();
|
||||
|
||||
UDim padding_h = parent->PaddingLeft();
|
||||
UDim padding_v = parent->PaddingTop();
|
||||
|
||||
float padding_x = padding_h.Pixels + (padding_h.Scale * parent_abs_size.x);
|
||||
float padding_y = padding_v.Pixels + (padding_v.Scale * parent_abs_size.y);
|
||||
|
||||
return {padding_x, padding_y};
|
||||
}
|
||||
|
||||
Vector2 Widget::GetAbsoluteMarginTopLeft()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Vector2 Widget::GetAbsolutePaddingBottomRight() const {
|
||||
UDim padding_h = parent->PaddingLeft() + parent->PaddingRight();
|
||||
float final_pad_x = padding_h.Pixels + (padding_h.Scale * parent->GetAbsoluteSize().x);
|
||||
|
||||
UDim padding_v = parent->PaddingTop() + parent->PaddingBottom();
|
||||
float final_pad_y = padding_v.Pixels + (padding_v.Scale * parent->GetAbsoluteSize().y);
|
||||
|
||||
Vector2 padding = {final_pad_x, final_pad_y};
|
||||
|
||||
return padding;
|
||||
}
|
||||
|
||||
Vector2 Widget::GetAbsoluteMarginBottomRight()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vector2 Widget::GetAbsolutePosition() const {
|
||||
@@ -193,14 +268,7 @@ namespace JUI {
|
||||
|
||||
auto anchor_offset = abs_size * AnchorPoint();
|
||||
|
||||
UDim padding_h = parent->PaddingLeft();
|
||||
UDim padding_v = parent->PaddingTop();
|
||||
|
||||
float calculated_padding_x = padding_h.Pixels + (padding_h.Scale * parent_abs_size.x);
|
||||
float calculated_padding_y = padding_v.Pixels + (padding_v.Scale * parent_abs_size.y);
|
||||
|
||||
Vector2 padding_offset = {calculated_padding_x, calculated_padding_y};
|
||||
|
||||
Vector2 padding_offset = GetAbsolutePaddingTopLeft();
|
||||
|
||||
Vector2 absolute_position =
|
||||
parent_abs_pos + child_pos_pixels + (parent_abs_size * child_pos_scale) + padding_offset;
|
||||
@@ -219,13 +287,7 @@ namespace JUI {
|
||||
|
||||
Vector2 parent_abs_size = this->GetParent()->GetAbsoluteSize();
|
||||
|
||||
UDim padding_h = parent->PaddingLeft() + parent->PaddingRight();
|
||||
float final_pad_x = padding_h.Pixels + (padding_h.Scale * parent->GetAbsoluteSize().x);
|
||||
|
||||
UDim padding_v = parent->PaddingTop() + parent->PaddingBottom();
|
||||
float final_pad_y = padding_v.Pixels + (padding_v.Scale * parent->GetAbsoluteSize().y);
|
||||
|
||||
Vector2 pad_size_reduction = {final_pad_x, final_pad_y};
|
||||
Vector2 pad_size_reduction = GetAbsolutePaddingBottomRight();
|
||||
|
||||
Vector2 abs_size = child_size_px + (parent_abs_size * child_size_scale) - pad_size_reduction;
|
||||
|
||||
|
@@ -180,5 +180,19 @@ namespace JUI
|
||||
|
||||
void Button::DisabledBorderColor(const Color4 &color) { disabled_border = color; }
|
||||
|
||||
void Button::BorderColors(const Color4 &base, const Color4 &hover, const Color4 &pressed, const Color4 &disabled) {
|
||||
BaseBorderColor(base);
|
||||
HoveredBorderColor(hover);
|
||||
PressedBorderColor(pressed);
|
||||
DisabledBGColor(disabled);
|
||||
}
|
||||
|
||||
void Button::BGColors(const Color4 &base, const Color4 &hover, const Color4 &pressed, const Color4 &disabled) {
|
||||
BaseBGColor(base);
|
||||
HoveredBGColor(hover);
|
||||
PressedBGColor(pressed);
|
||||
DisabledBGColor(disabled);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -14,6 +14,7 @@ namespace JUI
|
||||
|
||||
void TextButton::Draw() {
|
||||
Button::Draw();
|
||||
TextBase::Draw(this->GetAbsolutePosition(), this->GetAbsoluteSize());
|
||||
// TODO: Factor in padding here.
|
||||
TextBase::Draw(this->GetAbsolutePosition()+GetAbsolutePaddingTopLeft(), this->GetAbsoluteSize()-GetAbsolutePaddingBottomRight());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user