object-panels-w5: net change of 2 commits

- object-panels-w5: written from its sheet
- object-panels-w5: repair 1
This commit is contained in:
bflatastic
2026-11-21 23:35:43 +07:00
parent 2775f349af
commit a05005e736
5 changed files with 287 additions and 1040 deletions
File diff suppressed because it is too large Load Diff
@@ -3,12 +3,15 @@
//! rows ([Dynamic Text overview](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/dynamic-text-overview.html)
//! describes Block and its spacing between words and between lines).
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, Mixed, Props as _, Show as _, ShowContainer as _}; // PLAN: assumed `Mixed` re-export
use craft_ui::form::Field;
use craft_ui::text::{NumberField, StepArrows};
use egui::Ui;
use serde_json::{Value, json};
use vectorcraft_doc::{AreaOptions, NodeKind, TextKind};
use crate::VectorcraftApp;
use crate::widgets;
/// What the selected area type shows: whether Block is on in every frame (`None` when they
/// differ), the gaps every frame shares (`None` when they differ), and whether every frame can
@@ -58,25 +61,33 @@ fn run(app: &mut VectorcraftApp, p: Value) {
/// area type. Returns whether anything was drawn.
pub(crate) fn rows(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
let Some(s) = shown(app) else { return false };
if widgets::check(ui, tl!("Dynamic Text"), s.on == Some(true), s.enabled) {
run(app, json!({ "on": s.on != Some(true) }));
let on = s.on.map_or(Mixed::Mixed, Mixed::Same);
let out = Checkbox::new(Bind::given(on)).label(tl!("Dynamic Text")).enabled(s.enabled).show(ui);
if let Some(&on) = out.events.committed() {
run(app, json!({ "on": on }));
}
if s.on != Some(true) {
return true;
}
let fw = super::super::field_width(ui);
let (lo, hi) = AreaOptions::WORD_GAP;
ui.horizontal(|ui| {
ui.label(tl!("Word Gap"));
if let Some(v) = widgets::spin_plain_named(ui, "props-dt-word", Some(tl!("Word Gap")), s.word_gap, "%", 0, fw, 10.0, lo, &[]) {
Field::new(tl!("Word Gap")).show(ui, |ui, _| {
let out = NumberField::new(tl!("Word Gap"), Bind::given(s.word_gap))
.unit("%")
.fixed_decimals(0)
.range(lo..=hi)
.step(10.0)
.step_arrows(StepArrows::Leading)
.show(ui);
if let Some(Some(v)) = out.edit.events.committed() {
run(app, json!({ "wordGap": v.clamp(lo, hi) }));
}
});
let (lo, hi) = AreaOptions::LINE_GAP;
let unit = app.session.general_unit();
ui.horizontal(|ui| {
ui.label(tl!("Line Gap"));
if let Some(v) = widgets::spin_field_named(ui, "props-dt-line", Some(tl!("Line Gap")), s.line_gap, unit, fw, 1.0, lo, &[]) {
// PLAN: assumed `crate::panels::length_units(app) -> LengthUnits` (the general unit over points, as object-panels-w7's Keyboard Increment field builds it)
let lengths = crate::panels::length_units(app);
Field::new(tl!("Line Gap")).show(ui, |ui, _| {
let out = NumberField::length(tl!("Line Gap"), Bind::given(s.line_gap), lengths).range(lo..=hi).show(ui);
if let Some(Some(v)) = out.edit.events.committed() {
run(app, json!({ "lineGap": v.clamp(lo, hi) }));
}
});
+16 -32
View File
@@ -5,12 +5,14 @@
//! draws columns or bars, and Marker… when every one draws lines, scatter points or radar lines;
//! both run the same route as their Object › Graph items.
use craft_ui::buttons::Button;
use craft_ui::contract::{Props as _, Show as _, ShowContainer as _};
use craft_ui::layout_components::Row;
use craft_ui::sections::Section;
use egui::Ui;
use serde_json::json;
use vectorcraft_doc::{Document, GraphKind, MAX_GRAPH_SERIES, NodeId};
use crate::VectorcraftApp;
use crate::widgets::{self, divider, section_header};
/// The Graph section's optional buttons for the selection.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -74,37 +76,19 @@ fn series_of(doc: &Document, graph: NodeId, id: NodeId) -> Option<usize> {
}
}
/// The Graph section for the selection, with the divider after it; nothing without a graph.
/// The Graph section for the selection; nothing without a graph.
pub(crate) fn section(app: &mut VectorcraftApp, ui: &mut Ui) {
let Some(s) = shown(app) else { return };
section_header(ui, tl!("Graph"));
let mut buttons = vec![(tl!("Graph Type…"), "graph.setType"), (tl!("Graph Data…"), "graph.setData")];
if s.column {
buttons.push((tl!("Column…"), "graph.column"));
}
if s.marker {
buttons.push((tl!("Marker…"), "graph.marker"));
}
let full = ui.available_width();
let w = (full - 6.0) / 2.0;
for pair in buttons.chunks(2) {
// Two buttons share a row while both labels fit in half of it; a longer translated label
// puts each button of the pair on a row of its own.
if pair.iter().all(|(label, _)| widgets::flat_button_fit_width(ui, label, 0.0) <= w) {
ui.horizontal(|ui| {
for (label, id) in pair {
if widgets::flat_button(ui, label, w).clicked() {
crate::menus::invoke(app, id, json!({}));
}
}
});
} else {
for (label, id) in pair {
if widgets::flat_button_fit(ui, label, full).clicked() {
crate::menus::invoke(app, id, json!({}));
}
Section::fixed(tl!("Graph")).show(ui, |ui, _| {
Row::new().wrap(true).show(ui, |ui, _| {
Button::command("graph.setType").label(tl!("Graph Type…")).show(ui);
Button::command("graph.setData").label(tl!("Graph Data…")).show(ui);
if s.column {
Button::command("graph.column").label(tl!("Column…")).show(ui);
}
}
}
divider(ui);
if s.marker {
Button::command("graph.marker").label(tl!("Marker…")).show(ui);
}
});
});
}
@@ -0,0 +1,43 @@
//! The Properties panel's Character and Paragraph sections for the selected text.
use craft::text::ui::character::CharacterRows;
use craft_ui::contract::{Props as _, Show as _, ShowContainer as _};
use craft_ui::display::{Shade, Text};
use craft_ui::layout_components::Row;
use craft_ui::sections::Section;
use egui::Ui;
use vectorcraft_doc::NodeKind;
use super::{dynamic_text, more_options, vertical_align};
use crate::VectorcraftApp;
use crate::panels::{character, first_selected, paragraph};
/// The Character and Paragraph sections of the selected text; a note while no text is selected.
pub fn type_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
if !matches!(first_selected(app).as_deref().map(|n| &n.kind), Some(NodeKind::Text(_))) {
Text::new(tl!("Select a text object")).shade(Shade::Muted).show(ui);
return;
}
// The style of the Type tool's selection (or caret) when it edits text, else of the selected text's first run,
// as the Character panel shows it (#8189).
if character::text_style(app).is_none() {
return;
}
Section::fixed(tl!("Character")).show(ui, |ui, _| character::controls(app, ui, CharacterRows::PROPERTIES));
Section::fixed(tl!("Paragraph")).show(ui, |ui, _| {
// As in the Paragraph panel: the seven alignments and Hyphenate (#775), and area type's vertical alignment
// (#3759); the rest is there.
Row::new().show(ui, |ui, _| {
paragraph::alignment_toggles(app, ui, 7);
more_options(ui, "paragraph", tl!("More Paragraph options"));
});
if vertical_align::shown(app).is_some() {
Row::new().show(ui, |ui, _| {
vertical_align::buttons(app, ui);
});
}
paragraph::hyphenate_check(app, ui);
// Area type: Dynamic Text's Block and its gaps.
dynamic_text::rows(app, ui);
});
}
@@ -4,12 +4,14 @@
//! threaded ([Align text](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/align-text.html)),
//! so they are turned off when a selected frame has rows or columns or is threaded.
use craft_ui::buttons::ToggleButton;
use craft::behavior::{IconId, Mixed};
use craft_ui::contract::{Bind, Props as _, Show as _};
use egui::Ui;
use serde_json::json;
use vectorcraft_doc::{NodeKind, TextKind, VerticalAlign};
use crate::VectorcraftApp;
use crate::widgets;
/// The vertical alignment the selected area type shows, and whether the buttons can change it.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -47,7 +49,7 @@ pub(crate) fn shown(app: &VectorcraftApp) -> Option<Shown> {
/// it on every selected frame in one undo step (`text.areaOptions {verticalAlign}`, as Area Type
/// Options does, each frame keeping its other options). Turned off for frames with rows or columns
/// and threaded ones; nothing shows without area type. Returns whether the buttons were drawn.
pub(crate) fn buttons(app: &mut VectorcraftApp, ui: &mut Ui, size: f32) -> bool {
pub(crate) fn buttons(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
let Some(s) = shown(app) else { return false };
for (a, icon, tip, id) in [
(VerticalAlign::Top, "dc-al-top", tl!("Align Top"), "top"),
@@ -55,7 +57,9 @@ pub(crate) fn buttons(app: &mut VectorcraftApp, ui: &mut Ui, size: f32) -> bool
(VerticalAlign::Bottom, "dc-al-bottom", tl!("Align Bottom"), "bottom"),
(VerticalAlign::Justify, "dc-dist-vcenter", tl!("Justify Vertically"), "justify"),
] {
if widgets::icon_button_enabled(ui, icon, tip, s.enabled && s.shared == Some(a), s.enabled, size).clicked()
let on = s.shared.map_or(Mixed::Mixed, |shared| Mixed::Same(shared == a));
let out = ToggleButton::new(tip, Bind::given(on)).icon(IconId::new(icon)).icon_only().enabled(s.enabled).show(ui);
if out.events.committed().is_some()
&& let Err(e) = app.run("text.areaOptions", json!({ "verticalAlign": id }))
{
app.status(e);