| 26 | ImageDisplay::ImageDisplay(GUIManager& gui): Element(gui) {} |
| 27 | |
| 28 | void ImageDisplay::layout(const Clay_ElementId& id, const Data& data) { |
| 29 | if(data != d) { |
| 30 | d = data; |
| 31 | std::string imgData; |
| 32 | try { |
| 33 | imgData = read_file_to_string(data.imgPath); |
| 34 | auto codec = SkCodec::MakeFromData(SkData::MakeWithoutCopy(imgData.c_str(), imgData.size()), { |
| 35 | SkJpegDecoder::Decoder() |
| 36 | }); |
| 37 | img = std::get<0>(codec->getImage()); |
| 38 | } catch(...) { |
| 39 | img = nullptr; |
| 40 | } |
| 41 | gui.invalidate_draw_element(this); |
| 42 | } |
| 43 | |
| 44 | CLAY(id, { |
| 45 | .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}, |
| 46 | .custom = {.customData = this} |
| 47 | }) { |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void ImageDisplay::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) { |
| 52 | if(img) { |
nothing calls this directly
no test coverage detected