Skip to content

Commit

Permalink
Switch Text Component to Variables via C API (#847)
Browse files Browse the repository at this point in the history
This adds the ability to switch the Text Component to use cusotm
variables via the C API.
  • Loading branch information
CryZe authored Oct 27, 2024
1 parent 5177532 commit 86bc01b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions capi/src/text_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 86bc01b

Please sign in to comment.