Skip to content

Resource API

Declared by <huxerui/resource.h>.

ResourceId(domain, key) exposes Domain, Key, ToString, and equality. ImageResource, StringResource, and RawResource are distinct final ID types inheriting its constructors.

Retains direct text or a localized template for an API that composes the value after the call returns. Constructors accept empty, std::string, std::string_view, C string, or StringResource values. Format(resource, arguments...) retains positional formatted arguments.

UseString(StringResource, arguments...) resolves immediately to std::string. UseString(const StringVariant&) and UseString(StringVariant&&) resolve a retained value during the consumer’s composition. Prefer Text::Format(resource, ...) for Text, UseString(resource, ...) for an immediate string, and StringVariant::Format only for a parameter whose declared type is StringVariant.

Locale::FromLanguageTag, Locale::Default, and LanguageTag represent normalized locale choice. ResourceConfiguration contains locale and logical display_scale.

Factories: FromBytes, CopyBytes, and FromSharedBytes. Queries: Bytes, AsStringView, ToString, MimeType, HasValue, and handle equality.

Factories: FromFile, FromEncoded, and CopyEncoded, each with optional scale. Queries: EncodedBytes, Format, MimeType, pixel width/height, Scale, IntrinsicSize, HasValue, and handle equality. ImageFormat is Png or Jpeg; ImageSampling is Nearest or Linear.

UseRawResource, UseImage, and UseVectorImage resolve generated IDs through the current resource configuration. PlatformResources is the adapter interface exposing Configuration() and synchronous immutable package Read(path).

#include <huxerui/huxerui.h>
using namespace huxerui;
View InboxSummary(int unread_count) {
const StringResource title("app", "inbox_title");
const ImageResource cover("app", "inbox_cover");
return Column {
Text::Format(title, unread_count),
Button(UseString(title, unread_count)),
Image(cover).Fit(ImageFit::Cover),
}.With(Spacing(12.0F));
}

Text::Format resolves text owned by Text; UseString resolves an immediate string for Button; Image receives its resource ID directly.