Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Text Component to Variables via C API #847

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading