refactor(editor): split acp text helpers out to satisfy 800-line cap

agent_settings_acp.rs was over the 800-line cap (817 after the Card sink; ~812 before); moved draw_text + ellipsize into agent_settings_acp_helpers.rs. File now 798 lines, op-editor-ui clean.
This commit is contained in:
Kayshen-X 2026-06-20 10:19:26 +08:00
parent ed4154d91c
commit f763e2f339
3 changed files with 31 additions and 22 deletions

View file

@ -1,6 +1,7 @@
//! ACP Agent section for the Agent settings panel.
use crate::theme::Theme;
use crate::widgets::agent_settings_acp_helpers::{draw_text, ellipsize};
use crate::widgets::agent_settings_caret::{paint_settings_input_view, settings_input_text};
use crate::widgets::agent_settings_form_actions::{
cancel_button_rect, paint_form_actions, save_button_rect,
@ -12,7 +13,7 @@ use crate::widgets::agent_settings_i18n::t as t_settings;
use crate::widgets::button::{paint_ghost_button_feedback, tokens_from_theme};
use crate::widgets::icons::{draw_icon, Icon};
use crate::widgets::PaintCx;
use crate::{Color, Point2D, Rect, TextLayout};
use crate::{Color, Point2D, Rect};
use jian_widgets::components::button::{Button, ButtonVariant};
use jian_widgets::components::card::Card;
use op_editor_core::agent_settings::{
@ -794,24 +795,4 @@ fn field_input_rect(card: Rect, field: AcpAgentField) -> Rect {
}
}
fn draw_text(cx: &mut PaintCx<'_>, text: &str, size: f32, color: Color, x: f32, y: f32) {
let layout = TextLayout::single_run(
text,
"system-ui",
size,
(color).to_jian(),
Point2D::new(0.0, 0.0),
);
cx.backend.draw_text(&layout, Point2D::new(x, y));
}
fn ellipsize(cx: &mut PaintCx<'_>, value: &str, max_w: f32, size: f32) -> String {
if cx.backend.measure_text(value, size) <= max_w {
return value.to_string();
}
let mut out = value.to_string();
while !out.is_empty() && cx.backend.measure_text(&format!("{out}..."), size) > max_w {
out.pop();
}
format!("{out}...")
}
// `draw_text` + `ellipsize` moved to `agent_settings_acp_helpers` (800-line cap).

View file

@ -0,0 +1,27 @@
//! Small paint/text helpers for the ACP agent-settings section, split out of
//! `agent_settings_acp.rs` to keep that file under the 800-line cap.
use crate::widgets::PaintCx;
use crate::{Color, Point2D, TextLayout};
pub(super) fn draw_text(cx: &mut PaintCx<'_>, text: &str, size: f32, color: Color, x: f32, y: f32) {
let layout = TextLayout::single_run(
text,
"system-ui",
size,
(color).to_jian(),
Point2D::new(0.0, 0.0),
);
cx.backend.draw_text(&layout, Point2D::new(x, y));
}
pub(super) fn ellipsize(cx: &mut PaintCx<'_>, value: &str, max_w: f32, size: f32) -> String {
if cx.backend.measure_text(value, size) <= max_w {
return value.to_string();
}
let mut out = value.to_string();
while !out.is_empty() && cx.backend.measure_text(&format!("{out}..."), size) > max_w {
out.pop();
}
format!("{out}...")
}

View file

@ -132,6 +132,7 @@ pub mod brand_icons;
// Step 4 — extra editor-chrome widgets (TS app parity).
pub mod agent_settings_acp;
mod agent_settings_acp_helpers;
pub mod agent_settings_builtin;
mod agent_settings_builtin_layout;
mod agent_settings_builtin_parts;