dialog: add updateSize() method

This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent aca4b074ab
commit 6c8e8e5f98
2 changed files with 49 additions and 30 deletions
+32 -4
View File
@@ -23,16 +23,44 @@
DialogWindowContent::DialogWindowContent(Dialog* parent, const rect_t& rect) : DialogWindowContent::DialogWindowContent(Dialog* parent, const rect_t& rect) :
ModalWindowContent(parent, rect), ModalWindowContent(parent, rect),
form(this, {0, POPUP_HEADER_HEIGHT, rect.w, coord_t(rect.h - POPUP_HEADER_HEIGHT)}, FORM_NO_BORDER) form(this,
{ 0, POPUP_HEADER_HEIGHT, rect.w,
coord_t(rect.h - POPUP_HEADER_HEIGHT) },
FORM_NO_BORDER)
{ {
form.setFocus(SET_FOCUS_DEFAULT); form.setFocus(SET_FOCUS_DEFAULT);
} }
void DialogWindowContent::updateSize()
{
lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
lv_obj_center(lvobj);
lv_obj_update_layout(lvobj);
rect.x = lv_obj_get_x(lvobj);
rect.y = lv_obj_get_y(lvobj);
rect.w = lv_obj_get_width(lvobj);
rect.h = lv_obj_get_height(lvobj);
invalidate();
}
void DialogWindowContent::deleteLater(bool detach, bool trash)
{
if (_deleted) return;
form.deleteLater(true, false);
ModalWindowContent::deleteLater(detach, trash);
}
#if defined(DEBUG_WINDOWS)
std::string DialogWindowContent::getName() const override
{
return "DialogWindowContent";
}
#endif
Dialog::Dialog(Window* parent, std::string title, const rect_t& rect) : Dialog::Dialog(Window* parent, std::string title, const rect_t& rect) :
ModalWindow(parent), ModalWindow(parent), content(new DialogWindowContent(this, rect))
content(createDialogWindow(this, rect))
{ {
bringToTop(); bringToTop();
content->setTitle(std::move(title)); if (!title.empty()) content->setTitle(std::move(title));
} }
+5 -14
View File
@@ -31,31 +31,22 @@ class DialogWindowContent: public ModalWindowContent
public: public:
DialogWindowContent(Dialog* parent, const rect_t& rect); DialogWindowContent(Dialog* parent, const rect_t& rect);
void deleteLater(bool detach = true, bool trash = true) override void updateSize();
{ void deleteLater(bool detach = true, bool trash = true) override;
if (_deleted)
return;
form.deleteLater(true, false);
ModalWindowContent::deleteLater(detach, trash);
}
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override;
{
return "DialogWindowContent";
}
#endif #endif
public: public:
FormGroup form; FormGroup form;
}; };
class Dialog: public ModalWindow { class Dialog : public ModalWindow
{
public: public:
Dialog(Window* parent, std::string title, const rect_t& rect); Dialog(Window* parent, std::string title, const rect_t& rect);
protected: protected:
DialogWindowContent* content; DialogWindowContent* content;
}; };