Skip to content

Commit

Permalink
Add initial Form layout
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-attack committed Jun 28, 2024
1 parent d5d7c64 commit 8bbc395
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gwen/UnitTest/UnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ GWEN_CONTROL_CONSTRUCTOR( UnitTest )
ADD_UNIT_TEST( CollapsibleList );
ADD_UNIT_TEST( ColorPicker );
}
{
Controls::CollapsibleCategory* cat = pList->Add( "Layouts" );
ADD_UNIT_TEST( FormLayout );
}
m_StatusBar->SendToBack();
PrintText( L"Unit Test Started.\n" );
m_fLastSecond = Gwen::Platform::GetTimeInSeconds();
Expand Down
81 changes: 81 additions & 0 deletions gwen/include/Gwen/Controls/Layout/Form.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
GWEN
Copyright (c) 2010 Facepunch Studios
See license in Gwen.h
*/

#pragma once
#ifndef GWEN_CONTROLS_LAYOUT_FORM_H
#define GWEN_CONTROLS_LAYOUT_FORM_H

#include "Gwen/Controls/Label.h"
#include "Gwen/Utility.h"


namespace Gwen
{
namespace Controls
{
namespace Layout
{
class GWEN_EXPORT Form : public Base
{
std::vector<std::pair<Label*, Base*>> m_Rows;
public:

GWEN_CONTROL_INLINE( Form, Base )
{
}

void Layout( Skin::Base* skin ) override
{
// determine label width
int w = 0;
for ( auto& r: m_Rows )
{
if (!r.first) continue;
r.first->SizeToContents();
w = std::max(r.first->Width(), w);
}
// layout the rows
int h = 0;
for ( auto& r: m_Rows )
{
r.second->SetPos(w + 3, h);
r.second->SetWidth(Width() - (w + 3));
int nh = r.second->Height();
nh = std::max(nh, r.second->GetMinimumSize().y);
r.second->SetHeight(nh);
if (r.first)
{
r.first->SetPos(0, h);
nh = std::max(nh, r.first->Height());
}
//printf("w %i h %i\n", w, h);
h += nh + 3;// todo variable padding
}
SetHeight(std::max(Height(), h));
}

void AddRow(const Gwen::UnicodeString& label, Base* control)
{
Gwen::Controls::Label* l = new Gwen::Controls::Label( this );
l->SetText( label );
l->SizeToContents();
m_Rows.push_back({l, control});
Invalidate();
}

void AddRow(Base* control)
{
m_Rows.push_back({0, control});
Invalidate();
}

private:

};
}
}
}
#endif
2 changes: 1 addition & 1 deletion gwen/include/Gwen/Controls/Layout/Position.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef GWEN_CONTROLS_LAYOUT_POSITION_H
#define GWEN_CONTROLS_LAYOUT_POSITION_H

#include "Gwen/Controls/Label.h"
#include "Gwen/Controls/Base.h"
#include "Gwen/Utility.h"


Expand Down

0 comments on commit 8bbc395

Please sign in to comment.