-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding ruler tool and line drawing tool. closes: #50 ; closes: #49 * shift-click to draw straight lines with brush tool. closes: #51 * better keyboard handling (all dialogs can be confirmed/canceled using Return/Esc) * toolbar can now be resized to have two columns
- Loading branch information
Showing
20 changed files
with
1,792 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
#include "dialog.h" | ||
#include <nanogui/button.h> | ||
#include <nanogui/formhelper.h> | ||
#include <nanogui/label.h> | ||
#include <nanogui/layout.h> | ||
|
||
NAMESPACE_BEGIN(nanogui) | ||
|
||
Dialog::Dialog(Widget *parent, const std::string &title, bool form) : Window(parent, title) | ||
{ | ||
set_modal(true); | ||
|
||
request_focus(); | ||
if (form) | ||
make_form(); | ||
} | ||
|
||
void Dialog::make_form() | ||
{ | ||
// copied from FormHelper | ||
auto layout = new AdvancedGridLayout({10, 0, 10, 0}, {}); | ||
layout->set_margin(10); | ||
layout->set_col_stretch(2, 1); | ||
set_layout(layout); | ||
} | ||
|
||
Widget *Dialog::add_buttons(const std::string &button_text, const std::string &alt_button_text, bool alt_button) | ||
{ | ||
Widget *button_panel = new Widget(this); | ||
button_panel->set_layout(new GridLayout(Orientation::Horizontal, 2, Alignment::Fill, 0, 5)); | ||
|
||
if (alt_button) | ||
{ | ||
Button *button = new Button(button_panel, alt_button_text, m_theme->m_message_alt_button_icon); | ||
button->set_callback( | ||
[this] | ||
{ | ||
if (m_callback) | ||
m_callback(1); | ||
dispose(); | ||
}); | ||
} | ||
Button *button = new Button(button_panel, button_text, m_theme->m_message_primary_button_icon); | ||
button->set_callback( | ||
[this] | ||
{ | ||
if (m_callback) | ||
m_callback(0); | ||
dispose(); | ||
}); | ||
|
||
return button_panel; | ||
} | ||
|
||
SimpleDialog::SimpleDialog(Widget *parent, Type type, const std::string &title, const std::string &message, | ||
const std::string &button_text, const std::string &alt_button_text, bool alt_button) : | ||
Dialog(parent, title, false) | ||
{ | ||
set_layout(new BoxLayout(Orientation::Vertical, Alignment::Middle, 10, 10)); | ||
|
||
Widget *message_panel = new Widget(this); | ||
message_panel->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 10, 15)); | ||
int icon = 0; | ||
switch (type) | ||
{ | ||
case Type::Empty: icon = 0; break; | ||
case Type::Information: icon = m_theme->m_message_information_icon; break; | ||
case Type::Question: icon = m_theme->m_message_question_icon; break; | ||
case Type::Warning: icon = m_theme->m_message_warning_icon; break; | ||
} | ||
Label *icon_label = new Label(message_panel, std::string(utf8(icon).data()), "icons"); | ||
icon_label->set_font_size(50); | ||
m_message_label = new Label(message_panel, message); | ||
m_message_label->set_fixed_width(icon ? 200 : 0); | ||
|
||
add_buttons(button_text, alt_button_text, alt_button); | ||
|
||
center(); | ||
request_focus(); | ||
} | ||
|
||
NAMESPACE_END(nanogui) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
#pragma once | ||
|
||
#include <nanogui/messagedialog.h> | ||
#include <nanogui/nanogui.h> | ||
|
||
NAMESPACE_BEGIN(nanogui) | ||
|
||
/// Similar to MessageDialog but extensible and can be used with FormHelper class | ||
class Dialog : public Window | ||
{ | ||
public: | ||
Dialog(Widget *parent, const std::string &title = "Untitled", bool form = true); | ||
|
||
void make_form(); | ||
Widget *add_buttons(const std::string &button_text = "OK", const std::string &alt_button_text = "Cancel", | ||
bool alt_button = true); | ||
|
||
std::function<void(int)> callback() const { return m_callback; } | ||
void set_callback(const std::function<void(int)> &callback) { m_callback = callback; } | ||
|
||
protected: | ||
std::function<void(int)> m_callback; | ||
}; | ||
|
||
/// Identical to MessageDialog but derived from the above Dialog class. | ||
class SimpleDialog : public Dialog | ||
{ | ||
public: | ||
/// Classification of the type of message this SimpleDialog represents. | ||
enum class Type | ||
{ | ||
Empty, | ||
Information, | ||
Question, | ||
Warning | ||
}; | ||
|
||
SimpleDialog(Widget *parent, Type type, const std::string &title = "Untitled", | ||
const std::string &message = "Message", const std::string &button_text = "OK", | ||
const std::string &alt_button_text = "Cancel", bool alt_button = false); | ||
|
||
Label * message_label() { return m_message_label; } | ||
const Label *message_label() const { return m_message_label; } | ||
|
||
protected: | ||
Label *m_message_label; | ||
}; | ||
|
||
NAMESPACE_END(nanogui) |
Oops, something went wrong.