feat(textstyle): full Text Style editor — big/TT font, fixed height, flags, annotative
Expands the Text Style manager beyond font/width/oblique: big-font and TrueType font fields, fixed text height, Backward / Upside-down flags, and an Annotative toggle (applied live). Bumps acadrust for the annotative field. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
8b3d083789
commit
52850947d2
5 changed files with 131 additions and 39 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -54,7 +54,7 @@ checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "acadrust"
|
name = "acadrust"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
source = "git+https://github.com/HakanSeven12/acadrust?branch=main#5b09ccc00d92bb55dcccbef97c0fcecf94417e16"
|
source = "git+https://github.com/HakanSeven12/acadrust?branch=main#c117f98c3d33dc173e3ee01f39a7729d58bc0347"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,12 @@ pub(super) struct OpenCADStudio {
|
||||||
textstyle_width: String,
|
textstyle_width: String,
|
||||||
/// Edit buffer for oblique angle (degrees).
|
/// Edit buffer for oblique angle (degrees).
|
||||||
textstyle_oblique: String,
|
textstyle_oblique: String,
|
||||||
|
/// Edit buffer for fixed text height (0 = variable).
|
||||||
|
textstyle_height: String,
|
||||||
|
/// Edit buffer for big-font file name.
|
||||||
|
textstyle_bigfont: String,
|
||||||
|
/// Edit buffer for TrueType font name.
|
||||||
|
textstyle_ttf: String,
|
||||||
|
|
||||||
// ── Color Scheme ──────────────────────────────────────────────────────
|
// ── Color Scheme ──────────────────────────────────────────────────────
|
||||||
active_theme: Theme,
|
active_theme: Theme,
|
||||||
|
|
@ -880,6 +886,9 @@ pub enum Message {
|
||||||
TextStyleApply,
|
TextStyleApply,
|
||||||
/// Select a font from the built-in font list.
|
/// Select a font from the built-in font list.
|
||||||
TextStyleFontPick(String),
|
TextStyleFontPick(String),
|
||||||
|
/// Flip a boolean flag on the selected text style (backward / upside_down /
|
||||||
|
/// vertical / annotative), applied immediately.
|
||||||
|
TextStyleToggle(&'static str),
|
||||||
// ── TableStyle Dialog ─────────────────────────────────────────────────
|
// ── TableStyle Dialog ─────────────────────────────────────────────────
|
||||||
TableStyleDialogOpen,
|
TableStyleDialogOpen,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -1053,6 +1062,9 @@ impl OpenCADStudio {
|
||||||
textstyle_font: String::new(),
|
textstyle_font: String::new(),
|
||||||
textstyle_width: "1.0".to_string(),
|
textstyle_width: "1.0".to_string(),
|
||||||
textstyle_oblique: "0.0".to_string(),
|
textstyle_oblique: "0.0".to_string(),
|
||||||
|
textstyle_height: "0.0".to_string(),
|
||||||
|
textstyle_bigfont: String::new(),
|
||||||
|
textstyle_ttf: String::new(),
|
||||||
// TableStyle dialog
|
// TableStyle dialog
|
||||||
tablestyle_selected: "Standard".to_string(),
|
tablestyle_selected: "Standard".to_string(),
|
||||||
// MLineStyle dialog
|
// MLineStyle dialog
|
||||||
|
|
|
||||||
|
|
@ -5634,10 +5634,31 @@ impl OpenCADStudio {
|
||||||
"font" => self.textstyle_font = value,
|
"font" => self.textstyle_font = value,
|
||||||
"width" => self.textstyle_width = value,
|
"width" => self.textstyle_width = value,
|
||||||
"oblique" => self.textstyle_oblique = value,
|
"oblique" => self.textstyle_oblique = value,
|
||||||
|
"height" => self.textstyle_height = value,
|
||||||
|
"bigfont" => self.textstyle_bigfont = value,
|
||||||
|
"ttf" => self.textstyle_ttf = value,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::TextStyleToggle(field) => {
|
||||||
|
let i = self.active_tab;
|
||||||
|
let name = self.textstyle_selected.clone();
|
||||||
|
if self.tabs[i].scene.document.text_styles.get(&name).is_some() {
|
||||||
|
self.push_undo_snapshot(i, "STYLE EDIT");
|
||||||
|
if let Some(s) = self.tabs[i].scene.document.text_styles.get_mut(&name) {
|
||||||
|
match field {
|
||||||
|
"backward" => s.flags.backward = !s.flags.backward,
|
||||||
|
"upside_down" => s.flags.upside_down = !s.flags.upside_down,
|
||||||
|
"annotative" => s.annotative = !s.annotative,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.tabs[i].scene.bump_geometry();
|
||||||
|
self.tabs[i].dirty = true;
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
Message::TextStyleApply => {
|
Message::TextStyleApply => {
|
||||||
let i = self.active_tab;
|
let i = self.active_tab;
|
||||||
let name = self.textstyle_selected.clone();
|
let name = self.textstyle_selected.clone();
|
||||||
|
|
@ -5646,15 +5667,24 @@ impl OpenCADStudio {
|
||||||
let font = self.textstyle_font.clone();
|
let font = self.textstyle_font.clone();
|
||||||
let width_str = self.textstyle_width.clone();
|
let width_str = self.textstyle_width.clone();
|
||||||
let oblique_str = self.textstyle_oblique.clone();
|
let oblique_str = self.textstyle_oblique.clone();
|
||||||
|
let height_str = self.textstyle_height.clone();
|
||||||
|
let bigfont = self.textstyle_bigfont.clone();
|
||||||
|
let ttf = self.textstyle_ttf.clone();
|
||||||
if let Some(s) = self.tabs[i].scene.document.text_styles.get_mut(&name) {
|
if let Some(s) = self.tabs[i].scene.document.text_styles.get_mut(&name) {
|
||||||
s.font_file = font;
|
s.font_file = font;
|
||||||
|
s.big_font_file = bigfont;
|
||||||
|
s.true_type_font = ttf;
|
||||||
if let Ok(w) = width_str.trim().parse::<f64>() {
|
if let Ok(w) = width_str.trim().parse::<f64>() {
|
||||||
s.width_factor = w;
|
s.width_factor = w;
|
||||||
}
|
}
|
||||||
if let Ok(a) = oblique_str.trim().parse::<f64>() {
|
if let Ok(a) = oblique_str.trim().parse::<f64>() {
|
||||||
s.oblique_angle = a.to_radians();
|
s.oblique_angle = a.to_radians();
|
||||||
}
|
}
|
||||||
|
if let Ok(h) = height_str.trim().parse::<f64>() {
|
||||||
|
s.height = h.max(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
self.tabs[i].scene.bump_geometry();
|
||||||
self.tabs[i].dirty = true;
|
self.tabs[i].dirty = true;
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
|
|
@ -6635,6 +6665,9 @@ impl OpenCADStudio {
|
||||||
self.textstyle_font = s.font_file.clone();
|
self.textstyle_font = s.font_file.clone();
|
||||||
self.textstyle_width = format!("{:.4}", s.width_factor);
|
self.textstyle_width = format!("{:.4}", s.width_factor);
|
||||||
self.textstyle_oblique = format!("{:.2}", s.oblique_angle.to_degrees());
|
self.textstyle_oblique = format!("{:.2}", s.oblique_angle.to_degrees());
|
||||||
|
self.textstyle_height = format!("{:.4}", s.height);
|
||||||
|
self.textstyle_bigfont = s.big_font_file.clone();
|
||||||
|
self.textstyle_ttf = s.true_type_font.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,13 +65,26 @@ impl OpenCADStudio {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.name.clone())
|
.map(|s| s.name.clone())
|
||||||
.collect();
|
.collect();
|
||||||
return crate::ui::textstyle::view_window(
|
let (backward, upside_down, annotative) = tab
|
||||||
|
.scene
|
||||||
|
.document
|
||||||
|
.text_styles
|
||||||
|
.get(&self.textstyle_selected)
|
||||||
|
.map(|s| (s.flags.backward, s.flags.upside_down, s.annotative))
|
||||||
|
.unwrap_or((false, false, false));
|
||||||
|
return crate::ui::textstyle::view_window(crate::ui::textstyle::TextStyleView {
|
||||||
styles,
|
styles,
|
||||||
&self.textstyle_selected,
|
selected: &self.textstyle_selected,
|
||||||
&self.textstyle_font,
|
font_buf: &self.textstyle_font,
|
||||||
&self.textstyle_width,
|
width_buf: &self.textstyle_width,
|
||||||
&self.textstyle_oblique,
|
oblique_buf: &self.textstyle_oblique,
|
||||||
);
|
height_buf: &self.textstyle_height,
|
||||||
|
bigfont_buf: &self.textstyle_bigfont,
|
||||||
|
ttf_buf: &self.textstyle_ttf,
|
||||||
|
backward,
|
||||||
|
upside_down,
|
||||||
|
annotative,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if Some(window_id) == self.tablestyle_window {
|
if Some(window_id) == self.tablestyle_window {
|
||||||
use acadrust::objects::ObjectType;
|
use acadrust::objects::ObjectType;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,24 @@
|
||||||
//! Text Style Font Browser window — fills the entire OS window.
|
//! Text Style Font Browser window — fills the entire OS window.
|
||||||
|
|
||||||
use crate::app::Message;
|
use crate::app::Message;
|
||||||
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
use iced::widget::{button, checkbox, column, container, row, scrollable, text, text_input, Space};
|
||||||
use iced::{Background, Border, Color, Element, Fill, Theme};
|
use iced::{Background, Border, Color, Element, Fill, Theme};
|
||||||
|
|
||||||
|
/// View-model for the Text Style editor window.
|
||||||
|
pub struct TextStyleView<'a> {
|
||||||
|
pub styles: Vec<String>,
|
||||||
|
pub selected: &'a str,
|
||||||
|
pub font_buf: &'a str,
|
||||||
|
pub width_buf: &'a str,
|
||||||
|
pub oblique_buf: &'a str,
|
||||||
|
pub height_buf: &'a str,
|
||||||
|
pub bigfont_buf: &'a str,
|
||||||
|
pub ttf_buf: &'a str,
|
||||||
|
pub backward: bool,
|
||||||
|
pub upside_down: bool,
|
||||||
|
pub annotative: bool,
|
||||||
|
}
|
||||||
|
|
||||||
const TB: Color = Color {
|
const TB: Color = Color {
|
||||||
r: 0.13,
|
r: 0.13,
|
||||||
g: 0.13,
|
g: 0.13,
|
||||||
|
|
@ -169,13 +184,20 @@ fn vsep<'a>() -> Element<'a, Message> {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view_window<'a>(
|
pub fn view_window<'a>(v: TextStyleView<'a>) -> Element<'a, Message> {
|
||||||
styles: Vec<String>,
|
let TextStyleView {
|
||||||
selected: &'a str,
|
styles,
|
||||||
font_buf: &'a str,
|
selected,
|
||||||
width_buf: &'a str,
|
font_buf,
|
||||||
oblique_buf: &'a str,
|
width_buf,
|
||||||
) -> Element<'a, Message> {
|
oblique_buf,
|
||||||
|
height_buf,
|
||||||
|
bigfont_buf,
|
||||||
|
ttf_buf,
|
||||||
|
backward,
|
||||||
|
upside_down,
|
||||||
|
annotative,
|
||||||
|
} = v;
|
||||||
// ── Toolbar ───────────────────────────────────────────────────────────
|
// ── Toolbar ───────────────────────────────────────────────────────────
|
||||||
let toolbar = container(
|
let toolbar = container(
|
||||||
row![
|
row![
|
||||||
|
|
@ -296,36 +318,48 @@ pub fn view_window<'a>(
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.padding([12, 8]);
|
.padding([12, 8]);
|
||||||
|
|
||||||
|
// Labeled numeric/text field row → TextStyleEdit { field, value }.
|
||||||
|
fn frow<'a>(label: &'a str, ph: &'a str, buf: &'a str, field: &'static str) -> Element<'a, Message> {
|
||||||
|
row![
|
||||||
|
text(label).size(11).color(DIM).width(120),
|
||||||
|
text_input(ph, buf)
|
||||||
|
.on_input(move |v| Message::TextStyleEdit { field, value: v })
|
||||||
|
.style(field_style)
|
||||||
|
.size(11)
|
||||||
|
.width(140),
|
||||||
|
]
|
||||||
|
.spacing(6)
|
||||||
|
.align_y(iced::Center)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
// ── Right: Properties ─────────────────────────────────────────────────
|
// ── Right: Properties ─────────────────────────────────────────────────
|
||||||
let props_panel = container(
|
let props_panel = container(
|
||||||
column![
|
column![
|
||||||
text("Properties").size(11).color(ACCENT),
|
text("Properties").size(11).color(ACCENT),
|
||||||
|
frow("Big Font:", "big-font file…", bigfont_buf, "bigfont"),
|
||||||
|
frow("TrueType Font:", "e.g. Arial", ttf_buf, "ttf"),
|
||||||
|
frow("Fixed Height:", "0 = variable", height_buf, "height"),
|
||||||
|
frow("Width Factor:", "1.0", width_buf, "width"),
|
||||||
|
frow("Oblique (°):", "0.0", oblique_buf, "oblique"),
|
||||||
row![
|
row![
|
||||||
text("Width Factor:").size(11).color(DIM).width(120),
|
checkbox(backward)
|
||||||
text_input("1.0", width_buf)
|
.label("Backward")
|
||||||
.on_input(|v| Message::TextStyleEdit {
|
.on_toggle(|_| Message::TextStyleToggle("backward"))
|
||||||
field: "width",
|
.size(15)
|
||||||
value: v
|
.text_size(11),
|
||||||
})
|
checkbox(upside_down)
|
||||||
.style(field_style)
|
.label("Upside down")
|
||||||
.size(11)
|
.on_toggle(|_| Message::TextStyleToggle("upside_down"))
|
||||||
.width(90),
|
.size(15)
|
||||||
|
.text_size(11),
|
||||||
]
|
]
|
||||||
.spacing(6)
|
.spacing(16),
|
||||||
.align_y(iced::Center),
|
checkbox(annotative)
|
||||||
row![
|
.label("Annotative")
|
||||||
text("Oblique (°):").size(11).color(DIM).width(120),
|
.on_toggle(|_| Message::TextStyleToggle("annotative"))
|
||||||
text_input("0.0", oblique_buf)
|
.size(15)
|
||||||
.on_input(|v| Message::TextStyleEdit {
|
.text_size(11),
|
||||||
field: "oblique",
|
|
||||||
value: v
|
|
||||||
})
|
|
||||||
.style(field_style)
|
|
||||||
.size(11)
|
|
||||||
.width(90),
|
|
||||||
]
|
|
||||||
.spacing(6)
|
|
||||||
.align_y(iced::Center),
|
|
||||||
Space::new().height(8),
|
Space::new().height(8),
|
||||||
text("Preview").size(10).color(DIM),
|
text("Preview").size(10).color(DIM),
|
||||||
container(text("AaBbCc 0123").size(20))
|
container(text("AaBbCc 0123").size(20))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue