[DEV] add sample treeview
This commit is contained in:
parent
84769bc26e
commit
ba31625447
@ -1,5 +1,6 @@
|
||||
sample/HelloWord
|
||||
sample/CustomWidgets
|
||||
sample/wallpaper
|
||||
sample/treeView
|
||||
tools/visual_test
|
||||
tools/platform_test
|
68
sample/treeView/appl/Main.cpp
Normal file
68
sample/treeView/appl/Main.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
#include <appl/Windows.hpp>
|
||||
#include <ewol/object/Object.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <ewol/context/Context.hpp>
|
||||
#include <appl/widget/BasicTree.hpp>
|
||||
|
||||
namespace appl {
|
||||
class MainApplication : public ewol::context::Application {
|
||||
public:
|
||||
void onCreate(ewol::Context& _context) override {
|
||||
APPL_INFO(" == > CREATE ... " << PROJECT_NAME << " v" << APPL_VERSION << " (START) [" << gale::getBoardType() << "] (" << gale::getCompilationMode() << ") (BEGIN)");
|
||||
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
|
||||
etk::String tmpppp = _context.getCmd().get(iii);
|
||||
if ( tmpppp == "-h"
|
||||
|| tmpppp == "--help") {
|
||||
APPL_INFO(" -h/--help display this help" );
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
// TODO : Remove this : Move if in the windows properties
|
||||
_context.setSize(vec2(800, 600));
|
||||
|
||||
// select internal data for font ...
|
||||
_context.getFontDefault().setUseExternal(true);
|
||||
_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
|
||||
|
||||
appl::widget::BasicTree::createManagerWidget(_context.getWidgetManager());
|
||||
|
||||
ewol::widget::WindowsShared basicWindows = appl::Windows::create();
|
||||
// create the specific windows
|
||||
_context.setWindows(basicWindows);
|
||||
APPL_INFO("==> CREATE ... " PROJECT_NAME " (END)");
|
||||
}
|
||||
|
||||
void onStart(ewol::Context& _context) override {
|
||||
APPL_INFO("==> START ... " PROJECT_NAME " (BEGIN)");
|
||||
// nothing to do ...
|
||||
APPL_INFO("==> START ... " PROJECT_NAME " (END)");
|
||||
}
|
||||
void onStop(ewol::Context& _context) override {
|
||||
APPL_INFO("==> STOP ... " PROJECT_NAME " (START)");
|
||||
// nothing to do ...
|
||||
APPL_INFO("==> STOP ... " PROJECT_NAME " (END)");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
// second possibility
|
||||
return ewol::run(ETK_NEW(appl::MainApplication), _argc, _argv);
|
||||
}
|
8
sample/treeView/appl/Main.hpp
Normal file
8
sample/treeView/appl/Main.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
68
sample/treeView/appl/Windows.cpp
Normal file
68
sample/treeView/appl/Windows.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <appl/debug.hpp>
|
||||
#include <appl/Windows.hpp>
|
||||
#include <ewol/widget/Label.hpp>
|
||||
#include <ewol/widget/Button.hpp>
|
||||
#include <appl/widget/BasicTree.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
appl::Windows::Windows() :
|
||||
m_composer(null) {
|
||||
addObjectType("appl::Windows");
|
||||
propertyTitle.setDirectCheck(etk::String("sample ") + PROJECT_NAME);
|
||||
}
|
||||
|
||||
void appl::Windows::init() {
|
||||
ewol::widget::Windows::init();
|
||||
etk::String composition = etk::String("");
|
||||
composition += "<sizer mode='vert'>\n";
|
||||
composition += " <sizer mode='hori'>\n";
|
||||
composition += " <button name='bt-change'>\n";
|
||||
composition += " <label>\n";
|
||||
composition += " Change Data ...\n";
|
||||
composition += " </label>\n";
|
||||
composition += " </button>\n";
|
||||
composition += " <button name='bt-auto'>\n";
|
||||
composition += " <label>\n";
|
||||
composition += " Auto generate\n";
|
||||
composition += " </label>\n";
|
||||
composition += " </button>\n";
|
||||
composition += " </sizer>\n";
|
||||
composition += " <BasicTree name='displayer' expand='true' fill='true'/>\n";
|
||||
composition += "</sizer>\n";
|
||||
|
||||
m_composer = ewol::widget::Composer::create();
|
||||
if (m_composer == null) {
|
||||
APPL_CRITICAL(" An error occured ... in the windows creatrion ...");
|
||||
return;
|
||||
}
|
||||
m_composer->loadFromString(composition);
|
||||
setSubWidget(m_composer);
|
||||
subBind(ewol::widget::Button, "bt-change", signalPressed, sharedFromThis(), &appl::Windows::onCallbackChangeValues);
|
||||
subBind(ewol::widget::Button, "bt-auto", signalPressed, sharedFromThis(), &appl::Windows::onCallbackAutoMode);
|
||||
}
|
||||
|
||||
void appl::Windows::onCallbackChangeValues() {
|
||||
etk::Vector<float> tmp;
|
||||
for (int32_t iii=0; iii<2048; ++iii) {
|
||||
tmp.pushBack(etk::tool::frand(-1.0, 1.0));
|
||||
}
|
||||
ememory::SharedPtr<appl::widget::BasicTree> tmpDisp = ememory::dynamicPointerCast<appl::widget::BasicTree>(getSubObjectNamed("displayer"));
|
||||
if (tmpDisp != null) {
|
||||
//tmpDisp->setValue(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void appl::Windows::onCallbackAutoMode() {
|
||||
ememory::SharedPtr<appl::widget::BasicTree> tmpDisp = ememory::dynamicPointerCast<appl::widget::BasicTree>(getSubObjectNamed("displayer"));
|
||||
if (tmpDisp != null) {
|
||||
//tmpDisp->ToggleAuto();
|
||||
}
|
||||
}
|
||||
|
27
sample/treeView/appl/Windows.hpp
Normal file
27
sample/treeView/appl/Windows.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ewol/widget/Windows.hpp>
|
||||
#include <ewol/widget/Composer.hpp>
|
||||
|
||||
namespace appl {
|
||||
class Windows;
|
||||
using WindowsShared = ememory::SharedPtr<appl::Windows>;
|
||||
using WindowsWeak = ememory::WeakPtr<appl::Windows>;
|
||||
class Windows : public ewol::widget::Windows {
|
||||
private:
|
||||
ewol::widget::ComposerShared m_composer;
|
||||
protected:
|
||||
Windows();
|
||||
void init();
|
||||
public:
|
||||
DECLARE_FACTORY(Windows);
|
||||
public: // callback functions
|
||||
void onCallbackChangeValues();
|
||||
void onCallbackAutoMode();
|
||||
};
|
||||
}
|
13
sample/treeView/appl/debug.cpp
Normal file
13
sample/treeView/appl/debug.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
|
||||
int32_t appl::getLogId() {
|
||||
static int32_t g_val = elog::registerInstance("example");
|
||||
return g_val;
|
||||
}
|
37
sample/treeView/appl/debug.hpp
Normal file
37
sample/treeView/appl/debug.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <elog/log.hpp>
|
||||
|
||||
namespace appl {
|
||||
int32_t getLogId();
|
||||
};
|
||||
#define APPL_BASE(info,data) ELOG_BASE(appl::getLogId(),info,data)
|
||||
|
||||
#define APPL_CRITICAL(data) APPL_BASE(1, data)
|
||||
#define APPL_ERROR(data) APPL_BASE(2, data)
|
||||
#define APPL_WARNING(data) APPL_BASE(3, data)
|
||||
#ifdef DEBUG
|
||||
#define APPL_INFO(data) APPL_BASE(4, data)
|
||||
#define APPL_DEBUG(data) APPL_BASE(5, data)
|
||||
#define APPL_VERBOSE(data) APPL_BASE(6, data)
|
||||
#define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)
|
||||
#else
|
||||
#define APPL_INFO(data) do { } while(false)
|
||||
#define APPL_DEBUG(data) do { } while(false)
|
||||
#define APPL_VERBOSE(data) do { } while(false)
|
||||
#define APPL_TODO(data) do { } while(false)
|
||||
#endif
|
||||
|
||||
#define APPL_ASSERT(cond,data) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
APPL_CRITICAL(data); \
|
||||
assert(!#cond); \
|
||||
} \
|
||||
} while (0)
|
||||
|
135
sample/treeView/appl/widget/BasicTree.cpp
Normal file
135
sample/treeView/appl/widget/BasicTree.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include "BasicTree.hpp"
|
||||
#include <etk/tool.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(appl::widget::BasicTree);
|
||||
|
||||
appl::widget::BasicTree::BasicTree() {
|
||||
addObjectType("appl::widget::BasicTree");
|
||||
setMouseLimit(1);
|
||||
|
||||
|
||||
m_tree = NodeElement::create("root");
|
||||
for (size_t iii=0; iii<10; ++iii) {
|
||||
auto elem_iii = NodeElement::create("elem_" + etk::toString(iii));
|
||||
m_tree->addChild(elem_iii);
|
||||
for (size_t jjj=0; jjj<iii; ++jjj) {
|
||||
auto elem_iii_jjj = NodeElement::create("elem_" + etk::toString(iii) + "____" + etk::toString(jjj));
|
||||
elem_iii->addChild(elem_iii_jjj);
|
||||
}
|
||||
}
|
||||
m_flatTree.setRoot(m_tree);
|
||||
}
|
||||
|
||||
appl::widget::BasicTree::~BasicTree() {
|
||||
|
||||
}
|
||||
|
||||
etk::Color<> appl::widget::BasicTree::getBasicBG() {
|
||||
return etk::Color<>(0,0,0xFF,0xFF);
|
||||
}
|
||||
|
||||
|
||||
ivec2 appl::widget::BasicTree::getMatrixSize() const {
|
||||
return ivec2(3, 10);
|
||||
}
|
||||
|
||||
fluorine::Variant appl::widget::BasicTree::getData(int32_t _role, const ivec2& _pos) {
|
||||
switch (_role) {
|
||||
case ewol::widget::ListRole::Text:
|
||||
return "value: " + etk::toString(_pos);
|
||||
case ewol::widget::ListRole::FgColor:
|
||||
return etk::Color<>(0,0,0,0xFF);
|
||||
case ewol::widget::ListRole::BgColor:
|
||||
return fluorine::Variant();
|
||||
}
|
||||
return fluorine::Variant();
|
||||
}
|
||||
|
||||
bool appl::widget::BasicTree::onItemEvent(int32_t _IdInput,
|
||||
enum gale::key::status _typeEvent,
|
||||
const ivec2& _pos,
|
||||
const vec2& _mousePosition) {
|
||||
/*
|
||||
int32_t offset = 0;
|
||||
if (*propertyShowFolder == true) {
|
||||
if (*propertyPath == "/") {
|
||||
offset = 1;
|
||||
} else {
|
||||
offset = 2;
|
||||
}
|
||||
}
|
||||
if (_typeEvent == gale::key::status::pressSingle) {
|
||||
EWOL_VERBOSE("Event on List : IdInput=" << _IdInput << " _pos=" << _pos );
|
||||
if (1 == _IdInput) {
|
||||
int32_t previousRaw = m_selectedLine;
|
||||
if (_pos.y() > (int32_t)m_list.size()+offset ) {
|
||||
m_selectedLine = -1;
|
||||
} else {
|
||||
m_selectedLine = _pos.y();
|
||||
}
|
||||
if (previousRaw != m_selectedLine) {
|
||||
if( *propertyShowFolder == true
|
||||
&& m_selectedLine == 0) {
|
||||
// "." folder
|
||||
signalFolderSelect.emit(".");
|
||||
} else if ( *propertyShowFolder == true
|
||||
&& m_selectedLine == 1) {
|
||||
// ".." folder
|
||||
signalFolderSelect.emit("..");
|
||||
} else if( m_selectedLine-offset >= 0
|
||||
&& m_selectedLine-offset < (int32_t)m_list.size()
|
||||
&& null != m_list[m_selectedLine-offset] ) {
|
||||
// generate event extern :
|
||||
switch(m_list[m_selectedLine-offset]->getNodeType()) {
|
||||
case etk::typeNode_file :
|
||||
signalFileSelect.emit(m_list[m_selectedLine-offset]->getNameFile());
|
||||
break;
|
||||
case etk::typeNode_folder :
|
||||
signalFolderSelect.emit(m_list[m_selectedLine-offset]->getNameFile());
|
||||
break;
|
||||
default:
|
||||
EWOL_ERROR("Can not generate event on an unknow type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if( *propertyShowFolder == true
|
||||
&& m_selectedLine == 0) {
|
||||
// "." folder
|
||||
signalFolderValidate.emit(".");
|
||||
} else if ( *propertyShowFolder == true
|
||||
&& m_selectedLine == 1) {
|
||||
// ".." folder
|
||||
signalFolderValidate.emit("..");
|
||||
} else if( m_selectedLine-offset >= 0
|
||||
&& m_selectedLine-offset < (int32_t)m_list.size()
|
||||
&& null != m_list[m_selectedLine-offset] ) {
|
||||
switch(m_list[m_selectedLine-offset]->getNodeType()) {
|
||||
case etk::typeNode_file :
|
||||
signalFileValidate.emit(m_list[m_selectedLine-offset]->getNameFile());
|
||||
break;
|
||||
case etk::typeNode_folder :
|
||||
signalFolderValidate.emit(m_list[m_selectedLine-offset]->getNameFile());
|
||||
break;
|
||||
default:
|
||||
EWOL_ERROR("Can not generate event on an unknow type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// need to regenerate the display of the list :
|
||||
markToRedraw();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
41
sample/treeView/appl/widget/BasicTree.hpp
Normal file
41
sample/treeView/appl/widget/BasicTree.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ewol/widget/List.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <ewol/resource/ColorFile.hpp>
|
||||
#include <esignal/Signal.hpp>
|
||||
#include <etk/FlatTree.hpp>
|
||||
|
||||
namespace appl {
|
||||
namespace widget {
|
||||
class BasicTree;
|
||||
using BasicTreeShared = ememory::SharedPtr<appl::widget::BasicTree>;
|
||||
using BasicTreeWeak = ememory::WeakPtr<appl::widget::BasicTree>;
|
||||
/**
|
||||
* @brief Generic display folder class. This widget display the content of a single folder :
|
||||
*/
|
||||
class BasicTree : public ewol::widget::List {
|
||||
protected:
|
||||
BasicTree();
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(BasicTree, "BasicTree");
|
||||
virtual ~BasicTree();
|
||||
protected:
|
||||
etk::Color<> getBasicBG() 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, const ivec2& _pos, const vec2& _mousePosition) override;
|
||||
|
||||
using NodeElement = etk::TreeNode<etk::String>;
|
||||
ememory::SharedPtr<NodeElement> m_tree;
|
||||
etk::FlatTree<etk::String> m_flatTree;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
48
sample/treeView/lutin_ewol-sample-treeview.py
Normal file
48
sample/treeView/lutin_ewol-sample-treeview.py
Normal file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
def get_type():
|
||||
return "BINARY"
|
||||
|
||||
def get_sub_type():
|
||||
return "SAMPLE"
|
||||
|
||||
def get_desc():
|
||||
return "Tutorial 0XX : bsic tree example"
|
||||
|
||||
def get_licence():
|
||||
return "MPL-2"
|
||||
|
||||
def get_compagny_type():
|
||||
return "com"
|
||||
|
||||
def get_compagny_name():
|
||||
return "atria-soft"
|
||||
|
||||
def get_maintainer():
|
||||
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
|
||||
|
||||
def get_version():
|
||||
return [0,1]
|
||||
|
||||
def configure(target, my_module):
|
||||
my_module.add_src_file([
|
||||
'appl/Main.cpp',
|
||||
'appl/debug.cpp',
|
||||
'appl/Windows.cpp',
|
||||
'appl/widget/BasicTree.cpp',
|
||||
])
|
||||
my_module.add_depend([
|
||||
'ewol'
|
||||
])
|
||||
my_module.add_flag('c++', [
|
||||
"-DPROJECT_NAME=\"\\\""+my_module.get_name()+"\\\"\"",
|
||||
"-DAPPL_VERSION=\"\\\"" + tools.version_to_string(get_version()) + "\\\"\""
|
||||
])
|
||||
my_module.add_path(".")
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user