From 5d53bed86b145f726fe76c32f35dbd210fbbb21b Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 17 Aug 2018 21:52:33 +0200 Subject: [PATCH] [DEV] list start to be correct --- ewol/widget/List.cpp | 256 +++++++++++++++++++-------------- ewol/widget/List.hpp | 49 +++++-- ewol/widget/ListFileSystem.cpp | 30 ++-- ewol/widget/ListFileSystem.hpp | 5 +- 4 files changed, 201 insertions(+), 139 deletions(-) diff --git a/ewol/widget/List.cpp b/ewol/widget/List.cpp index 0a3b437c..81612c82 100644 --- a/ewol/widget/List.cpp +++ b/ewol/widget/List.cpp @@ -50,8 +50,9 @@ void ewol::widget::List::setRawVisible(int32_t _id) { m_displayStartRaw = _id - m_nbVisibleRaw + 2; } } - if (m_displayStartRaw > (int32_t)getNuberOfRaw()) { - m_displayStartRaw = getNuberOfRaw()-2; + ivec2 matrixSize = getMatrixSize(); + if (m_displayStartRaw > matrixSize.y()) { + m_displayStartRaw = matrixSize.y()-2; } if (m_displayStartRaw<0) { m_displayStartRaw = 0; @@ -104,129 +105,168 @@ void ewol::widget::List::onRegenerateDisplay() { if (needRedraw() == true) { // clean the object list ... clearOObjectList(); - //EWOL_DEBUG("OnRegenerateDisplay(" << m_size.x << "," << m_size.y << ")"); - int32_t tmpOriginX = 0; - int32_t tmpOriginY = 0; - /* - if (true == m_userFill.x) { - tmpOriginX = 0; + // ------------------------------------------------------- + // -- Calculate the size of each element + // ------------------------------------------------------- + ivec2 matrixSize = getMatrixSize(); + m_listSizeX.clear(); + m_listSizeX.resize(matrixSize.x(), 0); + m_listSizeY.clear(); + m_listSizeY.resize(matrixSize.y(), 0); + for (int_t yyy=0; yyy m_listSizeX[xxx]) { + m_listSizeX[xxx] = elementSize.x(); + } + if (elementSize.y() > m_listSizeY[yyy]) { + m_listSizeY[yyy] = elementSize.y(); + } + } } - if (true == m_userFill.y) { - tmpOriginY = 0; - }*/ - tmpOriginX += m_paddingSizeX; - tmpOriginY += m_paddingSizeY; - // TODO : remove this ... - int32_t minHeight = 25; - uint32_t nbColomn = getNuberOfColomn(); - int32_t nbRaw = getNuberOfRaw(); - // For the scrooling windows - m_maxSize = ivec2(m_size.x(), - (minHeight + 2*m_paddingSizeY) * nbRaw ); - - - etk::Vector listSizeColomn; - - ewol::compositing::Drawing * BGOObjects = ETK_NEW(ewol::compositing::Drawing); + // ------------------------------------------------------- + // -- Calculate the start position size of each element + // ------------------------------------------------------- + etk::Vector listStartPosX; + etk::Vector listStartPosY; + int32_t lastPositionX = 0; + for (auto &size: m_listSizeX) { + listStartPosX.pushBack(lastPositionX); + lastPositionX += size; + } + int32_t lastPositionY = 0; + for (auto &size: m_listSizeY) { + lastPositionY += size; + listStartPosY.pushBack(lastPositionY); + } + // ------------------------------------------------------- + // -- Update the scroolBar + // ------------------------------------------------------- + m_maxSize = ivec2(lastPositionX, lastPositionY); + // ------------------------------------------------------- + // -- Clean the background + // ------------------------------------------------------- + drawBackground(); + // ------------------------------------------------------- + // -- Draw each element + // ------------------------------------------------------- + for (int_t yyy=0; yyy element out of range ==> nothing to display + continue; + } + if (startYposition > m_size.y()) { + // ==> element out of range ==> nothing to display + break; + } + */ + for (int_t xxx=0; xxx element out of range ==> nothing to display + continue; + } + if (startYposition > m_size.x()) { + // ==> element out of range ==> nothing to display + break; + } + */ + drawElement(ivec2(xxx, yyy), + vec2(m_paddingSizeX + listStartPosX[xxx], startYposition), + vec2(m_listSizeX[xxx], m_listSizeY[yyy])); + } + } + // ------------------------------------------------------- + // -- Draw Scrooling widget + // ------------------------------------------------------- + WidgetScrolled::onRegenerateDisplay(); + } +} + +ivec2 ewol::widget::List::getMatrixSize() const { + return ivec2(1,0); +} + +vec2 ewol::widget::List::calculateElementSize(const ivec2& _pos) { + ewol::compositing::Text tmpText; + etk::String myTextToWrite = getData(ListRole::Text, _pos).getSafeString(); + vec3 textSize = tmpText.calculateSize(myTextToWrite); + ivec2 count = getMatrixSize(); + return vec2(textSize.x(), + textSize.y() + m_paddingSizeY*3 + ); +} + +void ewol::widget::List::drawBackground() { + ewol::compositing::Drawing * BGOObjects = ETK_NEW(ewol::compositing::Drawing); + if (BGOObjects != null) { + addOObject(BGOObjects); etk::Color<> basicBG = getBasicBG(); BGOObjects->setColor(basicBG); BGOObjects->setPos(vec3(0, 0, 0) ); - BGOObjects->rectangleWidth(vec3(m_size.x(), m_size.y(), 0) ); - - int32_t startRaw = m_originScrooled.y() / (minHeight + 2*m_paddingSizeY); - - if (startRaw >= nbRaw-1 ) { - startRaw = nbRaw - 1; + BGOObjects->rectangleWidth(m_size); + } +} + +void ewol::widget::List::drawElement(const ivec2& _pos, const vec2& _start, const vec2& _size) { + etk::String myTextToWrite = getData(ListRole::Text, _pos).getSafeString(); + etk::Color<> fg = getData(ListRole::FgColor, _pos).getSafeColor(); + etk::Color<> bg = getData(ListRole::BgColor, _pos).getSafeColor(); + + ewol::compositing::Drawing * BGOObjects = ETK_NEW(ewol::compositing::Drawing); + if (BGOObjects != null) { + addOObject(BGOObjects); + BGOObjects->setColor(bg); + BGOObjects->setPos(vec3(_start.x(), _start.y(), 0) ); + BGOObjects->rectangleWidth(_size); + } + if (myTextToWrite != "") { + ewol::compositing::Text * tmpText = ETK_NEW(ewol::compositing::Text); + if (tmpText != null) { + addOObject(tmpText); + int32_t displayPositionY = _start.y() + m_paddingSizeY; + tmpText->setColor(fg); + tmpText->setPos(vec3(_start.x() + m_paddingSizeX, displayPositionY, 0) ); + tmpText->print(myTextToWrite);; } - if (startRaw<0) { - startRaw = 0; - } - // We display only compleate lines ... - //EWOL_DEBUG("Request drawing list : " << startRaw << "-->" << (startRaw+displayableRaw) << " in " << nbRaw << "raws ; start display : " << m_originScrooled.y << " == > " << tmpOriginY << " line size=" << minHeight + 2*m_paddingSizeY ); - - /*clipping_ts drawClipping; - drawClipping.x = 0; - drawClipping.y = 0; - drawClipping.w = m_size.x - (2*m_paddingSizeX); - drawClipping.h = m_size.y; - */ - // remove all the positions : - m_lineSize.clear(); - int32_t displayPositionY = m_size.y(); - int32_t displayPositionX = 0; - ivec2 tmpRegister(startRaw, displayPositionY); - // add the default position raw : - m_lineSize.pushBack(tmpRegister); - - for (size_t jjj=0; jjj= 0; iii++) { - m_nbVisibleRaw++; - ivec2 position(jjj, iii); - etk::String myTextToWrite = getData(ListRole::Text, position).getSafeString(); - etk::Color<> fg = getData(ListRole::FgColor, position).getSafeColor(); - etk::Color<> bg = getData(ListRole::BgColor, position).getSafeColor(); - - ewol::compositing::Text * tmpText = ETK_NEW(ewol::compositing::Text); - if (null != tmpText) { - // get font size : - int32_t tmpFontHeight = tmpText->calculateSize(char32_t('A')).y(); - displayPositionY-=(tmpFontHeight+m_paddingSizeY); - - BGOObjects->setColor(bg); - BGOObjects->setPos(vec3(displayPositionX, displayPositionY, 0) ); - BGOObjects->rectangleWidth(vec3(m_size.x()-displayPositionX, tmpFontHeight+2*m_paddingSizeY, 0)); - - // get the maximum size of the colomn : - vec3 textSize = tmpText->calculateSize(myTextToWrite); - sizeColom = etk::max(sizeColom, (int32_t)textSize.x()); - - tmpText->setColor(fg); - tmpText->setPos(vec3(tmpOriginX + displayPositionX, displayPositionY, 0) ); - tmpText->print(myTextToWrite); - addOObject(tmpText); - // madding move ... - displayPositionY -= m_paddingSizeY; - - // add the raw position to remember it ... - tmpRegister.setX(tmpRegister.x()+1); - tmpRegister.setY(displayPositionY); - m_lineSize.pushBack(tmpRegister); - //EWOL_DEBUG("List indexation:" << tmpRegister); - } - } - displayPositionX += sizeColom; - tmpOriginX += m_paddingSizeX*2*2; - } - //m_lineSize.pushBack(tmpOriginY); - addOObject(BGOObjects, 0); - - // call the herited class... - WidgetScrolled::onRegenerateDisplay(); } } bool ewol::widget::List::onEventInput(const ewol::event::Input& _event) { vec2 relativePos = relativePosition(_event.getPos()); - - if (true == WidgetScrolled::onEventInput(_event)) { + if (WidgetScrolled::onEventInput(_event) == true) { keepFocus(); // nothing to do ... done on upper widet ... return true; } - // parse all the loged row position to find the good one... - int32_t rawID = -1; - for (size_t iii=0; iii= m_lineSize[iii+1].y() ) { - // we find the raw : - rawID = m_lineSize[iii].x(); + relativePos = vec2(relativePos.x(),m_size.y() - relativePos.y()) + m_originScrooled; + // Find the colomn and the row + ivec2 pos{-1,-1}; + int32_t offset = 0; + for (size_t iii=0; iii= previous ) { + pos.setY(iii); break; } } - bool isUsed = onItemEvent(_event.getId(), _event.getStatus(), ivec2(0, rawID), _event.getPos()); + offset = 0; + for (size_t iii=0; iii= previous ) { + pos.setX(iii); + break; + } + } + bool isUsed = onItemEvent(_event.getId(), _event.getStatus(), pos, _event.getPos()); if (isUsed == true) { // TODO : this generate bugs ... I did not understand why .. //ewol::WidgetSharedManager::focusKeep(this); diff --git a/ewol/widget/List.hpp b/ewol/widget/List.hpp index ed77c530..c518f3ba 100644 --- a/ewol/widget/List.hpp +++ b/ewol/widget/List.hpp @@ -19,9 +19,15 @@ namespace ewol { using ListWeak = ememory::WeakPtr; enum ListRole { - Text = 11234, - BgColor, - FgColor, + Text = 11234, // string + IsSelected, // bool + IsExpand, // bool + Icon, // string + ChildCount, // uint_t + HaveChild, // bool + ParentId, // uint_t + BgColor, // color + FgColor, // color // Every other role must be set here: EndOfEwolRole }; @@ -39,7 +45,8 @@ namespace ewol { // drawing capabilities .... private: etk::Vector m_listOObject; //!< generic element to display... - etk::Vector m_lineSize; + etk::Vector m_listSizeX; //!< size of every colomns + etk::Vector m_listSizeY; //!< size of every rows public: void addOObject(ewol::Compositing* _newObject, int32_t _pos=-1); void clearOObjectList(); @@ -55,16 +62,17 @@ namespace ewol { virtual etk::Color<> getBasicBG() { return etk::Color<>(0xFF, 0xFF, 0xFF, 0xFF); } - virtual uint32_t getNuberOfColomn() { - return 1; - }; + virtual bool getTitle(int32_t _colomn, etk::String& _myTitle, etk::Color<> &_fg, etk::Color<> &_bg) { _myTitle = ""; return false; }; - virtual uint32_t getNuberOfRaw() { - return 0; - }; + /** + * @brief Get the number of colomn and row availlable in the list + * @return Number of colomn and row + */ + virtual ivec2 getMatrixSize() const; + virtual fluorine::Variant getData(int32_t _role, const ivec2& _pos) { switch (_role) { case ListRole::Text: @@ -79,6 +87,27 @@ namespace ewol { } return fluorine::Variant(); }; + /** + * @brief Calculate an element size to extimate the render size. + * @note Does not generate the with the same size. + * @param[in] _pos Position of colomn and Raw of the element. + * @return The estimate size of the element. + */ + virtual vec2 calculateElementSize(const ivec2& _pos); + /** + * @brief Draw an element in the specific size and position. + * @param[in] _pos Position of colomn and Raw of the element. + * @param[in] _start Start display position. + * @param[in] _size Render raw size + * @return The estimate size of the element. + */ + virtual void drawElement(const ivec2& _pos, const vec2& _start, const vec2& _size); + + /** + * @brief Draw the background + */ + virtual void drawBackground(); + virtual bool onItemEvent(int32_t _IdInput, enum gale::key::status _typeEvent, const ivec2& _pos, const vec2& _mousePosition) { return false; } diff --git a/ewol/widget/ListFileSystem.cpp b/ewol/widget/ListFileSystem.cpp index 35910e45..336d20a1 100644 --- a/ewol/widget/ListFileSystem.cpp +++ b/ewol/widget/ListFileSystem.cpp @@ -112,16 +112,7 @@ void ewol::widget::ListFileSystem::setSelect(const etk::String& _data) { markToRedraw(); } -uint32_t ewol::widget::ListFileSystem::getNuberOfColomn() { - return 1; -} - -bool ewol::widget::ListFileSystem::getTitle(int32_t _colomn, etk::String &_myTitle, etk::Color<>& _fg, etk::Color<>& _bg) { - _myTitle = "title"; - return true; -} - -uint32_t ewol::widget::ListFileSystem::getNuberOfRaw() { +ivec2 ewol::widget::ListFileSystem::getMatrixSize() const { int32_t offset = 0; if (*propertyShowFolder == true) { if (propertyPath.get() == "/") { @@ -130,7 +121,12 @@ uint32_t ewol::widget::ListFileSystem::getNuberOfRaw() { offset = 2; } } - return m_list.size() + offset; + return ivec2(1, m_list.size() + offset); +} + +bool ewol::widget::ListFileSystem::getTitle(int32_t _colomn, etk::String &_myTitle, etk::Color<>& _fg, etk::Color<>& _bg) { + _myTitle = "title"; + return true; } fluorine::Variant ewol::widget::ListFileSystem::getData(int32_t _role, const ivec2& _pos) { @@ -175,10 +171,8 @@ fluorine::Variant ewol::widget::ListFileSystem::getData(int32_t _role, const ive bool ewol::widget::ListFileSystem::onItemEvent(int32_t _IdInput, enum gale::key::status _typeEvent, - int32_t _colomn, - int32_t _raw, - float _x, - float _y) { + const ivec2& _pos, + const vec2& _mousePosition) { int32_t offset = 0; if (*propertyShowFolder == true) { if (*propertyPath == "/") { @@ -188,13 +182,13 @@ bool ewol::widget::ListFileSystem::onItemEvent(int32_t _IdInput, } } if (_typeEvent == gale::key::status::pressSingle) { - EWOL_VERBOSE("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw ); + EWOL_VERBOSE("Event on List : IdInput=" << _IdInput << " _pos=" << _pos ); if (1 == _IdInput) { int32_t previousRaw = m_selectedLine; - if (_raw > (int32_t)m_list.size()+offset ) { + if (_pos.y() > (int32_t)m_list.size()+offset ) { m_selectedLine = -1; } else { - m_selectedLine = _raw; + m_selectedLine = _pos.y(); } if (previousRaw != m_selectedLine) { if( *propertyShowFolder == true diff --git a/ewol/widget/ListFileSystem.hpp b/ewol/widget/ListFileSystem.hpp index 4043db18..26054e23 100644 --- a/ewol/widget/ListFileSystem.hpp +++ b/ewol/widget/ListFileSystem.hpp @@ -44,11 +44,10 @@ namespace ewol { int32_t m_colorIdBackgroundSelected; //!< Color of line selected. protected: etk::Color<> getBasicBG() override; - uint32_t getNuberOfColomn() override; bool getTitle(int32_t _colomn, etk::String& _myTitle, etk::Color<>& _fg, etk::Color<>& _bg) override; - uint32_t getNuberOfRaw() override; + ivec2 getMatrixSize() const override; fluorine::Variant getData(int32_t _role, const ivec2& _pos) override; - bool onItemEvent(int32_t _IdInput, enum gale::key::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y) override; + bool onItemEvent(int32_t _IdInput, enum gale::key::status _typeEvent, const ivec2& _pos, const vec2& _mousePosition) override; protected: // TODO: use shred_ptr etk::Vector m_list; //!< List of all element in the path. (they are filtered)