[DEV] add a basic gird on the widget to display subWidget
This commit is contained in:
parent
27a6281357
commit
feb1ed56af
@ -63,6 +63,12 @@ void informOneObjectIsRemoved(ewol::EObject* object)
|
||||
m_eObjectList[iii]->OnObjectRemove(object);
|
||||
}
|
||||
}
|
||||
for (int32_t iii=0; iii<m_eObjectAutoRemoveList.Size(); iii++) {
|
||||
if( m_eObjectAutoRemoveList[iii] != NULL
|
||||
&& m_eObjectAutoRemoveList[iii] != object) {
|
||||
m_eObjectAutoRemoveList[iii]->OnObjectRemove(object);
|
||||
}
|
||||
}
|
||||
// call input event manager to remove linked widget ...
|
||||
eSystem::OnObjectRemove(object);
|
||||
}
|
||||
@ -82,6 +88,14 @@ void ewol::EObjectManager::Rm(ewol::EObject* object)
|
||||
return;
|
||||
}
|
||||
}
|
||||
// check if the object has not been auto removed ... or remove in defered time ...
|
||||
for (int32_t iii=0; iii<m_eObjectAutoRemoveList.Size(); iii++) {
|
||||
if( m_eObjectAutoRemoveList[iii] != NULL
|
||||
&& m_eObjectAutoRemoveList[iii] == object) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// in this case, we have an error ...
|
||||
EWOL_ERROR("Try to remove EObject that is not referenced ...");
|
||||
}
|
||||
|
||||
|
412
sources/ewol/widget/Gird.cpp
Normal file
412
sources/ewol/widget/Gird.cpp
Normal file
@ -0,0 +1,412 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/widget/Gird.h>
|
||||
#include <ewol/widget/WidgetManager.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Gird"
|
||||
|
||||
|
||||
widget::Gird::Gird(int32_t colNumber) :
|
||||
m_tmpWidget(NULL),
|
||||
m_sizeRow(0),
|
||||
m_borderSize(0,0)
|
||||
{
|
||||
SetColNumber(colNumber);
|
||||
ewol::RequestUpdateSize();
|
||||
}
|
||||
|
||||
widget::Gird::~Gird(void)
|
||||
{
|
||||
EWOL_DEBUG("[" << GetId() << "]={" << GetObjectType() << "} Gird : destroy");
|
||||
SubWidgetRemoveAll();
|
||||
}
|
||||
|
||||
void widget::Gird::SetBorderSize(const ivec2& newBorderSize)
|
||||
{
|
||||
m_borderSize = newBorderSize;
|
||||
if (m_borderSize.x() < 0) {
|
||||
EWOL_ERROR("Try to set a border size <0 on x : " << m_borderSize.x() << " ==> restore to 0");
|
||||
m_borderSize.setX(0);
|
||||
}
|
||||
if (m_borderSize.y() < 0) {
|
||||
EWOL_ERROR("Try to set a border size <0 on y : " << m_borderSize.y() << " ==> restore to 0");
|
||||
m_borderSize.setY(0);
|
||||
}
|
||||
MarkToRedraw();
|
||||
ewol::RequestUpdateSize();
|
||||
}
|
||||
|
||||
bool widget::Gird::CalculateSize(float availlableX, float availlableY)
|
||||
{
|
||||
//EWOL_DEBUG("Update Size");
|
||||
m_size.setValue(availlableX, availlableY);
|
||||
m_size -= m_borderSize*2;
|
||||
// calculate unExpendable Size :
|
||||
float unexpendableSize=0.0;
|
||||
int32_t nbWidgetFixedSize=0;
|
||||
int32_t nbWidgetNotFixedSize=0;
|
||||
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (NULL != m_subWidget[iii].widget) {
|
||||
//calculate the origin :
|
||||
vec2 tmpOrigin = m_origin + m_borderSize;
|
||||
// adding X origin :
|
||||
|
||||
int32_t tmpSizeWidth = 0;
|
||||
for (int32_t jjj=0; jjj<m_subWidget[iii].col; jjj++ ){
|
||||
tmpSizeWidth += abs(m_sizeCol[jjj]);
|
||||
}
|
||||
// adding Y orogin :
|
||||
int32_t addingPos = (m_subWidget[iii].row+1)*m_uniformSizeRow;
|
||||
|
||||
tmpOrigin += vec2(tmpSizeWidth, addingPos);
|
||||
|
||||
EWOL_DEBUG(" [" << iii << "] set subwidget origin=" <<tmpOrigin << " size=" << ivec2(abs(m_sizeCol[m_subWidget[iii].col]), m_uniformSizeRow) );
|
||||
// Set the origin :
|
||||
m_subWidget[iii].widget->SetOrigin(tmpOrigin.x(), tmpOrigin.y());
|
||||
// all time set oll the space .
|
||||
m_subWidget[iii].widget->CalculateSize(abs(m_sizeCol[m_subWidget[iii].col]), m_uniformSizeRow);
|
||||
}
|
||||
}
|
||||
m_size += m_borderSize*2;
|
||||
EWOL_DEBUG("Calculate size : " << m_size);
|
||||
MarkToRedraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool widget::Gird::CalculateMinSize(void)
|
||||
{
|
||||
for (int32_t iii=0; iii<m_sizeCol.Size(); iii++ ){
|
||||
if (m_sizeCol[iii] <= 0) {
|
||||
m_sizeCol[iii] = 0;
|
||||
}
|
||||
}
|
||||
//EWOL_DEBUG("Update minimum Size");
|
||||
m_minSize.setValue(0,0);
|
||||
if (m_userMinSize.x()>0) {
|
||||
m_minSize.setX(m_userMinSize.x());
|
||||
}
|
||||
if (m_userMinSize.y()>0) {
|
||||
m_minSize.setY(m_userMinSize.y());
|
||||
}
|
||||
m_uniformSizeRow = 0;
|
||||
m_minSize += m_borderSize*2;
|
||||
int32_t lastLineID = 0;
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (m_subWidget[iii].row > lastLineID) {
|
||||
// change of line :
|
||||
lastLineID = m_subWidget[iii].row;
|
||||
}
|
||||
if (NULL != m_subWidget[iii].widget) {
|
||||
m_subWidget[iii].widget->CalculateMinSize();
|
||||
vec2 tmpSize = m_subWidget[iii].widget->GetMinSize();
|
||||
EWOL_DEBUG(" [" << iii << "] subWidgetMinSize=" << tmpSize);
|
||||
// for all we get the max Size :
|
||||
m_uniformSizeRow = etk_max(tmpSize.y(), m_uniformSizeRow);
|
||||
// for the colomn size : We set the autamatic value in negative :
|
||||
if (m_sizeCol[m_subWidget[iii].col] <= 0) {
|
||||
m_sizeCol[m_subWidget[iii].col] = etk_min(m_sizeCol[m_subWidget[iii].col], -tmpSize.x() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_sizeRow > 0) {
|
||||
m_uniformSizeRow = m_sizeRow;
|
||||
}
|
||||
int32_t tmpSizeWidth = 0;
|
||||
for (int32_t iii=0; iii<m_sizeCol.Size(); iii++ ){
|
||||
tmpSizeWidth += abs(m_sizeCol[iii]);
|
||||
}
|
||||
EWOL_DEBUG(" tmpSizeWidth=" << tmpSizeWidth);
|
||||
EWOL_DEBUG(" m_uniformSizeRow=" << m_uniformSizeRow);
|
||||
m_minSize += ivec2(tmpSizeWidth, (lastLineID+1)*m_uniformSizeRow);
|
||||
|
||||
EWOL_DEBUG("Calculate min size : " << m_minSize);
|
||||
|
||||
//EWOL_DEBUG("Vert Result : expend="<< m_userExpend << " minSize="<< m_minSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
void widget::Gird::SetColNumber(int32_t colNumber)
|
||||
{
|
||||
if (m_sizeCol.Size() > colNumber) {
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
// remove subWidget :
|
||||
for (int32_t iii=m_subWidget.Size(); iii>=0; iii--) {
|
||||
if (m_subWidget[iii].col>(colNumber-1)) {
|
||||
// out of bounds : must remove it ...
|
||||
if (m_subWidget[iii].widget != NULL) {
|
||||
delete (m_subWidget[iii].widget);
|
||||
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
|
||||
if (errorControl == m_subWidget.Size()) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
|
||||
m_subWidget[iii].widget = NULL;
|
||||
}
|
||||
} else {
|
||||
EWOL_WARNING("[" << GetId() << "] Must not have null pointer on the subWidget list ...");
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
errorControl = m_subWidget.Size();
|
||||
}
|
||||
}
|
||||
// just add the col size:
|
||||
m_sizeCol.Erase(m_sizeCol.Size()-1, 0x7FFFFFFF);
|
||||
} else {
|
||||
// just add the col size:
|
||||
for (int32_t iii=m_sizeCol.Size()-1; iii<colNumber-1 ; iii++) {
|
||||
m_sizeCol.PushBack(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void widget::Gird::SetColSize(int32_t colId, int32_t size)
|
||||
{
|
||||
if (m_sizeCol.Size() > colId) {
|
||||
m_sizeCol[colId] = size;
|
||||
} else {
|
||||
EWOL_ERROR("Can not set the Colomn size : " << colId+1 << " at " << size << "px we have "<< m_sizeCol.Size() << " colomn");
|
||||
}
|
||||
}
|
||||
|
||||
void widget::Gird::SetRowSize(int32_t size)
|
||||
{
|
||||
m_sizeRow = size;
|
||||
}
|
||||
|
||||
int32_t widget::Gird::GetColSize(int32_t colId)
|
||||
{
|
||||
if (m_sizeCol.Size() > colId) {
|
||||
if (m_sizeCol[colId] <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return m_sizeCol[colId];
|
||||
}
|
||||
EWOL_ERROR("Can not get the Colomn size : " << colId+1 << " we have "<< m_sizeCol.Size() << " colomn");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t widget::Gird::GetRowSize(void)
|
||||
{
|
||||
return m_sizeRow;
|
||||
}
|
||||
|
||||
void widget::Gird::SubWidgetRemoveAll(void)
|
||||
{
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
// the size automaticly decrement with the auto call of the OnObjectRemove function
|
||||
while (m_subWidget.Size() > 0 ) {
|
||||
if (NULL != m_subWidget[0].widget) {
|
||||
delete(m_subWidget[0].widget);
|
||||
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
|
||||
if (errorControl == m_subWidget.Size()) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
|
||||
m_subWidget[0].widget = NULL;
|
||||
}
|
||||
} else {
|
||||
EWOL_WARNING("[" << GetId() << "] Must not have null pointer on the subWidget list ...");
|
||||
m_subWidget.Erase(0);
|
||||
}
|
||||
errorControl = m_subWidget.Size();
|
||||
}
|
||||
m_subWidget.Clear();
|
||||
}
|
||||
|
||||
|
||||
void widget::Gird::SubWidgetAdd(int32_t colId, int32_t rowId, ewol::Widget* newWidget)
|
||||
{
|
||||
if (NULL == newWidget) {
|
||||
return;
|
||||
}
|
||||
GirdProperties prop;
|
||||
prop.row = rowId;
|
||||
prop.col = colId;
|
||||
prop.widget = newWidget;
|
||||
|
||||
// need to find the correct position :
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (m_subWidget[iii].row < prop.row) {
|
||||
continue;
|
||||
} else if (m_subWidget[iii].row > prop.row) {
|
||||
// find a new position;
|
||||
m_subWidget.Insert(iii, prop);
|
||||
return;
|
||||
} else {
|
||||
if (m_subWidget[iii].col < prop.col) {
|
||||
continue;
|
||||
} else if (m_subWidget[iii].col > prop.col) {
|
||||
// find a new position;
|
||||
m_subWidget.Insert(iii, prop);
|
||||
return;
|
||||
} else {
|
||||
// The element already exist ==> replace it ...
|
||||
m_tmpWidget = m_subWidget[iii].widget;
|
||||
m_subWidget[iii].widget = newWidget;
|
||||
if (NULL != m_tmpWidget) {
|
||||
delete(m_tmpWidget);
|
||||
if (m_tmpWidget != NULL) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] Error while replacing a widget ... ==> never call when free");
|
||||
m_tmpWidget = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// not find ==> just adding it ...
|
||||
m_subWidget.PushBack(prop);
|
||||
}
|
||||
|
||||
void widget::Gird::SubWidgetRemove(ewol::Widget* newWidget)
|
||||
{
|
||||
if (NULL == newWidget) {
|
||||
return;
|
||||
}
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (newWidget == m_subWidget[iii].widget) {
|
||||
delete(m_subWidget[iii].widget);
|
||||
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
|
||||
if (errorControl == m_subWidget.Size()) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
|
||||
m_subWidget[iii].widget = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
EWOL_WARNING("[" << GetId() << "] Can not remove unExistant widget");
|
||||
}
|
||||
|
||||
void widget::Gird::SubWidgetRemove(int32_t colId, int32_t rowId)
|
||||
{
|
||||
if (colId<0 || rowId<0) {
|
||||
EWOL_WARNING("[" << GetId() << "] try to remove widget with id < 0 col=" << colId << " row=" << rowId);
|
||||
return;
|
||||
}
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
// try to find it ...
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if( m_subWidget[iii].row == rowId
|
||||
&& m_subWidget[iii].col == colId) {
|
||||
if (NULL==m_subWidget[iii].widget) {
|
||||
EWOL_WARNING("[" << GetId() << "] Remove NULL widget");
|
||||
m_subWidget.Erase(iii);
|
||||
} else {
|
||||
// The element already exist ==> replace it ...
|
||||
if (NULL != m_subWidget[iii].widget) {
|
||||
delete(m_subWidget[iii].widget);
|
||||
if (errorControl == m_subWidget.Size()) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
|
||||
m_subWidget[iii].widget = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
EWOL_WARNING("[" << GetId() << "] Can not remove unExistant widget");
|
||||
}
|
||||
|
||||
void widget::Gird::SubWidgetUnLink(ewol::Widget* newWidget)
|
||||
{
|
||||
if (NULL == newWidget) {
|
||||
return;
|
||||
}
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (newWidget == m_subWidget[iii].widget) {
|
||||
m_subWidget[iii].widget = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void widget::Gird::SubWidgetUnLink(int32_t colId, int32_t rowId)
|
||||
{
|
||||
if (colId<0 || rowId<0) {
|
||||
EWOL_WARNING("[" << GetId() << "] try to Unlink widget with id < 0 col=" << colId << " row=" << rowId);
|
||||
return;
|
||||
}
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
// try to find it ...
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if( m_subWidget[iii].row == rowId
|
||||
&& m_subWidget[iii].col == colId) {
|
||||
m_subWidget[iii].widget = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
return;
|
||||
}
|
||||
}
|
||||
EWOL_WARNING("[" << GetId() << "] Can not unLink unExistant widget");
|
||||
}
|
||||
|
||||
void widget::Gird::OnDraw(ewol::DrawProperty& displayProp)
|
||||
{
|
||||
// TODO : Only display the Widget inside the view ...
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (NULL != m_subWidget[iii].widget) {
|
||||
m_subWidget[iii].widget->GenDraw(displayProp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void widget::Gird::OnRegenerateDisplay(void)
|
||||
{
|
||||
// TODO : Only display the Widget inside the view ...
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (NULL != m_subWidget[iii].widget) {
|
||||
m_subWidget[iii].widget->OnRegenerateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ewol::Widget * widget::Gird::GetWidgetAtPos(vec2 pos)
|
||||
{
|
||||
if (true == IsHide()) {
|
||||
return NULL;
|
||||
}
|
||||
// for all element in the sizer ...
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (NULL != m_subWidget[iii].widget) {
|
||||
vec2 tmpSize = m_subWidget[iii].widget->GetSize();
|
||||
vec2 tmpOrigin = m_subWidget[iii].widget->GetOrigin();
|
||||
if( (tmpOrigin.x() <= pos.x() && tmpOrigin.x() + tmpSize.x() >= pos.x())
|
||||
&& (tmpOrigin.y() <= pos.y() && tmpOrigin.y() + tmpSize.y() >= pos.y()) )
|
||||
{
|
||||
ewol::Widget * tmpWidget = m_subWidget[iii].widget->GetWidgetAtPos(pos);
|
||||
if (NULL != tmpWidget) {
|
||||
return tmpWidget;
|
||||
}
|
||||
// stop searching
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void widget::Gird::OnObjectRemove(ewol::EObject * removeObject)
|
||||
{
|
||||
// First step call parrent :
|
||||
ewol::Widget::OnObjectRemove(removeObject);
|
||||
// second step find if in all the elements ...
|
||||
for(int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
|
||||
if(m_subWidget[iii].widget == removeObject) {
|
||||
EWOL_VERBOSE("[" << GetId() << "]={" << GetObjectType() << "} Remove sizer sub Element [" << iii << "/" << m_subWidget.Size()-1 << "] ==> destroyed object");
|
||||
m_subWidget[iii].widget = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
}
|
||||
if (m_tmpWidget == removeObject) {
|
||||
m_tmpWidget = NULL;
|
||||
}
|
||||
}
|
128
sources/ewol/widget/Gird.h
Normal file
128
sources/ewol/widget/Gird.h
Normal file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_WIDGET_GIRD_H__
|
||||
#define __EWOL_WIDGET_GIRD_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/widget/Widget.h>
|
||||
|
||||
namespace widget {
|
||||
class Gird :public ewol::Widget
|
||||
{
|
||||
private:
|
||||
class GirdProperties {
|
||||
public:
|
||||
ewol::Widget* widget;
|
||||
int32_t row;
|
||||
int32_t col;
|
||||
};
|
||||
int32_t m_sizeRow; //!< size of all Lines (row) (if set (otherwise 0)) ==> we have a only one size ==> multiple size will have no use ...
|
||||
int32_t m_uniformSizeRow;
|
||||
etk::Vector<int32_t> m_sizeCol; //!< size of all colomn (if set (otherwise 0))
|
||||
etk::Vector<GirdProperties> m_subWidget; //!< all sub widget are contained in this element
|
||||
ewol::Widget* m_tmpWidget; //!< use when replace a widget ...
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Gird(int32_t colNumber=1);
|
||||
/**
|
||||
* @brief Desstructor
|
||||
*/
|
||||
virtual ~Gird(void);
|
||||
/**
|
||||
* @brief Set the number of colomn
|
||||
* @param[in] colNumber Nuber of colomn
|
||||
*/
|
||||
void SetColNumber(int32_t colNumber);
|
||||
/**
|
||||
* @brief Change a size view of a colomn.
|
||||
* @param[in] colId Id of the colomn [0..x].
|
||||
* @param[in] size Size of the colomn.
|
||||
*/
|
||||
void SetColSize(int32_t colId, int32_t size);
|
||||
/**
|
||||
* @brief Change a size view of a Line.
|
||||
* @param[in] size Size of the line.
|
||||
*/
|
||||
void SetRowSize(int32_t size);
|
||||
/**
|
||||
* @brief Get the size view of a colomn.
|
||||
* @param[in] colId Id of the colomn [0..x].
|
||||
* @return The size of the colomn.
|
||||
*/
|
||||
int32_t GetColSize(int32_t colId);
|
||||
/**
|
||||
* @brief Get the size view of the Lines.
|
||||
* @return The size of the lines.
|
||||
*/
|
||||
int32_t GetRowSize(void);
|
||||
public:
|
||||
/**
|
||||
* @brief Remove all sub element from the widget.
|
||||
*/
|
||||
virtual void SubWidgetRemoveAll(void);
|
||||
/**
|
||||
* @brief Add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
|
||||
* @param[in] colId Id of the colomn [0..x].
|
||||
* @param[in] rowId Id of the row [0..y].
|
||||
* @param[in] newWidget the element pointer
|
||||
*/
|
||||
virtual void SubWidgetAdd(int32_t colId, int32_t rowId, ewol::Widget* newWidget);
|
||||
/**
|
||||
* @brief Remove definitly a widget from the system and this Gird.
|
||||
* @param[in] newWidget the element pointer.
|
||||
*/
|
||||
virtual void SubWidgetRemove(ewol::Widget* newWidget);
|
||||
/**
|
||||
* @brief Remove definitly a widget from the system and this Gird.
|
||||
* @param[in] colId Id of the colomn [0..x].
|
||||
* @param[in] rowId Id of the row [0..y].
|
||||
*/
|
||||
virtual void SubWidgetRemove(int32_t colId, int32_t rowId);
|
||||
/**
|
||||
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...).
|
||||
* @param[in] newWidget the element pointer.
|
||||
*/
|
||||
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
|
||||
/**
|
||||
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...).
|
||||
* @param[in] colId Id of the colomn [0..x].
|
||||
* @param[in] rowId Id of the row [0..y].
|
||||
*/
|
||||
virtual void SubWidgetUnLink(int32_t colId, int32_t rowId);
|
||||
private:
|
||||
ivec2 m_borderSize; //!< Border size needed for all the display
|
||||
public:
|
||||
/**
|
||||
* @brief Set the current border size of the current element:
|
||||
* @param[in] newBorderSize The border size to set (0 if not used)
|
||||
*/
|
||||
void SetBorderSize(const ivec2& newBorderSize);
|
||||
/**
|
||||
* @brief Get the current border size of the current element:
|
||||
* @return the border size (0 if not used)
|
||||
*/
|
||||
const ivec2& GetBorderSize(void) { return m_borderSize; };
|
||||
protected: // Derived function
|
||||
virtual void OnDraw(ewol::DrawProperty& displayProp);
|
||||
public: // Derived function
|
||||
virtual void OnRegenerateDisplay(void);
|
||||
virtual ewol::Widget* GetWidgetAtPos(vec2 pos);
|
||||
virtual void OnObjectRemove(ewol::EObject* removeObject);
|
||||
virtual const char * const GetObjectType(void) { return "Ewol::Sizer"; };
|
||||
virtual bool CalculateSize(float availlableX, float availlableY);
|
||||
virtual bool CalculateMinSize(void);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -43,7 +43,7 @@ namespace widget {
|
||||
*/
|
||||
etk::UString GetLabel(void);
|
||||
// Derived function
|
||||
virtual const char * const GetObjectType(void) { return "EwolLabel"; };
|
||||
virtual const char * const GetObjectType(void) { return "Ewol::Label"; };
|
||||
// Derived function
|
||||
virtual bool CalculateMinSize(void);
|
||||
// Derived function
|
||||
|
@ -22,6 +22,7 @@ widget::Layer::Layer(void)
|
||||
|
||||
widget::Layer::~Layer(void)
|
||||
{
|
||||
EWOL_DEBUG("[" << GetId() << "] Layer : destroy");
|
||||
SubWidgetRemoveAll();
|
||||
}
|
||||
|
||||
@ -207,7 +208,7 @@ void widget::Layer::OnObjectRemove(ewol::EObject * removeObject)
|
||||
// second step find if in all the elements ...
|
||||
for(int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
|
||||
if(m_subWidget[iii] == removeObject) {
|
||||
EWOL_DEBUG("Remove sizer sub Element [" << iii << "] ==> destroyed object");
|
||||
EWOL_DEBUG("Remove layer sub Element [" << iii << "] ==> destroyed object");
|
||||
m_subWidget[iii] = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
|
@ -23,24 +23,23 @@ namespace widget {
|
||||
virtual const char * const GetObjectType(void) { return "EwolLayer"; };
|
||||
public:
|
||||
// Derived function
|
||||
virtual bool CalculateSize(float availlableX, float availlableY);
|
||||
// Derived function
|
||||
virtual bool CalculateMinSize(void);
|
||||
virtual void SetMinSise(float x=-1, float y=-1);
|
||||
virtual void SetExpendX(bool newExpend=false);
|
||||
virtual bool CanExpentX(void);
|
||||
virtual void SetExpendY(bool newExpend=false);
|
||||
virtual bool CanExpentY(void);
|
||||
void LockExpendContamination(bool lockExpend=false);
|
||||
virtual bool CalculateSize(float availlableX, float availlableY);
|
||||
virtual bool CalculateMinSize(void);
|
||||
virtual void SetMinSise(float x=-1, float y=-1);
|
||||
virtual void SetExpendX(bool newExpend=false);
|
||||
virtual bool CanExpentX(void);
|
||||
virtual void SetExpendY(bool newExpend=false);
|
||||
virtual bool CanExpentY(void);
|
||||
void LockExpendContamination(bool lockExpend=false);
|
||||
private:
|
||||
bool m_lockExpendContamination;
|
||||
bool m_lockExpendContamination;
|
||||
etk::Vector<ewol::Widget*> m_subWidget;
|
||||
public:
|
||||
virtual void SubWidgetRemoveAll(void);
|
||||
virtual void SubWidgetAdd(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetAddFront(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetRemove(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetRemoveAll(void);
|
||||
virtual void SubWidgetAdd(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetAddFront(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetRemove(ewol::Widget* newWidget);
|
||||
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
|
||||
protected:
|
||||
// Derived function
|
||||
virtual void OnDraw(ewol::DrawProperty& displayProp);
|
||||
|
@ -28,8 +28,8 @@ namespace widget {
|
||||
void SetLabel(etk::UString newLabel);
|
||||
// Drawing capabilities ....
|
||||
private:
|
||||
etk::Vector<ewol::Compositing*> m_listOObject; //!< generic element to display...
|
||||
etk::Vector<ivec2 > m_lineSize;
|
||||
etk::Vector<ewol::Compositing*> m_listOObject; //!< generic element to display...
|
||||
etk::Vector<ivec2 > m_lineSize;
|
||||
public:
|
||||
void AddOObject(ewol::Compositing* newObject, int32_t pos=-1);
|
||||
void ClearOObjectList(void);
|
||||
@ -38,10 +38,10 @@ namespace widget {
|
||||
virtual void OnDraw(ewol::DrawProperty& displayProp);
|
||||
// list properties ...
|
||||
private:
|
||||
int32_t m_paddingSizeX;
|
||||
int32_t m_paddingSizeY;
|
||||
int32_t m_displayStartRaw; //!< Current starting diaplayed raw
|
||||
int32_t m_displayCurrentNbLine; //!< Number of line in the display
|
||||
int32_t m_paddingSizeX;
|
||||
int32_t m_paddingSizeY;
|
||||
int32_t m_displayStartRaw; //!< Current starting diaplayed raw
|
||||
int32_t m_displayCurrentNbLine; //!< Number of line in the display
|
||||
public:
|
||||
// Derived function
|
||||
virtual void OnRegenerateDisplay(void);
|
||||
|
@ -6,6 +6,7 @@
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/widget/Sizer.h>
|
||||
#include <ewol/widget/WidgetManager.h>
|
||||
|
||||
@ -16,20 +17,39 @@
|
||||
|
||||
widget::Sizer::Sizer(widget::Sizer::displayMode_te mode):
|
||||
m_mode(mode),
|
||||
m_lockExpendContamination(false,false)
|
||||
m_lockExpendContamination(false,false),
|
||||
m_borderSize(0,0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
widget::Sizer::~Sizer(void)
|
||||
{
|
||||
EWOL_DEBUG("[" << GetId() << "]={" << GetObjectType() << "} Sizer : destroy (mode=" << (m_mode==widget::Sizer::modeVert?"Vert":"Hori") << ")");
|
||||
SubWidgetRemoveAll();
|
||||
}
|
||||
|
||||
|
||||
void widget::Sizer::SetBorderSize(const ivec2& newBorderSize)
|
||||
{
|
||||
m_borderSize = newBorderSize;
|
||||
if (m_borderSize.x() < 0) {
|
||||
EWOL_ERROR("Try to set a border size <0 on x : " << m_borderSize.x() << " ==> restore to 0");
|
||||
m_borderSize.setX(0);
|
||||
}
|
||||
if (m_borderSize.y() < 0) {
|
||||
EWOL_ERROR("Try to set a border size <0 on y : " << m_borderSize.y() << " ==> restore to 0");
|
||||
m_borderSize.setY(0);
|
||||
}
|
||||
MarkToRedraw();
|
||||
ewol::RequestUpdateSize();
|
||||
}
|
||||
|
||||
void widget::Sizer::SetMode(widget::Sizer::displayMode_te mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
MarkToRedraw();
|
||||
ewol::RequestUpdateSize();
|
||||
}
|
||||
|
||||
widget::Sizer::displayMode_te widget::Sizer::GetMode(void)
|
||||
@ -41,6 +61,7 @@ bool widget::Sizer::CalculateSize(float availlableX, float availlableY)
|
||||
{
|
||||
//EWOL_DEBUG("Update Size");
|
||||
m_size.setValue(availlableX, availlableY);
|
||||
m_size -= m_borderSize*2;
|
||||
// calculate unExpendable Size :
|
||||
float unexpendableSize=0.0;
|
||||
int32_t nbWidgetFixedSize=0;
|
||||
@ -78,7 +99,7 @@ bool widget::Sizer::CalculateSize(float availlableX, float availlableY)
|
||||
sizeToAddAtEveryOne=0;
|
||||
}
|
||||
}
|
||||
vec2 tmpOrigin = m_origin;
|
||||
vec2 tmpOrigin = m_origin + m_borderSize;
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (NULL != m_subWidget[iii]) {
|
||||
vec2 tmpSize = m_subWidget[iii]->GetMinSize();
|
||||
@ -105,6 +126,7 @@ bool widget::Sizer::CalculateSize(float availlableX, float availlableY)
|
||||
}
|
||||
}
|
||||
}
|
||||
m_size += m_borderSize*2;
|
||||
MarkToRedraw();
|
||||
return true;
|
||||
}
|
||||
@ -115,6 +137,13 @@ bool widget::Sizer::CalculateMinSize(void)
|
||||
//EWOL_DEBUG("Update minimum Size");
|
||||
m_userExpend.setValue(false, false);
|
||||
m_minSize.setValue(0,0);
|
||||
if (m_userMinSize.x()>0) {
|
||||
m_minSize.setX(m_userMinSize.x());
|
||||
}
|
||||
if (m_userMinSize.y()>0) {
|
||||
m_minSize.setY(m_userMinSize.y());
|
||||
}
|
||||
m_minSize += m_borderSize*2;
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (NULL != m_subWidget[iii]) {
|
||||
m_subWidget[iii]->CalculateMinSize();
|
||||
@ -146,12 +175,12 @@ bool widget::Sizer::CalculateMinSize(void)
|
||||
|
||||
void widget::Sizer::SetMinSize(float x, float y)
|
||||
{
|
||||
EWOL_ERROR("Sizer can not have a user Minimum size (herited from under elements)");
|
||||
EWOL_ERROR("[" << GetId() << "] Sizer can not have a user Minimum size (herited from under elements)");
|
||||
}
|
||||
|
||||
void widget::Sizer::SetExpendX(bool newExpend)
|
||||
{
|
||||
EWOL_ERROR("Sizer can not have a user expend settings X (herited from under elements)");
|
||||
EWOL_ERROR("[" << GetId() << "] Sizer can not have a user expend settings X (herited from under elements)");
|
||||
}
|
||||
|
||||
bool widget::Sizer::CanExpentX(void)
|
||||
@ -164,7 +193,7 @@ bool widget::Sizer::CanExpentX(void)
|
||||
|
||||
void widget::Sizer::SetExpendY(bool newExpend)
|
||||
{
|
||||
EWOL_ERROR("Sizer can not have a user expend settings Y (herited from under elements)");
|
||||
EWOL_ERROR("[" << GetId() << "] Sizer can not have a user expend settings Y (herited from under elements)");
|
||||
}
|
||||
|
||||
bool widget::Sizer::CanExpentY(void)
|
||||
@ -190,12 +219,21 @@ void widget::Sizer::LockExpendContaminationHori(bool lockExpend)
|
||||
|
||||
void widget::Sizer::SubWidgetRemoveAll(void)
|
||||
{
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
// the size automaticly decrement with the auto call of the OnObjectRemove function
|
||||
while (m_subWidget.Size() > 0 ) {
|
||||
if (NULL != m_subWidget[0]) {
|
||||
delete(m_subWidget[0]);
|
||||
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
|
||||
if (errorControl == m_subWidget.Size()) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
|
||||
m_subWidget[0] = NULL;
|
||||
}
|
||||
} else {
|
||||
EWOL_WARNING("[" << GetId() << "] Must not have null pointer on the subWidget list ...");
|
||||
m_subWidget.Erase(0);
|
||||
}
|
||||
errorControl = m_subWidget.Size();
|
||||
}
|
||||
m_subWidget.Clear();
|
||||
}
|
||||
@ -223,11 +261,16 @@ void widget::Sizer::SubWidgetRemove(ewol::Widget* newWidget)
|
||||
if (NULL == newWidget) {
|
||||
return;
|
||||
}
|
||||
int32_t errorControl = m_subWidget.Size();
|
||||
for (int32_t iii=0; iii<m_subWidget.Size(); iii++) {
|
||||
if (newWidget == m_subWidget[iii]) {
|
||||
delete(m_subWidget[iii]);
|
||||
m_subWidget[iii] = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
// no remove, this element is removed with the function OnObjectRemove ==> it does not exist anymore ...
|
||||
if (errorControl == m_subWidget.Size()) {
|
||||
EWOL_CRITICAL("[" << GetId() << "] The number of element might have been reduced ... ==> it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
|
||||
m_subWidget[iii] = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -304,7 +347,7 @@ void widget::Sizer::OnObjectRemove(ewol::EObject * removeObject)
|
||||
// second step find if in all the elements ...
|
||||
for(int32_t iii=m_subWidget.Size()-1; iii>=0; iii--) {
|
||||
if(m_subWidget[iii] == removeObject) {
|
||||
EWOL_VERBOSE("Remove sizer sub Element [" << iii << "/" << m_subWidget.Size()-1 << "] ==> destroyed object");
|
||||
EWOL_VERBOSE("[" << GetId() << "]={" << GetObjectType() << "} Remove sizer sub Element [" << iii << "/" << m_subWidget.Size()-1 << "] ==> destroyed object");
|
||||
m_subWidget[iii] = NULL;
|
||||
m_subWidget.Erase(iii);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ namespace widget {
|
||||
{
|
||||
public:
|
||||
typedef enum {
|
||||
modeVert,
|
||||
modeHori,
|
||||
modeVert, //!< Vertical mode
|
||||
modeHori, //!< Horizontal mode
|
||||
} displayMode_te;
|
||||
private:
|
||||
etk::Vector<ewol::Widget*> m_subWidget; //!< all sub widget are contained in this element
|
||||
@ -45,7 +45,7 @@ namespace widget {
|
||||
*/
|
||||
displayMode_te GetMode(void);
|
||||
private:
|
||||
etk::Vector2D<bool> m_lockExpendContamination; //!< If some sub-widget request the expend==> this permit to unpropagate the problem
|
||||
bvec2 m_lockExpendContamination; //!< If some sub-widget request the expend==> this permit to unpropagate the problem
|
||||
public:
|
||||
/**
|
||||
* @brief Change state of the expend contatmination (if some sub-widget request the expent this permit to not propagate if at this widget)
|
||||
@ -87,31 +87,32 @@ namespace widget {
|
||||
* @param[in] newWidget the element pointer.
|
||||
*/
|
||||
virtual void SubWidgetUnLink(ewol::Widget* newWidget);
|
||||
protected:
|
||||
// Derived function
|
||||
virtual void OnDraw(ewol::DrawProperty& displayProp);
|
||||
private:
|
||||
ivec2 m_borderSize; //!< Border size needed for all the display
|
||||
public:
|
||||
// Derived function
|
||||
/**
|
||||
* @brief Set the current border size of the current element:
|
||||
* @param[in] newBorderSize The border size to set (0 if not used)
|
||||
*/
|
||||
void SetBorderSize(const ivec2& newBorderSize);
|
||||
/**
|
||||
* @brief Get the current border size of the current element:
|
||||
* @return the border size (0 if not used)
|
||||
*/
|
||||
const ivec2& GetBorderSize(void) { return m_borderSize; };
|
||||
protected: // Derived function
|
||||
virtual void OnDraw(ewol::DrawProperty& displayProp);
|
||||
public: // Derived function
|
||||
virtual void OnRegenerateDisplay(void);
|
||||
// Derived function
|
||||
virtual ewol::Widget* GetWidgetAtPos(vec2 pos);
|
||||
// Derived function
|
||||
virtual void OnObjectRemove(ewol::EObject* removeObject);
|
||||
// Derived function
|
||||
virtual const char * const GetObjectType(void) { return "EwolSizerVert"; };
|
||||
// Derived function
|
||||
virtual const char * const GetObjectType(void) { return "Ewol::Sizer"; };
|
||||
virtual bool CalculateSize(float availlableX, float availlableY);
|
||||
// Derived function
|
||||
virtual bool CalculateMinSize(void);
|
||||
// Derived function
|
||||
virtual void SetMinSize(float x=-1, float y=-1);
|
||||
// Derived function
|
||||
virtual void SetExpendX(bool newExpend=false);
|
||||
// Derived function
|
||||
virtual bool CanExpentX(void);
|
||||
// Derived function
|
||||
virtual void SetExpendY(bool newExpend=false);
|
||||
// Derived function
|
||||
virtual bool CanExpentY(void);
|
||||
};
|
||||
|
||||
|
@ -58,6 +58,7 @@ FILE_LIST+= ewol/widget/Widget.cpp \
|
||||
ewol/widget/WidgetManager.cpp \
|
||||
ewol/widget/Windows.cpp \
|
||||
ewol/widget/Button.cpp \
|
||||
ewol/widget/Gird.cpp \
|
||||
ewol/widget/Image.cpp \
|
||||
ewol/widget/ButtonColor.cpp \
|
||||
ewol/widget/CheckBox.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user