Skip to content

Commit 86bc01b

Browse files
authored
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.
1 parent 5177532 commit 86bc01b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

capi/src/text_component.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
//! suitable for a situation where you have a label and a value.
44
55
use super::{output_vec, str, Json};
6-
use crate::component::OwnedComponent;
7-
use crate::text_component_state::OwnedTextComponentState;
8-
use livesplit_core::{component::text::Component as TextComponent, Timer};
6+
use crate::{component::OwnedComponent, text_component_state::OwnedTextComponentState};
7+
use livesplit_core::{
8+
component::text::{Component as TextComponent, Text},
9+
Timer,
10+
};
911
use std::os::raw::c_char;
1012

1113
/// type
@@ -38,6 +40,18 @@ pub extern "C" fn TextComponent_state_as_json(this: &TextComponent, timer: &Time
3840
})
3941
}
4042

43+
/// Switches the component to display the specified custom variable instead of a
44+
/// fixed text. The boolean indicates whether the name should also be shown as a
45+
/// key value pair.
46+
#[no_mangle]
47+
pub unsafe extern "C" fn TextComponent_use_variable(
48+
this: &mut TextComponent,
49+
variable: *const c_char,
50+
split: bool,
51+
) {
52+
this.settings_mut().text = Text::Variable(str(variable).into(), split);
53+
}
54+
4155
/// Sets the centered text. If the current mode is split, it is switched to
4256
/// centered mode.
4357
#[no_mangle]

0 commit comments

Comments
 (0)