From 86bc01b32372e5b692dc9674af462f70da5b57f0 Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Sun, 27 Oct 2024 22:42:20 +0100 Subject: [PATCH] Switch Text Component to Variables via C API (#847) This adds the ability to switch the Text Component to use cusotm variables via the C API. --- capi/src/text_component.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/capi/src/text_component.rs b/capi/src/text_component.rs index ee68067d..9d98c0a1 100644 --- a/capi/src/text_component.rs +++ b/capi/src/text_component.rs @@ -3,9 +3,11 @@ //! suitable for a situation where you have a label and a value. use super::{output_vec, str, Json}; -use crate::component::OwnedComponent; -use crate::text_component_state::OwnedTextComponentState; -use livesplit_core::{component::text::Component as TextComponent, Timer}; +use crate::{component::OwnedComponent, text_component_state::OwnedTextComponentState}; +use livesplit_core::{ + component::text::{Component as TextComponent, Text}, + Timer, +}; use std::os::raw::c_char; /// type @@ -38,6 +40,18 @@ pub extern "C" fn TextComponent_state_as_json(this: &TextComponent, timer: &Time }) } +/// Switches the component to display the specified custom variable instead of a +/// fixed text. The boolean indicates whether the name should also be shown as a +/// key value pair. +#[no_mangle] +pub unsafe extern "C" fn TextComponent_use_variable( + this: &mut TextComponent, + variable: *const c_char, + split: bool, +) { + this.settings_mut().text = Text::Variable(str(variable).into(), split); +} + /// Sets the centered text. If the current mode is split, it is switched to /// centered mode. #[no_mangle]