Skip to content

Commit e46bcad

Browse files
committed
feat(shadow): toast/status/tooltip 同步支持 blur+spread 投影
将候选窗已有的 ViewShadow.Blur/Spread 渲染能力同步到三类辅助窗口: - viewbox_status.go / status_renderer.go:状态泡(模式指示器)支持 blur+spread shadow,shadowMargins 扩展画布 - viewbox_tooltip.go / tooltip.go:提示浮层同步支持,render 方法 已用 shadowMargins 扩展画布 - toast_renderer.go:toast 窗口支持 blur+spread shadow;accent 条 坐标叠加 (ml, mt) 偏移以匹配内容区域位置 注:三类窗口目前默认主题不配置 blur/spread,若未来主题启用该效果, window 定位代码(tooltip.Show / status.Show / computeToastPosition) 还需同步补偿 shadowMarginLeft/Top,避免视觉位置偏移。
1 parent 104597f commit e46bcad

5 files changed

Lines changed: 54 additions & 17 deletions

File tree

wind_input/internal/ui/status_renderer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ func (r *StatusRenderer) Render(state StatusState, cfg StatusWindowConfig) *imag
7070

7171
// 构建 View 树 + 布局(padding 现状兜底 6、radius 兜底 cfg.BorderRadius)
7272
root := buildStatusTree(text, node, cfg.FontSize, 6.0, cfg.BorderRadius, scale, td, &r.imgRes, resources)
73-
Layout(root, 0, 0, td)
73+
ml, mt, mr, mb := shadowMargins(root.Shadow)
74+
Layout(root, ml, mt, td)
7475

75-
w := root.Rect().Dx()
76-
h := root.Rect().Dy()
76+
w := root.Rect().Dx() + ml + mr
77+
h := root.Rect().Dy() + mt + mb
7778
dc, img := newSharedDrawContext(w, h)
7879
PaintTree(root, dc, img, td)
7980

wind_input/internal/ui/toast_renderer.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,26 @@ func (r *ToastRenderer) Render(opts ToastOptions, maxContentPx int) *image.RGBA
187187
border.Width = int(1.0 * scale)
188188
}
189189
}
190+
var shadow *ViewShadow
191+
if node.ShadowColor != nil {
192+
shadow = &ViewShadow{
193+
OffsetX: node.ShadowOffsetX.Scaled(scale),
194+
OffsetY: node.ShadowOffsetY.Scaled(scale),
195+
Blur: node.ShadowBlur.Scaled(scale),
196+
Spread: node.ShadowSpread.Scaled(scale),
197+
Color: node.ShadowColor,
198+
}
199+
}
190200
root := &View{
191201
Layout: LayoutColumn,
192202
Gap: int(lineSpacing),
193203
Padding: Edges{Top: padTop, Right: padRight, Bottom: padBottom, Left: int(textLeft)},
194-
Background: r.imgRes.fillFor(node.BgColor, node.BgImage, node.BgGradient, resources, scale), // P8 切片6:背景可带图/渐变
204+
Background: r.imgRes.fillFor(node.BgColor, node.BgImage, node.BgGradient, resources, scale),
195205
Border: border,
206+
Shadow: shadow,
196207
FixedW: int(width),
197208
}
198-
r.imgRes.appendLayers(root, node.Layers, resources, func(v float64) int { return int(v * scale) }) // P8 切片6:toast 装饰层
209+
r.imgRes.appendLayers(root, node.Layers, resources, func(v float64) int { return int(v * scale) })
199210
if title != "" {
200211
// 标题用 accent 颜色(level 运行时色),醒目。
201212
tv := &View{Text: title, TextStyle: TextStyle{FontSize: titleSize, Color: accent, Weight: node.FontWeight, Family: node.FontFamily}}
@@ -209,17 +220,19 @@ func (r *ToastRenderer) Render(opts ToastOptions, maxContentPx int) *image.RGBA
209220
root.Children = append(root.Children, &View{Text: line, TextStyle: TextStyle{FontSize: bodySize, Color: node.TextColor, Weight: node.FontWeight, Family: node.FontFamily}})
210221
}
211222

212-
Layout(root, 0, 0, td)
213-
w := root.Rect().Dx()
214-
h := root.Rect().Dy()
223+
ml, mt, mr, mb := shadowMargins(root.Shadow)
224+
Layout(root, ml, mt, td)
225+
w := root.Rect().Dx() + ml + mr
226+
h := root.Rect().Dy() + mt + mb
215227
dc, img := newSharedDrawContext(w, h)
216228
PaintTree(root, dc, img, td)
217229

