Skip to content

Commit

Permalink
Merge pull request libRocket#43 from viciious/crashfix_and_columnid
Browse files Browse the repository at this point in the history
A bugfix and a new feature for datagrid cells
  • Loading branch information
lloydw committed Mar 29, 2012
2 parents 51c24aa + 3ecf236 commit 0fdecf2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Include/Rocket/Controls/ElementDataGridCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class ROCKETCONTROLS_API ElementDataGridCell : public Core::Element, public Core
ElementDataGridCell(const Rocket::Core::String& tag);
virtual ~ElementDataGridCell();

void Initialise(Core::Element* header);
void Initialise(int column, Core::Element* header);
int GetColumn();

protected:
virtual void ProcessEvent(Core::Event& event);

private:
int column;
Core::Element* header;
};

Expand Down
13 changes: 11 additions & 2 deletions Source/Controls/ElementDataGridCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,29 @@ ElementDataGridCell::ElementDataGridCell(const Rocket::Core::String& tag) : Core

ElementDataGridCell::~ElementDataGridCell()
{
if (header)
if (header) {
header->RemoveEventListener("resize", this);
header->RemoveReference();
}
}

void ElementDataGridCell::Initialise(Core::Element* _header)
void ElementDataGridCell::Initialise(int _column, Core::Element* _header)
{
column = _column;
header = _header;
if (header)
{
header->AddReference();
header->AddEventListener("resize", this);
SetProperty("width", Core::Property(header->GetBox().GetSize(Core::Box::MARGIN).x, Core::Property::PX));
}
}

int ElementDataGridCell::GetColumn()
{
return column;
}

void ElementDataGridCell::ProcessEvent(Core::Event& event)
{
Core::Element::ProcessEvent(event);
Expand Down
2 changes: 1 addition & 1 deletion Source/Controls/ElementDataGridRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void ElementDataGridRow::Initialise(ElementDataGrid* _parent_grid, ElementDataGr
for (int i = 0; i < num_columns; i++)
{
ElementDataGridCell* cell = dynamic_cast< ElementDataGridCell* >(Core::Factory::InstanceElement(this, "#rktctl_datagridcell", "datagridcell", cell_attributes));
cell->Initialise(header_row->GetChild(i));
cell->Initialise(i, header_row->GetChild(i));
cell->SetProperty("display", Rocket::Core::Property(Rocket::Core::DISPLAY_INLINE_BLOCK, Rocket::Core::Property::KEYWORD));
AppendChild(cell);
cell->RemoveReference();
Expand Down

0 comments on commit 0fdecf2

Please sign in to comment.