@@ -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
0 commit comments