pub struct StyleBuilder { /* private fields */ }
Expand description
Builds a style.
Implementations§
Source§impl StyleBuilder
impl StyleBuilder
Sourcepub fn rule(self, builder: RuleBuilder) -> Self
pub fn rule(self, builder: RuleBuilder) -> Self
Add a rule defined in a RuleBuilder
to the StyleBuilder
.
Sourcepub fn scope<S: AsRef<str>>(self, selector: S) -> Self
pub fn scope<S: AsRef<str>>(self, selector: S) -> Self
Prepend the given selector to all rules in this StyleBuilder
.
Sourcepub fn merge(self, builder: StyleBuilder) -> Self
pub fn merge(self, builder: StyleBuilder) -> Self
Merge with another StyleBuilder
.
Sourcepub fn component<C: Component>(self) -> Self
pub fn component<C: Component>(self) -> Self
Include the scoped style of a Component
in this StyleBuilder
.
Sourcepub async fn from_read_fn<P, R>(path: P, read: R) -> Result<Self>
pub async fn from_read_fn<P, R>(path: P, read: R) -> Result<Self>
Asynchronously load a stylesheet from a .pwss file. See the style module documentation on how to write .pwss files.
Sourcepub fn from_file<P>(path: P) -> Result<Self>
pub fn from_file<P>(path: P) -> Result<Self>
Synchronously load a stylesheet from a .pwss file. See the style module documentation on how to write .pwss files.
Sourcepub fn load_image(
&mut self,
key: impl Into<String>,
load: impl FnOnce() -> Result<RgbaImage> + 'static,
) -> ImageId
pub fn load_image( &mut self, key: impl Into<String>, load: impl FnOnce() -> Result<RgbaImage> + 'static, ) -> ImageId
Returns an ImageId
for the key
.
When the style is built, the image is loaded using the closure.
Sourcepub fn load_patch(
&mut self,
key: impl Into<String>,
load: impl FnOnce() -> Result<RgbaImage> + 'static,
) -> PatchId
pub fn load_patch( &mut self, key: impl Into<String>, load: impl FnOnce() -> Result<RgbaImage> + 'static, ) -> PatchId
Returns a PatchId
for the key
.
When the style is built, the 9-patch is loaded using the closure.
Sourcepub fn load_font(
&mut self,
key: impl Into<String>,
load: impl FnOnce() -> Result<Vec<u8>> + 'static,
) -> FontId
pub fn load_font( &mut self, key: impl Into<String>, load: impl FnOnce() -> Result<Vec<u8>> + 'static, ) -> FontId
Returns a FontId
for the key
.
When the style is built, the font is loaded using the closure.
The closure must return the bytes of a .ttf file.
Sourcepub fn load_image_async(
&mut self,
key: impl Into<String>,
fut: impl Future<Output = Result<RgbaImage>> + 'static,
) -> ImageId
pub fn load_image_async( &mut self, key: impl Into<String>, fut: impl Future<Output = Result<RgbaImage>> + 'static, ) -> ImageId
Returns an ImageId
for the key
.
When the style is built, the image is loaded by awaiting the future.
Sourcepub fn load_patch_async(
&mut self,
key: impl Into<String>,
fut: impl Future<Output = Result<RgbaImage>> + 'static,
) -> PatchId
pub fn load_patch_async( &mut self, key: impl Into<String>, fut: impl Future<Output = Result<RgbaImage>> + 'static, ) -> PatchId
Returns a PatchId
for the key
.
When the style is built, the 9-patch is loaded by awaiting the future.
Sourcepub fn load_font_async(
&mut self,
key: impl Into<String>,
fut: impl Future<Output = Result<Vec<u8>>> + 'static,
) -> FontId
pub fn load_font_async( &mut self, key: impl Into<String>, fut: impl Future<Output = Result<Vec<u8>>> + 'static, ) -> FontId
Returns a FontId
for the key
.
When the style is built, the font is loaded by awaiting the future.
The future must output the bytes of a .ttf file.
Sourcepub async fn build_async(self) -> Result<Style>
pub async fn build_async(self) -> Result<Style>
Builds the Style
. All loading of images, 9 patches and fonts happens in this method.
If any of them fail, an error is returned.