* Apply an attribute NWidgetPart to an NWidget. * @param nwid Attribute NWidgetPart * @param dest NWidget to apply attribute to. * @pre NWidgetPart must be an attribute NWidgetPart. */
| 3164 | * @pre NWidgetPart must be an attribute NWidgetPart. |
| 3165 | */ |
| 3166 | void ApplyNWidgetPartAttribute(const NWidgetPart &nwid, NWidgetBase *dest) |
| 3167 | { |
| 3168 | switch (nwid.type) { |
| 3169 | case WPT_RESIZE: { |
| 3170 | NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest); |
| 3171 | if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_RESIZE requires NWidgetResizeBase"); |
| 3172 | assert(nwid.u.xy.x >= 0 && nwid.u.xy.y >= 0); |
| 3173 | nwrb->SetResize(nwid.u.xy.x, nwid.u.xy.y); |
| 3174 | break; |
| 3175 | } |
| 3176 | |
| 3177 | case WPT_MINSIZE: { |
| 3178 | NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest); |
| 3179 | if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_MINSIZE requires NWidgetResizeBase"); |
| 3180 | assert(nwid.u.xy.x >= 0 && nwid.u.xy.y >= 0); |
| 3181 | nwrb->SetMinimalSize(nwid.u.xy.x, nwid.u.xy.y); |
| 3182 | break; |
| 3183 | } |
| 3184 | |
| 3185 | case WPT_MINTEXTLINES: { |
| 3186 | NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest); |
| 3187 | if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_MINTEXTLINES requires NWidgetResizeBase"); |
| 3188 | assert(nwid.u.text_lines.size >= FS_BEGIN && nwid.u.text_lines.size < FS_END); |
| 3189 | nwrb->SetMinimalTextLines(nwid.u.text_lines.lines, nwid.u.text_lines.spacing, nwid.u.text_lines.size); |
| 3190 | break; |
| 3191 | } |
| 3192 | |
| 3193 | case WPT_TOOLBARSIZE: { |
| 3194 | NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest); |
| 3195 | if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_TOOLBARSIZE requires NWidgetResizeBase"); |
| 3196 | assert(nwid.u.xy.x >= 0); |
| 3197 | nwrb->SetToolbarMinimalSize(nwid.u.xy.x); |
| 3198 | break; |
| 3199 | } |
| 3200 | |
| 3201 | case WPT_TEXTSTYLE: { |
| 3202 | NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest); |
| 3203 | if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_TEXTSTYLE requires NWidgetCore"); |
| 3204 | nwc->SetTextStyle(nwid.u.text_style.colour, nwid.u.text_style.size); |
| 3205 | break; |
| 3206 | } |
| 3207 | |
| 3208 | case WPT_ALIGNMENT: { |
| 3209 | NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest); |
| 3210 | if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_ALIGNMENT requires NWidgetCore"); |
| 3211 | nwc->SetAlignment(nwid.u.align.align); |
| 3212 | break; |
| 3213 | } |
| 3214 | |
| 3215 | case WPT_FILL: { |
| 3216 | NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest); |
| 3217 | if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_FILL requires NWidgetResizeBase"); |
| 3218 | nwrb->SetFill(nwid.u.xy.x, nwid.u.xy.y); |
| 3219 | break; |
| 3220 | } |
| 3221 | |
| 3222 | case WPT_DATATIP: { |
| 3223 | NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest); |
no test coverage detected