[DEV] update the GUI

This commit is contained in:
2018-10-09 21:31:47 +02:00
parent a044d64f02
commit 05a4627a23
15 changed files with 211 additions and 103 deletions

View File

@@ -11,23 +11,6 @@
#include <appl/Gui/MainWindows.hpp>
#include <ewol/object/Object.hpp>
// TODO : write it better
static void SortElementList(etk::Vector<appl::dataBufferStruct>& _list) {
etk::Vector<appl::dataBufferStruct> tmpList = _list;
_list.clear();
for(size_t iii=0; iii<tmpList.size(); iii++) {
size_t findPos = 0;
for(size_t jjj=0; jjj<_list.size(); jjj++) {
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (tmpList[iii].m_bufferName.getFileName() > _list[jjj].m_bufferName.getFileName()) {
findPos = jjj+1;
}
}
//EWOL_DEBUG("position="<<findPos);
_list.insert(_list.begin()+findPos, tmpList[iii]);
}
}
appl::widget::BufferList::BufferList() :
m_openOrderMode(false) {
addObjectType("appl::BufferList");
@@ -36,7 +19,7 @@ appl::widget::BufferList::BufferList() :
// load buffer manager:
m_bufferManager = appl::BufferManager::create();
// load color properties
m_paintingProperties = appl::GlyphPainting::create("THEME:COLOR:bufferList.json");
m_paintingProperties = appl::GlyphPainting::create("THEME_COLOR:///bufferList.json");
// get all id properties ...
m_colorBackground1 = m_paintingProperties->request("backgroung1");
m_colorBackground2 = m_paintingProperties->request("backgroung2");
@@ -47,7 +30,7 @@ appl::widget::BufferList::BufferList() :
void appl::widget::BufferList::init() {
ewol::widget::List::init();
propertyHide.set(true);
//propertyHide.set(true);
propertyCanFocus.set(true);
if (m_bufferManager != null) {
m_bufferManager->signalNewBuffer.connect(sharedFromThis(), &appl::widget::BufferList::onCallbackNewBuffer);
@@ -106,6 +89,7 @@ void appl::widget::BufferList::onCallbackNewBuffer(const ememory::SharedPtr<appl
} else {
insertAlphabetic(tmp);
}
/*
if (m_list.size() <= 1) {
propertyHide.set(true);
propertySetOnWidgetNamed("appl-Buffer-viewer-separator", "hide", "true");
@@ -113,6 +97,7 @@ void appl::widget::BufferList::onCallbackNewBuffer(const ememory::SharedPtr<appl
propertyHide.set(false);
propertySetOnWidgetNamed("appl-Buffer-viewer-separator", "hide", "false");
}
*/
markToRedraw();
}
@@ -159,11 +144,13 @@ void appl::widget::BufferList::onCallbackBufferRemoved(const ememory::SharedPtr<
++it;
}
}
/*
if (m_list.size() <= 1) {
propertyHide.set(true);
} else {
propertyHide.set(false);
}
*/
markToRedraw();
}
void appl::widget::BufferList::onCallbackIsSave() {

View File

@@ -10,25 +10,14 @@
//#include <ColorizeManager.hpp>
#include <appl/Gui/MainWindows.hpp>
#include <ewol/object/Object.hpp>
// TODO : write it better
static void SortElementList(etk::Vector<appl::dataBufferStruct>& _list) {
etk::Vector<appl::dataBufferStruct> tmpList = _list;
_list.clear();
for(size_t iii=0; iii<tmpList.size(); iii++) {
size_t findPos = 0;
for(size_t jjj=0; jjj<_list.size(); jjj++) {
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (tmpList[iii].m_bufferName.getFileName() > _list[jjj].m_bufferName.getFileName()) {
findPos = jjj+1;
}
}
//EWOL_DEBUG("position="<<findPos);
_list.insert(_list.begin()+findPos, tmpList[iii]);
}
}
#include <ewol/compositing/Image.hpp>
#include <etk/algorithm.hpp>
appl::widget::BufferTree::BufferTree() :
propertyShowUnNeeded(this, "show-un-needed",
false,
"show element that is not open",
&appl::widget::BufferTree::onChangePropertyShowUnNeeded),
m_openOrderMode(false) {
addObjectType("appl::BufferTree");
m_selectedID = -1;
@@ -36,7 +25,7 @@ appl::widget::BufferTree::BufferTree() :
// load buffer manager:
m_bufferManager = appl::BufferManager::create();
// load color properties
m_paintingProperties = appl::GlyphPainting::create("THEME:COLOR:bufferList.json");
m_paintingProperties = appl::GlyphPainting::create("THEME_COLOR:///bufferList.json");
// get all id properties ...
m_colorBackground1 = m_paintingProperties->request("backgroung1");
m_colorBackground2 = m_paintingProperties->request("backgroung2");
@@ -57,6 +46,9 @@ void appl::widget::BufferTree::init() {
m_bufferManager->signalSelectFile.connect(sharedFromThis(), &appl::widget::BufferTree::onSelectBuffer);
m_bufferManager->signalRemoveBuffer.connect(sharedFromThis(), &appl::widget::BufferTree::onRemoveBuffer);
}
addComposeElemnent("image_folder", ememory::makeShared<ewol::compositing::Image>("THEME_GUI:///Folder.svg?lib=ewol"));
addComposeElemnent("image_file", ememory::makeShared<ewol::compositing::Image>("THEME_GUI:///File.svg?lib=ewol"));
}
static etk::String getCommonPathPart(const etk::Path& _left, const etk::Path& _right) {
@@ -68,6 +60,10 @@ static etk::String getCommonPathPart(const etk::Path& _left, const etk::Path& _r
}
break;
}
size_t pos = out.rfind('/');
if (pos != etk::String::npos) {
out = out.extract(0, pos);
}
return out;
}
@@ -83,6 +79,10 @@ void appl::widget::BufferTree::generateFlatTree() {
updateFlatTree();
}
static bool localSort(const etk::Path& _left, const etk::Path& _right) {
return _left.getString().toUpper() <= _right.getString().toUpper();
}
void appl::widget::BufferTree::populateNodeIfNeeded(ememory::SharedPtr<etk::TreeNode<appl::TreeElement>> _node) {
if (_node == null) {
return;
@@ -96,7 +96,8 @@ void appl::widget::BufferTree::populateNodeIfNeeded(ememory::SharedPtr<etk::Tree
// already populated...
return;
}
etk::Vector<etk::Path> child = etk::path::list(value.m_path);
etk::Vector<etk::Path> child = etk::path::list(value.m_path, etk::path::LIST_FOLDER|etk::path::LIST_FILE);
etk::algorithm::quickSort(child, localSort);
APPL_ERROR(" nbChilds: " << child.size() << " for path: " << value.m_path);
for (auto& it: child) {
APPL_ERROR("add element: " << it);
@@ -114,6 +115,10 @@ void appl::widget::BufferTree::goUpper() {
}
// generate new futur root node ...
etk::Path path = m_tree->getData().m_path.getParent();
if (path == m_tree->getData().m_path) {
APPL_ERROR("No more parent in upper ... '" << path << "'");
return;
}
auto treeElement = etk::TreeNode<appl::TreeElement>::create(TreeElement(path, true));
// Add all sub-items
populateNodeIfNeeded(treeElement);
@@ -121,6 +126,7 @@ void appl::widget::BufferTree::goUpper() {
for (auto& it: treeElement->getChilds()) {
if (it->getData().m_nodeName == m_tree->getData().m_nodeName) {
it = m_tree;
it->setParent(treeElement);
break;
}
}
@@ -130,18 +136,76 @@ void appl::widget::BufferTree::goUpper() {
updateFlatTree();
}
bool appl::widget::BufferTree::updateChildOpen(ememory::SharedPtr<etk::TreeNode<appl::TreeElement>> _node) {
if (_node == null) {
return false;
}
appl::TreeElement& value = _node->getData();
if (value.m_isFolder == false) {
// nothing to reset...
return value.m_buffer != null;
}
value.m_haveChildOpen = false;
for (auto& it: _node->getChilds()) {
if (updateChildOpen(it) == true) {
value.m_haveChildOpen = true;
}
}
return value.m_haveChildOpen;
}
void appl::widget::BufferTree::updateFlatTree() {
m_flatTree.setRoot(m_tree,
[&](const TreeElement& _value){
return true;
},
[&](const TreeElement& _value){
return _value.m_isExpand;
});
// Enable parent with child open:
updateChildOpen(m_tree);
// flat tree element enable
if (propertyShowUnNeeded.get() == false) {
m_flatTree.setRoot(m_tree,
[&](const TreeElement& _value){
if ( _value.m_isFolder == true
&& _value.m_haveChildOpen == true) {
return true;
}
if ( _value.m_buffer != null) {
return true;
}
return false;
},
[&](const TreeElement& _value){
return _value.m_isExpand;
});
} else {
m_flatTree.setRoot(m_tree,
[&](const TreeElement& _value){
return true;
},
[&](const TreeElement& _value){
return _value.m_isExpand;
});
}
markToRedraw();
}
void appl::widget::BufferTree::expandToPath(ememory::SharedPtr<etk::TreeNode<appl::TreeElement>> _node, const etk::Path& _path) {
if (_node == null) {
return;
}
appl::TreeElement& value = _node->getData();
if (value.m_isFolder == false) {
return;
}
if (_path.getString().startWith(value.m_path.getString() + "/") == false) {
return;
}
// force expand
value.m_isExpand = true;
populateNodeIfNeeded(_node);
for (auto& it: _node->getChilds()) {
expandToPath(it, _path);
}
}
appl::widget::BufferTree::~BufferTree() {
removeAllElement();
@@ -191,15 +255,17 @@ etk::Path appl::widget::BufferTree::getRootPath() {
}
void appl::widget::BufferTree::onNewBuffer(const ememory::SharedPtr<appl::Buffer>& _buffer) {
APPL_ERROR("New Buffer open: '" << _buffer->getFileName() << "'");
APPL_INFO("New Buffer open: '" << _buffer->getFileName() << "'");
if (m_tree == null) {
generateFlatTree();
} else {
etk::Path rootPath = getRootPath();
while (rootPath != m_tree->getData().m_path ) {
APPL_ERROR("rootPath=" << rootPath << " != " << m_tree->getData().m_path);
goUpper();
}
}
expandToPath(m_tree, _buffer->getFileName());
auto listElements = m_tree->findIf([&](const etk::TreeNode<TreeElement>& _node) {
APPL_WARNING("Compare : '" << _node.getData().m_path << "' =?= '" << _buffer->getFileName() << "'");
if (_node.getData().m_path == _buffer->getFileName()) {
@@ -321,6 +387,10 @@ fluorine::Variant appl::widget::BufferTree::getData(int32_t _role, const ivec2&
case ewol::widget::ListRole::Text:
return value.m_nodeName;
case ewol::widget::ListRole::FgColor:
// Folder with child open element
if (value.m_haveChildOpen == true) {
return (*m_paintingProperties)[m_colorTextNormal].getForeground();
}
if (value.m_buffer == null) {
//APPL_ERROR( m_colorBackgroundHide << " => " << (*m_paintingProperties)[m_colorBackgroundHide].getForeground());
return (*m_paintingProperties)[m_colorTextNotOpen].getForeground();
@@ -332,6 +402,10 @@ fluorine::Variant appl::widget::BufferTree::getData(int32_t _role, const ivec2&
case ewol::widget::ListRole::BgColor:
//return fluorine::Variant();
//APPL_ERROR( m_colorBackground1 << " => " << (*m_paintingProperties)[m_colorBackground1].getForeground());
if ( value.m_buffer == m_selection
&& m_selection != null) {
return (*m_paintingProperties)[m_colorBackgroundSelect].getForeground();
}
if (_pos.y() % 2) {
return (*m_paintingProperties)[m_colorBackground1].getForeground();
}
@@ -339,19 +413,22 @@ fluorine::Variant appl::widget::BufferTree::getData(int32_t _role, const ivec2&
case ewol::widget::ListRole::Icon:
/*
if (elem->countToRoot() == 0) {
return "{ewol}THEME:GUI:Home.svg";
return "THEME_GUI:///Home.svg?lib=ewol";
}*/
if (value.m_isFolder == true) {
return "{ewol}THEME:GUI:Folder.svg";
return "image_folder";
} else {
return "{ewol}THEME:GUI:File.svg";
return "image_file";
}
return "";
case ewol::widget::ListRole::DistanceToRoot:
return uint_t(elem->countToRoot());
case ewol::widget::ListRole::HaveChild:
return elem->haveChild();
if (elem->haveChild() == true) {
return true;
}
return value.m_haveChild;
case ewol::widget::ListRole::IsExpand:
return value.m_isExpand;
case ewol::widget::ListRole::IsSelected:
@@ -379,14 +456,21 @@ bool appl::widget::BufferTree::onItemEvent(const ewol::event::Input& _event, con
updateFlatTree();
return true;
} else if (value.m_buffer == null) {
// TODO: Open the file...
if (m_bufferManager != null) {
APPL_INFO("Select file: '" << value.m_path << "' in list");
m_bufferManager->open(value.m_path);
value.m_buffer = m_bufferManager->get(value.m_path);
}
return true;
}
}
if (_event.getStatus() == gale::key::status::pressSingle) {
APPL_INFO("Event on List: " << _event << " pos=" << _pos );
if (value.m_buffer != null) {
// TODO: Display the current buffer...
if (m_bufferManager != null) {
APPL_INFO("Select file: '" << value.m_path << "' in list");
m_bufferManager->open(value.m_path);
}
return true;
}
}
@@ -406,4 +490,7 @@ bool appl::widget::BufferTree::onItemEvent(const ewol::event::Input& _event, con
return false;
}
void appl::widget::BufferTree::onChangePropertyShowUnNeeded() {
updateFlatTree();
markToRedraw();
}

View File

@@ -23,11 +23,13 @@ namespace appl {
m_buffer(null),
m_isSelected(false),
m_isExpand(_isExpand) {
m_haveChild = etk::path::haveChild(_path);
}
etk::Path m_path;
etk::String m_nodeName; // must be here ==> the buffer is optionnal..
bool m_isFolder;
bool m_haveChildOpen = false;
bool m_haveChild = false;
ememory::SharedPtr<appl::Buffer> m_buffer;
bool m_isSelected = false;
bool m_isExpand = false;
@@ -39,6 +41,8 @@ namespace appl {
using BufferTreeWeak = ememory::WeakPtr<BufferTree>;
class BufferTree : public ewol::widget::TreeView {
public:
eproperty::Value<bool> propertyShowUnNeeded; //!< Size of the icon.
private:
ememory::SharedPtr<appl::BufferManager> m_bufferManager; //!< handle on the buffer manager
private:
@@ -55,8 +59,11 @@ namespace appl {
int32_t m_selectedID;
void updateFlatTree();
void generateFlatTree();
// Recursive update of the child opening or not
bool updateChildOpen(ememory::SharedPtr<etk::TreeNode<appl::TreeElement>> _node);
etk::Path getRootPath();
void populateNodeIfNeeded(ememory::SharedPtr<etk::TreeNode<appl::TreeElement>> _node);
void expandToPath(ememory::SharedPtr<etk::TreeNode<appl::TreeElement>> _node, const etk::Path& _path);
void goUpper();
ememory::SharedPtr<etk::TreeNode<TreeElement>> m_tree;
etk::FlatTree<TreeElement> m_flatTree;
@@ -87,6 +94,7 @@ namespace appl {
void onSelectBuffer(const ememory::SharedPtr<appl::Buffer>& _buffer);
void onRemoveBuffer(const ememory::SharedPtr<appl::Buffer>& _buffer);
void calculateMinMaxSize() override;
void onChangePropertyShowUnNeeded();
};
}
}