Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions include/nanogui/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class NANOGUI_EXPORT Button : public Widget {
std::string_view caption() const { return m_caption; }

/// Sets the caption of this Button.
void set_caption(std::string_view caption) { m_caption = caption; }
void set_caption(std::string_view caption) {
if (m_caption != caption) {
m_caption = caption;
preferred_size_changed();
}
}

/// Returns the background color of this Button.
const Color &background_color() const { return m_background_color; }
Expand All @@ -74,7 +79,12 @@ class NANOGUI_EXPORT Button : public Widget {
/// Returns the icon of this Button. See \ref nanogui::Button::m_icon.
int icon() const { return m_icon; }
/// Sets the icon of this Button. See \ref nanogui::Button::m_icon.
void set_icon(int icon) { m_icon = icon; }
void set_icon(int icon) {
if (m_icon != icon) {
m_icon = icon;
preferred_size_changed();
}
}

/// The current flags of this Button (see \ref nanogui::Button::Flags for options).
int flags() const { return m_flags; }
Expand All @@ -84,7 +94,12 @@ class NANOGUI_EXPORT Button : public Widget {
/// The position of the icon for this Button.
IconPosition icon_position() const { return m_icon_position; }
/// Sets the position of the icon for this Button.
void set_icon_position(IconPosition icon_position) { m_icon_position = icon_position; }
void set_icon_position(IconPosition icon_position) {
if (m_icon_position != icon_position) {
m_icon_position = icon_position;
preferred_size_changed();
}
}

/// Whether or not this Button is currently pushed.
bool pushed() const { return m_pushed; }
Expand All @@ -109,10 +124,18 @@ class NANOGUI_EXPORT Button : public Widget {
/// The padding of this Button.
const Vector2i &padding() const { return m_padding; }
/// Set the padding of this Button.
void set_padding(const Vector2i &padding) { m_padding = padding; }
void set_padding(const Vector2i &padding) {
if (m_padding != padding) {
m_padding = padding;
preferred_size_changed();
}
}

protected:
/// The preferred size of this Button.
virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;

public:
/// The callback that is called when any type of mouse button event is issued to this Button.
virtual bool mouse_enter_event(const Vector2i &p, bool enter) override;
virtual bool mouse_button_event(const Vector2i &p, int button, bool down, int modifiers) override;
Expand Down
12 changes: 10 additions & 2 deletions include/nanogui/checkbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class NANOGUI_EXPORT CheckBox : public Widget {
std::string_view caption() const { return m_caption; }

/// Sets the caption of this check box
void set_caption(std::string_view caption) { m_caption = caption; }
void set_caption(std::string_view caption) {
if (m_caption != caption) {
m_caption = caption;
preferred_size_changed();
}
}

/// Return whether or not this widget is currently checked.
const bool &checked() const { return m_checked; }
Expand All @@ -73,8 +78,11 @@ class NANOGUI_EXPORT CheckBox : public Widget {
/// Mouse button event processing for this check box
virtual bool mouse_button_event(const Vector2i &p, int button, bool down, int modifiers) override;

protected:
/// The preferred size of this CheckBox.
virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;

public:

/// Draws this CheckBox.
virtual void draw(NVGcontext *ctx) override;
Expand Down
5 changes: 3 additions & 2 deletions include/nanogui/colorwheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class NANOGUI_EXPORT ColorWheel : public Widget {
/// Sets the current Color this ColorWheel has selected.
void set_color(const Color& color);

/// The preferred size of this ColorWheel.
virtual Vector2i preferred_size(NVGcontext *ctx) const override;

/// Draws the ColorWheel.
virtual void draw(NVGcontext *ctx) override;
Expand Down Expand Up @@ -99,6 +97,9 @@ class NANOGUI_EXPORT ColorWheel : public Widget {

/// The current callback to execute when the color value has changed.
std::function<void(const Color &)> m_callback;

/// The preferred size of this ColorWheel.
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;
};

NAMESPACE_END(nanogui)
12 changes: 12 additions & 0 deletions include/nanogui/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ extern NANOGUI_EXPORT std::vector<std::pair<int, std::string>>
extern NANOGUI_EXPORT int __nanogui_get_image(NVGcontext *ctx, std::string_view name,
uint8_t *data, uint32_t size);

template <typename Func> struct scope_guard {
scope_guard(Func &&func) : func(std::move(func)) { };
~scope_guard() { func(); }
scope_guard(const Func &) = delete;
scope_guard() = delete;
scope_guard& operator=(const Func &) = delete;
scope_guard& operator=(Func&&) = delete;

private:
Func func;
};

NAMESPACE_END(nanogui)

NAMESPACE_BEGIN(drjit)
Expand Down
2 changes: 1 addition & 1 deletion include/nanogui/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class NANOGUI_EXPORT Graph : public Widget {
std::vector<float> &values() { return m_values; }
void set_values(const std::vector<float> &values) { m_values = values; }

virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual void draw(NVGcontext *ctx) override;
protected:
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;
std::string m_caption, m_header, m_footer;
Color m_background_color, m_fill_color, m_stroke_color, m_text_color;
std::vector<float> m_values;
Expand Down
4 changes: 2 additions & 2 deletions include/nanogui/imagepanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NANOGUI_EXPORT ImagePanel : public Widget {
public:
ImagePanel(Widget *parent);

void set_images(const Images &data) { m_images = data; }
void set_images(const Images &data) { m_images = data; preferred_size_changed(); }
const Images& images() const { return m_images; }

const std::function<void(int)> &callback() const { return m_callback; }
Expand All @@ -38,10 +38,10 @@ class NANOGUI_EXPORT ImagePanel : public Widget {
int modifiers) override;
virtual bool mouse_button_event(const Vector2i &p, int button, bool down,
int modifiers) override;
virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual void draw(NVGcontext *ctx) override;

protected:
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;
Vector2i grid_size() const;
int index_for_position(const Vector2i &p) const;
protected:
Expand Down
19 changes: 16 additions & 3 deletions include/nanogui/label.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ class NANOGUI_EXPORT Label : public Widget {
/// Get the label's text caption
std::string_view caption() const { return m_caption; }
/// Set the label's text caption
void set_caption(std::string_view caption) { m_caption = caption; }
void set_caption(std::string_view caption) {
if (m_caption != caption) {
m_caption = caption;
preferred_size_changed();
}
}

/// Set the currently active font (2 are available by default: 'sans' and 'sans-bold')
void set_font(std::string_view font) { m_font = font; }
void set_font(std::string_view font) {
if (m_font != font) {
m_font = font;
preferred_size_changed();
}
}
/// Get the currently active font
std::string_view font() const { return m_font; }

Expand All @@ -47,8 +57,11 @@ class NANOGUI_EXPORT Label : public Widget {
/// Set the \ref Theme used to draw this widget
virtual void set_theme(Theme *theme) override;

protected:
/// Compute the size needed to fully display the label
virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;

public:

/// Draw the label
virtual void draw(NVGcontext *ctx) override;
Expand Down
2 changes: 1 addition & 1 deletion include/nanogui/progressbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class NANOGUI_EXPORT ProgressBar : public Widget {
float value() { return m_value; }
void set_value(float value) { m_value = value; }

virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual void draw(NVGcontext* ctx) override;
protected:
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;
float m_value;
};

Expand Down
4 changes: 2 additions & 2 deletions include/nanogui/python.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ extern "C" {
bool keyboard_character_event(unsigned int codepoint) override { \
NB_OVERRIDE(keyboard_character_event, codepoint); \
} \
::nanogui::Vector2i preferred_size(NVGcontext *ctx) const override { \
NB_OVERRIDE(preferred_size, ctx); \
::nanogui::Vector2i preferred_size_impl(NVGcontext *ctx) const override { \
NB_OVERRIDE(preferred_size_impl, ctx); \
} \
void perform_layout(NVGcontext *ctx) override { \
NB_OVERRIDE(perform_layout, ctx); \
Expand Down
7 changes: 4 additions & 3 deletions include/nanogui/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ class NANOGUI_EXPORT Screen : public Widget {
void set_shutdown_glfw(bool v) { m_shutdown_glfw = v; }
bool shutdown_glfw() { return m_shutdown_glfw; }

/// Is a tooltip currently fading in?
bool tooltip_fade_in_progress() const;

using Widget::perform_layout;

/// Compute the layout of all widgets
Expand Down Expand Up @@ -331,6 +328,10 @@ class NANOGUI_EXPORT Screen : public Widget {
std::function<void(Vector2i)> m_resize_callback;
RunMode m_last_run_mode;
ref<Texture> m_depth_stencil_texture;

double m_tooltip_delay = 0.2;
bool m_tooltip_redraw_required = false;
void *m_tooltip_redraw_notify_thread;
#if defined(NANOGUI_USE_METAL)
void *m_metal_texture = nullptr;
void *m_metal_drawable = nullptr;
Expand Down
5 changes: 4 additions & 1 deletion include/nanogui/slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class NANOGUI_EXPORT Slider : public Widget {
const std::function<void(float)> &final_callback() const { return m_final_callback; }
void set_final_callback(const std::function<void(float)> &callback) { m_final_callback = callback; }

virtual Vector2i preferred_size(NVGcontext *ctx) const override;
protected:
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;

public:
virtual bool mouse_drag_event(const Vector2i &p, const Vector2i &rel, int button, int modifiers) override;
virtual bool mouse_button_event(const Vector2i &p, int button, bool down, int modifiers) override;
virtual void draw(NVGcontext* ctx) override;
Expand Down
10 changes: 5 additions & 5 deletions include/nanogui/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ class NANOGUI_EXPORT TabWidgetBase : public Widget {
/// Return the caption of the tab with the given ID
const std::string& tab_caption(int id) const { return m_tab_captions[tab_index(id)]; }
/// Change the caption of the tab with the given ID
void set_tab_caption(int id, std::string_view caption) { m_tab_captions[tab_index(id)] = caption; }
void set_tab_caption(int id, std::string_view caption) { m_tab_captions[tab_index(id)] = caption; preferred_size_changed(); }

/// Return whether tabs provide a close button
bool tabs_closeable() const { return m_tabs_closeable; }
void set_tabs_closeable(bool value) { m_tabs_closeable = value; }
void set_tabs_closeable(bool value) { m_tabs_closeable = value; preferred_size_changed(); }

/// Return whether tabs can be dragged to different positions
bool tabs_draggable() const { return m_tabs_draggable; }
void set_tabs_draggable(bool value) { m_tabs_draggable = value; }

/// Return the padding between the tab widget boundary and child widgets
int padding() const { return m_padding; }
void set_padding(int value) { m_padding = value; }
void set_padding(int value) { m_padding = value; preferred_size_changed(); }

/// Set the widget's background color (a global property)
void set_background_color(const Color &background_color) {
Expand Down Expand Up @@ -101,7 +101,6 @@ class NANOGUI_EXPORT TabWidgetBase : public Widget {

// Widget implementation
virtual void perform_layout(NVGcontext* ctx) override;
virtual Vector2i preferred_size(NVGcontext* ctx) const override;
virtual void draw(NVGcontext* ctx) override;
virtual bool mouse_button_event(const Vector2i &p, int button, bool down,
int modifiers) override;
Expand All @@ -110,6 +109,7 @@ class NANOGUI_EXPORT TabWidgetBase : public Widget {
int modifiers) override;

protected:
virtual Vector2i preferred_size_impl(NVGcontext* ctx) const override;
std::pair<int, bool> tab_at_position(const Vector2i &p,
bool test_vertical = true) const;
virtual void update_visibility();
Expand Down Expand Up @@ -198,8 +198,8 @@ class NANOGUI_EXPORT TabWidget : public TabWidgetBase {
void set_remove_children(bool value) { m_remove_children = value; }

virtual void perform_layout(NVGcontext* ctx) override;
virtual Vector2i preferred_size(NVGcontext* ctx) const override;
protected:
virtual Vector2i preferred_size_impl(NVGcontext* ctx) const override;
virtual void update_visibility() override;
protected:
std::vector<std::pair<int, Widget *>> m_widgets;
Expand Down
4 changes: 2 additions & 2 deletions include/nanogui/textarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class NANOGUI_EXPORT TextArea : public Widget {
}

/// Set the amount of padding to add around the text
void set_padding(int padding) { m_padding = padding; }
void set_padding(int padding) { m_padding = padding; preferred_size_changed(); }

/// Return the amount of padding that is added around the text
int padding() const { return m_padding; }
Expand All @@ -90,14 +90,14 @@ class NANOGUI_EXPORT TextArea : public Widget {

/* Widget implementation */
virtual void draw(NVGcontext *ctx) override;
virtual Vector2i preferred_size(NVGcontext *ctx) const override;
virtual bool mouse_button_event(const Vector2i &p, int button, bool down,
int modifiers) override;
virtual bool mouse_drag_event(const Vector2i &p, const Vector2i &rel, int button,
int modifiers) override;
virtual bool keyboard_event(int key, int scancode, int action, int modifiers) override;

protected:
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;
Vector2i position_to_block(const Vector2i &pos) const;
Vector2i block_to_position(const Vector2i &pos) const;

Expand Down
40 changes: 34 additions & 6 deletions include/nanogui/textbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,20 @@ class NANOGUI_EXPORT TextBox : public Widget {
void set_editable(bool editable);

bool spinnable() const { return m_spinnable; }
void set_spinnable(bool spinnable) { m_spinnable = spinnable; }
void set_spinnable(bool spinnable) {
if (m_spinnable != spinnable) {
m_spinnable = spinnable;
preferred_size_changed();
}
}

const std::string &value() const { return m_value; }
void set_value(std::string_view value) { m_value = value; }
void set_value(std::string_view value) {
if (m_value != value) {
m_value = value;
preferred_size_changed();
}
}

std::string_view default_value() const { return m_default_value; }
void set_default_value(std::string_view default_value) { m_default_value = default_value; }
Expand All @@ -58,10 +68,20 @@ class NANOGUI_EXPORT TextBox : public Widget {
void set_alignment(Alignment align) { m_alignment = align; }

std::string_view units() const { return m_units; }
void set_units(std::string_view units) { m_units = units; }
void set_units(std::string_view units) {
if (m_units != units) {
m_units = units;
preferred_size_changed();
}
}

int units_image() const { return m_units_image; }
void set_units_image(int image) { m_units_image = image; }
void set_units_image(int image) {
if (m_units_image != image) {
m_units_image = image;
preferred_size_changed();
}
}

/// Return the underlying regular expression specifying valid formats
std::string_view format() const { return m_format; }
Expand All @@ -71,7 +91,12 @@ class NANOGUI_EXPORT TextBox : public Widget {
/// Return the placeholder text to be displayed while the text box is empty.
std::string_view placeholder() const { return m_placeholder; }
/// Specify a placeholder text to be displayed while the text box is empty.
void set_placeholder(std::string_view placeholder) { m_placeholder = placeholder; }
void set_placeholder(std::string_view placeholder) {
if (m_placeholder != placeholder) {
m_placeholder = placeholder;
preferred_size_changed();
}
}

/// Set the \ref Theme used to draw this widget
virtual void set_theme(Theme *theme) override;
Expand Down Expand Up @@ -111,7 +136,10 @@ class NANOGUI_EXPORT TextBox : public Widget {
virtual bool keyboard_event(int key, int scancode, int action, int modifiers) override;
virtual bool keyboard_character_event(unsigned int codepoint) override;

virtual Vector2i preferred_size(NVGcontext *ctx) const override;
protected:
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;

public:
virtual void draw(NVGcontext* ctx) override;
protected:
bool check_format(const std::string &input, const std::string &format);
Expand Down
Loading
Loading