use super::validation::{assert_finite_f32, assert_finite_vec2};
use crate::scope::{NativeScopePop, NativeScopeToken};
use crate::{Ui, sys};
#[must_use]
pub struct IndentToken<'ui> {
scope: NativeScopeToken<'ui>,
}
impl IndentToken<'_> {
pub fn end(self) {}
}
impl Drop for IndentToken<'_> {
fn drop(&mut self) {
self.scope.finish();
}
}
impl Ui {
#[doc(alias = "SameLine")]
pub fn same_line(&self) {
self.same_line_with_pos(0.0);
}
#[doc(alias = "SameLine")]
pub fn same_line_with_pos(&self, pos_x: f32) {
self.same_line_with_spacing(pos_x, -1.0)
}
#[doc(alias = "SameLine")]
pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
assert_finite_f32("Ui::same_line_with_spacing()", "pos_x", pos_x);
assert_finite_f32("Ui::same_line_with_spacing()", "spacing_w", spacing_w);
self.run_with_bound_context(|| unsafe { sys::igSameLine(pos_x, spacing_w) });
}
#[doc(alias = "NewLine")]
pub fn new_line(&self) {
self.run_with_bound_context(|| unsafe { sys::igNewLine() });
}
#[doc(alias = "Spacing")]
pub fn spacing(&self) {
self.run_with_bound_context(|| unsafe { sys::igSpacing() });
}
#[doc(alias = "Dummy")]
pub fn dummy(&self, size: impl Into<[f32; 2]>) {
let size = size.into();
assert_finite_vec2("Ui::dummy()", "size", size);
let size_vec: sys::ImVec2 = size.into();
self.run_with_bound_context(|| unsafe { sys::igDummy(size_vec) });
}
#[doc(alias = "Indent")]
pub fn indent(&self) {
self.indent_by(0.0)
}
#[doc(alias = "Indent")]
pub fn indent_by(&self, width: f32) {
assert_finite_f32("Ui::indent_by()", "width", width);
self.run_with_bound_context(|| unsafe { sys::igIndent(width) });
}
#[doc(alias = "Indent")]
pub fn begin_indent(&self) -> IndentToken<'_> {
self.begin_indent_by(0.0)
}
#[doc(alias = "Indent")]
pub fn begin_indent_by(&self, width: f32) -> IndentToken<'_> {
assert_finite_f32("Ui::begin_indent_by()", "width", width);
let width = self.run_with_bound_context(|| unsafe {
let width = if width == 0.0 {
(*sys::igGetStyle()).IndentSpacing
} else {
width
};
sys::igIndent(width);
width
});
IndentToken {
scope: self
.begin_provenance_native_scope(NativeScopePop::Unindent(width), "IndentToken"),
}
}
#[doc(alias = "Indent", alias = "Unindent")]
pub fn with_indent<R>(&self, f: impl FnOnce() -> R) -> R {
let indent = self.begin_indent();
let result = f();
drop(indent);
result
}
#[doc(alias = "Indent", alias = "Unindent")]
pub fn with_indent_by<R>(&self, width: f32, f: impl FnOnce() -> R) -> R {
let indent = self.begin_indent_by(width);
let result = f();
drop(indent);
result
}
#[doc(alias = "Unindent")]
pub fn unindent(&self) {
self.unindent_by(0.0)
}
#[doc(alias = "Unindent")]
pub fn unindent_by(&self, width: f32) {
assert_finite_f32("Ui::unindent_by()", "width", width);
self.run_with_bound_context(|| unsafe { sys::igUnindent(width) });
}
}
impl Ui {
#[doc(alias = "AlignTextToFramePadding")]
pub fn align_text_to_frame_padding(&self) {
self.run_with_bound_context(|| unsafe { sys::igAlignTextToFramePadding() });
}
}