merge: resolve manuscript conflicts with latest main comments
This commit is contained in:
@@ -47,30 +47,38 @@ pub enum DrawCommand {
|
||||
opacity: f32,
|
||||
tint: Option<Color>,
|
||||
},
|
||||
// 在 rect 内绘制不可变 3D 视图;平移/缩放改变视口矩形,不改写共享场景或相机。
|
||||
Scene3D {
|
||||
rect: Rect,
|
||||
view: std::sync::Arc<crate::scene3d::View>,
|
||||
},
|
||||
// 清除整个目标缓冲;不携带几何,因此列表平移和缩放不会改变它。
|
||||
Clear(Color),
|
||||
// 将矩形压入裁剪栈;后续命令受裁剪约束,必须由对应 PopClip 恢复。
|
||||
PushClip(Rect),
|
||||
// 恢复上层裁剪。合并列表保持原顺序,调用方需保证裁剪栈配对。
|
||||
PopClip,
|
||||
// 填充圆角矩形;半径与矩形尺寸在设备缩放时使用同一比例。
|
||||
FillRoundedRect {
|
||||
rect: Rect,
|
||||
radius: f32,
|
||||
color: Color,
|
||||
},
|
||||
// 描边圆角矩形;描边宽度也是长度,必须随几何一起缩放。
|
||||
StrokeRoundedRect {
|
||||
rect: Rect,
|
||||
radius: f32,
|
||||
width: f32,
|
||||
color: Color,
|
||||
},
|
||||
// 在有限矩形内进行文本布局;缩放同时作用于矩形和文字样式,保持换行比例。
|
||||
WrappedText {
|
||||
rect: Rect,
|
||||
value: String,
|
||||
style: TextStyle,
|
||||
color: Color,
|
||||
},
|
||||
// 以原点定位文本,文本布局使用 TextStyle;与 WrappedText 不同,不额外携带有限文本框。
|
||||
Text {
|
||||
origin: Point,
|
||||
value: String,
|
||||
@@ -82,6 +90,7 @@ pub enum DrawCommand {
|
||||
impl DrawCommand {
|
||||
/// 返回平移后的绘制命令,并同步移动命令中的相关几何。
|
||||
pub fn translated(mut self, delta: Point) -> Self {
|
||||
// 平移只改变位置,保留尺寸、圆角、文字样式和颜色;消费 self 后返回修改后的命令。
|
||||
match &mut self {
|
||||
Self::WrappedText { rect, .. }
|
||||
| Self::Scene3D { rect, .. }
|
||||
@@ -110,7 +119,9 @@ pub struct DisplayList {
|
||||
impl DisplayList {
|
||||
/// 按设备比例缩放命令,文字、边框和矩形不能分别使用不一致比例。
|
||||
pub fn scale(&mut self, scale: f32) {
|
||||
// 原地累计缩放:重复调用会相乘,并非设置绝对缩放值。调用方负责提供有效设备比例。
|
||||
for command in &mut self.commands {
|
||||
// 先处理各变体独有的长度(字体、圆角、描边),再把公共矩形交给下方统一缩放。
|
||||
let rect = match command {
|
||||
DrawCommand::WrappedText { rect, style, .. } => {
|
||||
*style = style.scaled(scale);
|
||||
@@ -149,6 +160,7 @@ impl DisplayList {
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
// 矩形的原点和宽高一起缩放,保证裁剪范围、文本框与实际绘制内容对齐。
|
||||
if let Some(rect) = rect {
|
||||
rect.x *= scale;
|
||||
rect.y *= scale;
|
||||
@@ -163,6 +175,7 @@ impl DisplayList {
|
||||
}
|
||||
|
||||
/// 平移当前显示列表中的命令,供整块页面或管理面板放入窗口坐标。
|
||||
// 与单条 translated 相同,但直接修改整个列表;Clear/PopClip 没有位置需要移动。
|
||||
pub fn translate(&mut self, delta: Point) {
|
||||
for command in &mut self.commands {
|
||||
match command {
|
||||
@@ -189,6 +202,7 @@ impl DisplayList {
|
||||
}
|
||||
|
||||
/// 按原顺序合并另一组绘制命令,不在这里重排层次。
|
||||
// 消费另一个列表并移动其命令,不复制字符串或场景数据,也不在连接处补裁剪指令。
|
||||
pub fn extend(&mut self, other: DisplayList) {
|
||||
self.commands.extend(other.commands);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user