Skip to content

Commit e56c916

Browse files
authored
Merge pull request #2645 from storytold/fix/2075-stroke-width-control
Character panel: the stroke width shows its icon and a presets menu (#2075)
2 parents 5abef26 + 5085a1c commit e56c916

3 files changed

Lines changed: 58 additions & 9 deletions

File tree

‎crates/ui-egui/src/icons.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ pub enum Icon {
112112
Fullscreen,
113113
Channel,
114114
Exposure,
115+
/// Stroke width: three bars, thin to thick.
116+
StrokeWidth,
115117
// links
116118
Chat,
117119
Globe,
@@ -548,6 +550,11 @@ pub fn paint(painter: &Painter, rect: Rect, icon: Icon, color: Color32) {
548550
}
549551
pen.circle(8.0, 8.0, 4.2);
550552
}
553+
StrokeWidth => {
554+
pen.rect_fill(2.5, 3.0, 13.5, 3.75);
555+
pen.rect_fill(2.5, 6.5, 13.5, 8.0);
556+
pen.rect_fill(2.5, 10.5, 13.5, 13.0);
557+
}
551558
Hamburger => {
552559
for y in [4.5, 8.0, 11.5] {
553560
pen.line(&[(3.0, y), (13.0, y)]);

‎crates/ui-egui/src/panels/text_panels.rs‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,21 @@ fn numeric_fields(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
127127
let row = i / 2;
128128
let fx = x0 + col as f32 * (w / 2.0);
129129
let fy = y + row as f32 * 28.0;
130-
p.text(pos2(fx, fy + 9.0), Align2::LEFT_CENTER, glyph, Tokens::semibold(11.0), t.text_dim);
131-
let (r, nv, _) = widgets::hot_number_at(
132-
ui,
133-
pos2(fx + 26.0, fy),
134-
egui::Id::unique(("char", key)),
135-
v,
136-
&widgets::HotSpec { speed: 0.5, range, decimals: 0, suffix },
137-
&t,
138-
);
130+
let stroke = key == "strokeWidth";
131+
if stroke {
132+
// The stroke-width icon, as in After Effects, not a letter that reads as "width".
133+
crate::icons::paint(p, Rect::from_min_size(pos2(fx, fy + 1.0), vec2(18.0, 18.0)), crate::icons::Icon::StrokeWidth, t.text_dim);
134+
} else {
135+
p.text(pos2(fx, fy + 9.0), Align2::LEFT_CENTER, glyph, Tokens::semibold(11.0), t.text_dim);
136+
}
137+
// Fractional stroke widths (the 0.25 / 0.5 / 0.75 presets) show their decimals.
138+
let decimals = if stroke && v.fract().abs() > 1e-9 { 2 } else { 0 };
139+
let (r, nv, _) =
140+
widgets::hot_number_at(ui, pos2(fx + 26.0, fy), egui::Id::unique(("char", key)), v, &widgets::HotSpec { speed: 0.5, range, decimals, suffix }, &t);
139141
app.auto.add(&format!("character.{key}"), r, key);
142+
if stroke {
143+
stroke_width_presets(app, ui, r, enabled, actions);
144+
}
140145
if let Some(nv) = nv
141146
&& enabled
142147
{
@@ -145,6 +150,26 @@ fn numeric_fields(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
145150
}
146151
}
147152

153+
/// The stroke width's presets menu beside its value (`r`), as in After Effects.
154+
fn stroke_width_presets(app: &mut EffectcraftApp, ui: &mut egui::Ui, r: Rect, enabled: bool, actions: &mut Vec<serde_json::Value>) {
155+
const PRESETS: [f64; 22] = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0];
156+
let t = app.tokens;
157+
let br = Rect::from_min_size(pos2(r.max.x + 4.0, r.min.y + 2.0), vec2(16.0, 16.0));
158+
let pop = egui::Id::unique("char-stroke-width-pop");
159+
if widgets::icon_button(ui, br, crate::icons::Icon::ChevronDown, false, &t, egui::Id::unique("char-stroke-width-presets"))
160+
.on_hover_text(tr("Stroke width presets"))
161+
.clicked()
162+
&& enabled
163+
{
164+
widgets::open_popup(ui, pop);
165+
}
166+
app.auto.add("character.strokeWidth.presets", br, "Stroke width presets");
167+
let labels: Vec<String> = PRESETS.iter().map(|v| format!("{v} px")).collect();
168+
if let Some(v) = widgets::popup_menu(ui, pop, br.left_bottom(), &labels, None).and_then(|i| PRESETS.get(i)) {
169+
actions.push(json!({"strokeWidth": v}));
170+
}
171+
}
172+
148173
/// Kerning: Metrics / Optical / a manual value (grid row 1, left).
149174
fn kerning_field(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, g: Grid, doc: &TextDoc, actions: &mut Vec<serde_json::Value>) {
150175
let t = app.tokens;

‎crates/ui-egui/tests/it/ui_text_edit.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use effectcraft_ui_egui::EffectcraftApp;
88
use effectcraft_ui_egui::dock::PanelKind;
99
use egui::{Event, Key, Modifiers, PointerButton, Pos2};
1010
use egui_kittest::Harness;
11+
use egui_kittest::kittest::Queryable;
1112
use serde_json::json;
1213

1314
fn app() -> EffectcraftApp {
@@ -1854,3 +1855,19 @@ fn character_panel_line_join_buttons_set_the_join() {
18541855
click(&mut h, bevel, Modifiers::NONE);
18551856
assert_eq!(join(&h), effectcraft_engine::keyframe::LineJoin::Bevel);
18561857
}
1858+
1859+
/// #2075: the Character panel's stroke width has a presets menu (0.25 … 100 px) beside its value.
1860+
#[test]
1861+
fn character_panel_stroke_width_presets_set_the_width() {
1862+
let mut s = Session::default();
1863+
s.execute("comp.new", json!({"name": "Type", "width": 640, "height": 360, "duration": 2})).unwrap();
1864+
let lid = s.execute("layer.newText", json!({"text": "Stroke", "size": 80, "applyStroke": true, "strokeWidth": 8})).unwrap()["layer"].as_u64().unwrap();
1865+
let mut h = harness(EffectcraftApp::new(s));
1866+
h.state_mut().show_panel(PanelKind::Character);
1867+
h.run_steps(3);
1868+
let arrow = rect(&h, "character.strokeWidth.presets").center();
1869+
click(&mut h, arrow, Modifiers::NONE);
1870+
let entry = h.get_by_label("0.5 px").rect().center();
1871+
click(&mut h, entry, Modifiers::NONE);
1872+
assert_eq!(layer_doc(&h.state().session, LayerId(lid)).unwrap().stroke_width, 0.5);
1873+
}

0 commit comments

Comments
 (0)