diff --git a/fyrox-ui/src/button.rs b/fyrox-ui/src/button.rs index 8ee8ab772..a275514f6 100644 --- a/fyrox-ui/src/button.rs +++ b/fyrox-ui/src/button.rs @@ -223,6 +223,8 @@ pub enum ButtonContent { text: String, /// Optional font of the button. If [`None`], the default font will be used. font: Option, + /// Font size of the text. Default is 14.0 + size: f32, }, /// Arbitrary widget handle. It could be any widget handle, for example a handle of [`crate::image::Image`] /// widget. @@ -235,6 +237,7 @@ impl ButtonContent { Self::Text { text: s.as_ref().to_owned(), font: None, + size: 14.0, } } @@ -243,6 +246,16 @@ impl ButtonContent { Self::Text { text: s.as_ref().to_owned(), font: Some(font), + size: 14.0, + } + } + + /// Creates [`ButtonContent::Text`] with custom font and size. + pub fn text_with_font_size>(s: S, font: FontResource, size: f32) -> Self { + Self::Text { + text: s.as_ref().to_owned(), + font: Some(font), + size, } } @@ -253,11 +266,12 @@ impl ButtonContent { fn build(&self, ctx: &mut BuildContext) -> Handle { match self { - Self::Text { text, font } => TextBuilder::new(WidgetBuilder::new()) + Self::Text { text, font, size } => TextBuilder::new(WidgetBuilder::new()) .with_text(text) .with_horizontal_text_alignment(HorizontalAlignment::Center) .with_vertical_text_alignment(VerticalAlignment::Center) .with_font(font.clone().unwrap_or_else(|| ctx.default_font())) + .with_font_size(*size) .build(ctx), Self::Node(node) => *node, } @@ -297,6 +311,12 @@ impl ButtonBuilder { self } + /// Sets the content of the button to be [`ButtonContent::Text`] (text with a custom font and size). + pub fn with_text_and_font_size(mut self, text: &str, font: FontResource, size: f32) -> Self { + self.content = Some(ButtonContent::text_with_font_size(text, font, size)); + self + } + /// Sets the content of the button to be [`ButtonContent::Node`] (arbitrary widget handle). pub fn with_content(mut self, node: Handle) -> Self { self.content = Some(ButtonContent::Node(node));