/* * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD * * SPDX-License-Identifier: MIT */ #include "toast.h" #include #include #include #include #include #include using namespace view; using namespace uitk; using namespace uitk::lvgl_cpp; using namespace mooncake; struct ToastColor_t { uint32_t bg = 0x000000; uint32_t border = 0x000000; uint32_t msg = 0xFFFFFF; }; static const std::string_view _tag = "toast"; static ToastColor_t _toast_color_info = {0xE6F1FE, 0xAFD1F9, 0x005BC4}; static ToastColor_t _toast_color_warning = {0xFEFCE8, 0xDBD38B, 0xC4841D}; static ToastColor_t _toast_color_error = {0xFEE7EF, 0xFCB5CD, 0xC20E4D}; static ToastColor_t _toast_color_success = {0xE8FAF0, 0xA2E8C1, 0x12A150}; static ToastColor_t _toast_color_orange = {0xFFDCD1, 0xFFBFAA, 0xF84C13}; static ToastColor_t _toast_color_gray = {0xFFFFFF, 0xD9D9D9, 0x11181C}; static ToastColor_t _toast_color_rose = {0xFFE9F4, 0xFFBFDF, 0xFF339A}; static ToastColor_t _toast_color_dark = {0x383838, 0x222222, 0xF4F3F3}; static Toast::KeyFrame_t _toast_kf_closed = {-100, 296 / 2}; // pos y, width static Toast::KeyFrame_t _toast_kf_opened = {12, 296}; static int16_t _toast_x = 0; static int16_t _toast_h = 60; static ToastColor_t get_toast_color(ToastType type) { switch (type) { case ToastType::Info: return _toast_color_info; case ToastType::Warning: return _toast_color_warning; case ToastType::Error: return _toast_color_error; case ToastType::Success: return _toast_color_success; case ToastType::Orange: return _toast_color_orange; case ToastType::Gray: return _toast_color_gray; case ToastType::Rose: return _toast_color_rose; case ToastType::Dark: return _toast_color_dark; default: return _toast_color_info; } } void Toast::init(lv_obj_t* parent) { auto toast_color = get_toast_color(config.type); _toast = std::make_unique(parent); _toast->setBorderWidth(2); _toast->setBorderColor(lv_color_hex(toast_color.border)); _toast->setBgColor(lv_color_hex(toast_color.bg)); _toast->setRadius(18); _toast->setAlign(LV_ALIGN_TOP_MID); _toast->removeFlag(LV_OBJ_FLAG_SCROLLABLE); _toast->onClick().connect([&]() { close(); }); _msg_label = std::make_unique