use crate::oxml::shape::Sp as OxmlSp;
use crate::oxml::simpletypes::PresetGeometry;
use crate::oxml::txbody::{Paragraph, TextBody};
use crate::shape::autoshape::AutoShape;
use crate::shape::base::Shape;
use crate::units::Emu;
#[derive(Clone, Debug, Default)]
pub struct TextBox {
pub(crate) shape: AutoShape,
}
impl TextBox {
pub fn new(name: impl Into<String>) -> Self {
let mut s = AutoShape::new(name, PresetGeometry::Rectangle);
s.sp_mut().text = TextBody::new();
TextBox { shape: s }
}
pub fn from_sp(sp: OxmlSp) -> Self {
TextBox {
shape: AutoShape::from_sp(sp),
}
}
pub fn text_frame(&self) -> &TextBody {
&self.shape.sp.text
}
pub fn text_frame_mut(&mut self) -> &mut TextBody {
&mut self.shape.sp_mut().text
}
pub fn set_text(&mut self, text: &str) -> &mut TextBody {
let tb = self.text_frame_mut();
tb.paragraphs.clear();
for line in text.split('\n') {
let mut p = Paragraph::new();
p.runs.push(crate::oxml::txbody::Run::new(line));
tb.paragraphs.push(p);
}
tb
}
pub fn text(&self) -> String {
let mut out = String::new();
let mut first = true;
for p in &self.text_frame().paragraphs {
if !first {
out.push('\n');
}
first = false;
for r in &p.runs {
out.push_str(&r.text);
}
}
out
}
pub fn set_word_wrap(&mut self, v: bool) {
self.text_frame_mut().set_word_wrap(v);
}
pub fn set_auto_size(&mut self, v: crate::oxml::simpletypes::MsoAutoSize) {
self.text_frame_mut().set_auto_size(v);
}
pub fn set_vertical_anchor(&mut self, v: crate::oxml::simpletypes::MsoAnchor) {
self.text_frame_mut().set_vertical_anchor(v);
}
pub fn set_outer_shadow(&mut self, shadow: crate::oxml::sppr::ShadowEffect) {
self.shape.set_outer_shadow(shadow);
}
pub fn set_inner_shadow(&mut self, shadow: crate::oxml::sppr::ShadowEffect) {
self.shape.set_inner_shadow(shadow);
}
pub fn set_glow(&mut self, glow: crate::oxml::sppr::GlowEffect) {
self.shape.set_glow(glow);
}
pub fn set_soft_edge(&mut self, rad: i64) {
self.shape.set_soft_edge(rad);
}
pub fn set_reflection(&mut self, reflection: crate::oxml::sppr::ReflectionEffect) {
self.shape.set_reflection(reflection);
}
pub fn clear_effects(&mut self) {
self.shape.clear_effects();
}
pub fn set_3d_rotation(&mut self, lat_deg: f64, lon_deg: f64, rev_deg: f64) {
self.shape.set_3d_rotation(lat_deg, lon_deg, rev_deg);
}
pub fn set_3d_extrusion(&mut self, height_emu: i32, color: Option<crate::oxml::color::Color>) {
self.shape.set_3d_extrusion(height_emu, color);
}
pub fn set_3d_bevel(&mut self, top_w: i32, top_h: i32, bottom_w: i32, bottom_h: i32) {
self.shape.set_3d_bevel(top_w, top_h, bottom_w, bottom_h);
}
pub fn set_3d_material(&mut self, material: crate::oxml::sppr::MaterialPreset) {
self.shape.set_3d_material(material);
}
pub fn clear_3d(&mut self) {
self.shape.clear_3d();
}
pub fn scene_3d(&self) -> Option<&crate::oxml::sppr::Scene3d> {
self.shape.scene_3d()
}
pub fn scene_3d_mut(&mut self) -> &mut Option<crate::oxml::sppr::Scene3d> {
self.shape.scene_3d_mut()
}
pub fn sp_3d(&self) -> Option<&crate::oxml::sppr::Sp3d> {
self.shape.sp_3d()
}
pub fn sp_3d_mut(&mut self) -> &mut Option<crate::oxml::sppr::Sp3d> {
self.shape.sp_3d_mut()
}
pub fn locks(&self) -> Option<&crate::oxml::shape::ShapeLocks> {
self.shape.locks()
}
pub fn locks_mut(&mut self) -> &mut crate::oxml::shape::ShapeLocks {
self.shape.locks_mut()
}
pub fn lock_select(&mut self, locked: bool) {
self.shape.lock_select(locked);
}
pub fn lock_move(&mut self, locked: bool) {
self.shape.lock_move(locked);
}
pub fn lock_resize(&mut self, locked: bool) {
self.shape.lock_resize(locked);
}
pub fn lock_rotate(&mut self, locked: bool) {
self.shape.lock_rotate(locked);
}
pub fn lock_group(&mut self, locked: bool) {
self.shape.lock_group(locked);
}
pub fn clear_locks(&mut self) {
self.shape.clear_locks();
}
pub fn set_lock(&mut self, lock_type: crate::oxml::shape::LockType, locked: bool) {
self.shape.set_lock(lock_type, locked);
}
pub fn style(&self) -> Option<&crate::oxml::shape::ShapeStyle> {
self.shape.style()
}
pub fn set_style(&mut self, style: crate::oxml::shape::ShapeStyle) {
self.shape.set_style(style);
}
pub fn clear_style(&mut self) {
self.shape.clear_style();
}
}
impl Shape for TextBox {
fn id(&self) -> u32 {
self.shape.id()
}
fn set_id(&mut self, id: u32) {
self.shape.set_id(id);
}
fn name(&self) -> &str {
self.shape.name()
}
fn set_name(&mut self, name: String) {
self.shape.set_name(name);
}
fn shape_type(&self) -> &'static str {
"text_box"
}
fn left(&self) -> Emu {
self.shape.left()
}
fn set_left(&mut self, emu: Emu) {
self.shape.set_left(emu);
}
fn top(&self) -> Emu {
self.shape.top()
}
fn set_top(&mut self, emu: Emu) {
self.shape.set_top(emu);
}
fn width(&self) -> Emu {
self.shape.width()
}
fn set_width(&mut self, emu: Emu) {
self.shape.set_width(emu);
}
fn height(&self) -> Emu {
self.shape.height()
}
fn set_height(&mut self, emu: Emu) {
self.shape.set_height(emu);
}
fn rotation(&self) -> f64 {
self.shape.rotation()
}
fn set_rotation(&mut self, deg: f64) {
self.shape.set_rotation(deg);
}
}