218-
// 左侧 accent 条(Fill,完全位于 bg 内部,不接触圆角外缘)。后处理:定位用 root 高度。
219-
barH := float64(h) - accentBarInset*2
230+
// 左侧 accent 条(Fill,完全位于 bg 内部,不接触圆角外缘)。
231+
// X/Y 需叠加 shadow margin 偏移,使条位于 root content 区内而非 shadow 扩展区。
232+
barH := float64(root.Rect().Dy()) - accentBarInset*2
220233
if barH > 0 {
221234
dc.SetColor(accent)
222-
dc.DrawRoundedRectangle(accentBarInset, accentBarInset, accentBarWidth, barH, accentBarWidth/2)
235+
dc.DrawRoundedRectangle(float64(ml)+accentBarInset, float64(mt)+accentBarInset, accentBarWidth, barH, accentBarWidth/2)
223236
dc.Fill()
224237
}
225238

wind_input/internal/ui/tooltip.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ func (w *TooltipWindow) render(text string, maxContentWidth float64) *image.RGBA
350350
if root == nil {
351351
return nil
352352
}
353-
Layout(root, 0, 0, td)
354-
dc, img := newSharedDrawContext(root.Rect().Dx(), root.Rect().Dy())
353+
ml, mt, mr, mb := shadowMargins(root.Shadow)
354+
Layout(root, ml, mt, td)
355+
dc, img := newSharedDrawContext(root.Rect().Dx()+ml+mr, root.Rect().Dy()+mt+mb)
355356
PaintTree(root, dc, img, td)
356357
DrawDebugBanner(img)
357358
return img

wind_input/internal/ui/viewbox_status.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,25 @@ func buildStatusTree(text string, node theme.RVNode, fontSize, fallbackPad, fall
9393
}
9494
}
9595

96+
var shadow *ViewShadow
97+
if node.ShadowColor != nil {
98+
shadow = &ViewShadow{
99+
OffsetX: node.ShadowOffsetX.Scaled(scale),
100+
OffsetY: node.ShadowOffsetY.Scaled(scale),
101+
Blur: node.ShadowBlur.Scaled(scale),
102+
Spread: node.ShadowSpread.Scaled(scale),
103+
Color: node.ShadowColor,
104+
}
105+
}
96106
root := &View{
97107
Text: text,
98108
TextStyle: TextStyle{FontSize: fs, Color: node.TextColor, Align: AlignCenter, Weight: node.FontWeight, Family: node.FontFamily},
99109
Padding: Edges{Top: padT, Right: padR, Bottom: padB, Left: padL},
100-
Background: ir.fillFor(node.BgColor, node.BgImage, node.BgGradient, resources, scale), // P8 切片6:背景可带图/渐变
110+
Background: ir.fillFor(node.BgColor, node.BgImage, node.BgGradient, resources, scale),
101111
Border: border,
112+
Shadow: shadow,
102113
FixedW: w,
103114
}
104-
ir.appendLayers(root, node.Layers, resources, func(v float64) int { return int(v * scale) }) // P8 切片6:状态泡装饰层
115+
ir.appendLayers(root, node.Layers, resources, func(v float64) int { return int(v * scale) })
105116
return root
106117
}

wind_input/internal/ui/viewbox_tooltip.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,25 @@ func buildTooltipTree(text string, maxContentWidth float64, node theme.RVNode, s
9494
border.Width = int(1.0 * scale)
9595
}
9696
}
97+
var shadow *ViewShadow
98+
if node.ShadowColor != nil {
99+
shadow = &ViewShadow{
100+
OffsetX: node.ShadowOffsetX.Scaled(scale),
101+
OffsetY: node.ShadowOffsetY.Scaled(scale),
102+
Blur: node.ShadowBlur.Scaled(scale),
103+
Spread: node.ShadowSpread.Scaled(scale),
104+
Color: node.ShadowColor,
105+
}
106+
}
97107
root := &View{
98108
Layout: LayoutColumn,
99109
Gap: lineSpacing,
100110
Padding: Edges{Top: padT, Right: padR, Bottom: padB, Left: padL},
101-
Background: ir.fillFor(node.BgColor, node.BgImage, node.BgGradient, resources, scale), // P8 切片6:背景可带图/渐变
111+
Background: ir.fillFor(node.BgColor, node.BgImage, node.BgGradient, resources, scale),
102112
Border: border,
113+
Shadow: shadow,
103114
}
104-
ir.appendLayers(root, node.Layers, resources, func(v float64) int { return int(v * scale) }) // P8 切片6:tooltip 装饰层
115+
ir.appendLayers(root, node.Layers, resources, func(v float64) int { return int(v * scale) })
105116
mkText := func(s string) *View {
106117
return &View{Text: s, TextStyle: TextStyle{FontSize: fontSize, Color: node.TextColor, Weight: weight, Family: family}}
107118
}

0 commit comments

Comments
 (0)