fix some ui glitch with NodeButton, start implementing working dir option

This commit is contained in:
2018-10-06 16:17:42 +02:00
parent 739784b0d1
commit 05decb6a05
9 changed files with 74 additions and 16 deletions

View File

@@ -61,6 +61,26 @@ std::mutex task_mutex;
} }
return ret; return ret;
} }
- (std::string)pick_dir
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO]; // yes if more than one dir is allowed
NSInteger clicked = [panel runModal];
std::string ret;
if (clicked == NSFileHandlingPanelOKButton)
{
for (NSURL *url in [panel URLs])
{
LOG("selected path: %s", [[url path] cStringUsingEncoding:NSUTF8StringEncoding]);
ret = [[url path] cStringUsingEncoding:NSUTF8StringEncoding];
}
}
return ret;
}
- (instancetype)initWithFrame:(NSRect)frameRect - (instancetype)initWithFrame:(NSRect)frameRect
{ {
gl_ready = false; gl_ready = false;

View File

@@ -23,4 +23,5 @@
- (void)async_unlock; - (void)async_unlock;
- (void)async_swap; - (void)async_swap;
- (std::string)pick_file:(NSArray<NSString*>*)types; - (std::string)pick_file:(NSArray<NSString*>*)types;
- (std::string)pick_dir;
@end @end

View File

@@ -317,7 +317,7 @@
<text id="message" text="Longer description for the error or the message." font-face="arial" font-size="11"></text> <text id="message" text="Longer description for the error or the message." font-face="arial" font-size="11"></text>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -335,7 +335,7 @@
<border width="50" height="30" grow="1" margin="0 10 0 0" color=".2"> <border width="50" height="30" grow="1" margin="0 10 0 0" color=".2">
<border id="progress" width="50%" color="1 0 0 1" height="30"/> <border id="progress" width="50%" color="1 0 0 1" height="30"/>
</border> </border>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -403,8 +403,8 @@
<text-input id="txt-input" justify="center" pad="5" grow="1" height="30" color=".3"/> <text-input id="txt-input" justify="center" pad="5" grow="1" height="30" color=".3"/>
</border> </border>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Rename Layer" width="100" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Rename Layer" width="110" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -427,7 +427,7 @@
</border> </border>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Resize" width="70" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Resize" width="70" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -455,7 +455,7 @@
<node id="footer" height="40" dir="row" align="flex-end" justify="flex-end" pad="10"> <node id="footer" height="40" dir="row" align="flex-end" justify="flex-end" pad="10">
<node grow="1"><button id="btn-delete" text="Delete Project" width="100" height="30" margin="0 10 0 0" color="1 0 0 1"/></node> <node grow="1"><button id="btn-delete" text="Delete Project" width="100" height="30" margin="0 10 0 0" color="1 0 0 1"/></node>
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -483,7 +483,7 @@
<node id="footer" height="40" dir="row" align="flex-end" justify="flex-end" pad="10"> <node id="footer" height="40" dir="row" align="flex-end" justify="flex-end" pad="10">
<node grow="1"/> <node grow="1"/>
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -518,7 +518,7 @@
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<node grow="1"><button id="btn-delete" text="Delete Project" width="100" height="30" margin="0 10 0 0" color="1 0 0 1"/></node> <node grow="1"><button id="btn-delete" text="Delete Project" width="100" height="30" margin="0 10 0 0" color="1 0 0 1"/></node>
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -539,7 +539,7 @@
</border> </border>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Save Project" width="100" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Save Project" width="100" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -562,8 +562,9 @@
</border> </border>
<text os="win,osx" id="path" text="Workind dir: path" text-wrap-width="470" font-face="arial" font-size="11" margin="10 5 10 5"/> <text os="win,osx" id="path" text="Workind dir: path" text-wrap-width="470" font-face="arial" font-size="11" margin="10 5 10 5"/>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Create Project" width="100" height="30" margin="0 10 0 0"/> <node grow="1" os="win,osx"><button id="btn-path" text="Set working dir" width="120" height="30" margin="0 10 0 0"/></node>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/> <button id="btn-ok" text="Create Project" width="110" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>
@@ -601,7 +602,7 @@
<!--footer buttons--> <!--footer buttons-->
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end"> <node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/> <button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/>
<button text="Cancel" width="60" height="30" pad="10"/> <button text="Cancel" width="60" height="30"/>
</node> </node>
</border> </border>
</border> </border>

View File

@@ -182,6 +182,9 @@ void App::initLog()
CreateDirectoryA(rec_path.c_str(), NULL); CreateDirectoryA(rec_path.c_str(), NULL);
#endif #endif
// TODO: save this path somewhere in the settings, don't overwrite every start
work_path = data_path;
//LogRemote::I.start(); //LogRemote::I.start();
LogRemote::I.file_init(); LogRemote::I.file_init();
LOG("%s", g_version); LOG("%s", g_version);

View File

@@ -37,7 +37,7 @@ class App
public: public:
static App I; static App I;
std::string data_path{ "." }; std::string data_path{ "." };
std::string work_path{ "." };
std::string rec_path{ "." }; std::string rec_path{ "." };
std::thread rec_thread; std::thread rec_thread;
bool rec_running = false; bool rec_running = false;
@@ -95,6 +95,7 @@ public:
#endif #endif
void pick_image(std::function<void(std::string path)> callback); void pick_image(std::function<void(std::string path)> callback);
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback); void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
void pick_dir(std::function<void(std::string path)> callback);
void display_file(std::string path); void display_file(std::string path);
void showKeyboard(); void showKeyboard();
void hideKeyboard(); void hideKeyboard();

View File

@@ -90,6 +90,27 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
#endif #endif
} }
void App::pick_dir(std::function<void(std::string path)> callback)
{
redraw = true;
#ifdef __IOS__
// NOT IMPLEMENTED
#elif __OSX__
dispatch_async(dispatch_get_main_queue(), ^{
std::string path = [osx_view pick_dir];
if (!path.empty())
callback(path);
});
#elif __ANDROID__
// NOT IMPLEMENTED
#elif _WIN32
// TODO: to be implemented
// std::string path = win32_open_file();
// if (!path.empty())
// callback(path);
#endif
}
void App::display_file(std::string path) void App::display_file(std::string path)
{ {
#ifdef __IOS__ #ifdef __IOS__

View File

@@ -64,6 +64,7 @@ void NodeButton::loaded()
void NodeButton::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) void NodeButton::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
{ {
Node::parse_attributes(ka, attr);
switch (ka) switch (ka)
{ {
case kAttribute::Color: case kAttribute::Color:
@@ -84,7 +85,7 @@ void NodeButton::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* a
m_text->parse_attributes(ka, attr); m_text->parse_attributes(ka, attr);
break; break;
default: default:
Node::parse_attributes(ka, attr); // Node::parse_attributes(ka, attr);
break; break;
} }
// m_border->parse_attributes(ka, attr); // m_border->parse_attributes(ka, attr);

View File

@@ -233,9 +233,18 @@ void NodeDialogNewDoc::init_controls()
btn_ok->on_click(btn_ok); btn_ok->on_click(btn_ok);
}; };
#if defined(_WIN32) || defined(__OSX__) #if defined(_WIN32) || defined(__OSX__)
working_path = find<NodeText>("path");
static char path_buffer[256]; static char path_buffer[256];
realpath(App::I.data_path.c_str(), path_buffer); btn_path = find<NodeButton>("btn-path");
btn_path->on_click = [this](Node*){
App::I.pick_dir([this](std::string path){
LOG("change working path to %s", path.c_str());
App::I.work_path = path;
realpath(path.c_str(), path_buffer);
working_path->set_text_format("Working dir: %s", path_buffer);
});
};
working_path = find<NodeText>("path");
realpath(App::I.work_path.c_str(), path_buffer);
working_path->set_text_format("Working dir: %s", path_buffer); working_path->set_text_format("Working dir: %s", path_buffer);
#endif #endif
} }

View File

@@ -65,6 +65,7 @@ class NodeDialogNewDoc : public NodeBorder
public: public:
NodeButton* btn_cancel; NodeButton* btn_cancel;
NodeButton* btn_ok; NodeButton* btn_ok;
NodeButton* btn_path;
NodeTextInput* input; NodeTextInput* input;
NodeText* working_path; NodeText* working_path;
NodeComboBox* m_resolution; NodeComboBox* m_resolution;