Skip to main content

waft_winui/controls/
tab_view_item.rs

1//! TabViewItem's header template and pointer behavior from TabView.xaml and TabViewItem.cpp.
2
3use crate::*;
4use std::{any::Any, fmt, rc::Rc};
5use waft_embedder::Canvas;
6use waft_embedder::valo::{FillRule, Paint};
7use waft_embedder::{Color, FontWeight, PathBuilder, Size};
8use waft_foundation::{App, Listener};
9use waft_painting::{Alignment, EdgeInsetsGeometry};
10use waft_rendering::{BoxConstraints, CustomPainter};
11use waft_widgets::*;
12
13/// How the tab strip allocates width to its headers.
14#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
15pub enum TabViewWidthMode {
16    /// Equal widths constrained by TabViewItemMinWidth and TabViewItemMaxWidth.
17    #[default]
18    Equal,
19
20    /// Each header takes the width required by its content.
21    SizeToContent,
22
23    /// Unselected headers show their icon without their label.
24    Compact,
25}
26
27/// When closable tabs expose their close button.
28#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
29pub enum TabViewCloseButtonOverlayMode {
30    /// The desktop default displays the close button.
31    #[default]
32    Auto,
33
34    /// Displays the button for a selected or hovered tab.
35    OnPointerOver,
36
37    /// Displays the close button whenever the tab is closable.
38    Always,
39}
40
41/// A stable tab identity, header, and content supplied to TabView.
42///
43/// The identity must remain unchanged when the tab moves within the collection.
44#[derive(Clone)]
45pub struct TabViewItem {
46    /// Stable item identity, independent of its current collection index.
47    pub id: String,
48
49    /// Header content presented in the tab strip.
50    pub header: WidgetRef,
51
52    /// The original string header used for the default header ToolTip.
53    pub header_text: Option<String>,
54
55    /// The icon element presented beside the header.
56    pub icon_source: Option<WidgetRef>,
57
58    /// Content presented when this tab is selected.
59    pub content: WidgetRef,
60
61    /// Whether the close button and middle-click close request are available.
62    pub is_closable: bool,
63
64    /// Whether the tab accepts input and keyboard selection.
65    pub is_enabled: bool,
66
67    /// Whether the tab participates in layout and keyboard navigation.
68    pub is_visible: bool,
69
70    /// An explicit foreground used in the unselected resting state.
71    pub foreground: Option<Color>,
72
73    /// An explicit tooltip, overriding the nonempty string header fallback.
74    pub tool_tip: Option<ToolTip>,
75
76    /// Raised after the parent TabCloseRequested event; the owner decides whether to remove it.
77    pub close_requested: Option<Listener>,
78}
79
80impl fmt::Debug for TabViewItem {
81    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82        f.debug_struct("TabViewItem")
83            .field("id", &self.id)
84            .field("header_text", &self.header_text)
85            .finish_non_exhaustive()
86    }
87}
88
89impl TabViewItem {
90    /// Creates a tab with a stable identity, header widget and content widget.
91    #[cfg_attr(debug_assertions, track_caller)]
92    pub fn new<H, C>(
93        id: impl Into<String>,
94        header: impl IntoWidget<H>,
95        content: impl IntoWidget<C>,
96    ) -> Self {
97        Self {
98            id: id.into(),
99            header: header.into_widget(),
100            header_text: None,
101            icon_source: None,
102            content: content.into_widget(),
103            is_closable: true,
104            is_enabled: true,
105            is_visible: true,
106            foreground: None,
107            tool_tip: None,
108            close_requested: None,
109        }
110    }
111
112    /// Creates a string header with the source's automatic header tooltip.
113    #[cfg_attr(debug_assertions, track_caller)]
114    pub fn text<C>(
115        id: impl Into<String>,
116        header: impl Into<String>,
117        content: impl IntoWidget<C>,
118    ) -> Self {
119        let text = header.into();
120        let mut item = Self::new(id, Text::new(text.clone()), content);
121        item.header_text = Some(text);
122        item
123    }
124
125    /// Sets the icon element; native widgets replace XAML IconSource factories.
126    #[cfg_attr(debug_assertions, track_caller)]
127    pub fn icon_source<K>(mut self, icon: impl IntoWidget<K>) -> Self {
128        self.icon_source = Some(icon.into_widget());
129        self
130    }
131
132    /// Sets whether closing can be requested for this tab.
133    pub fn is_closable(mut self, value: bool) -> Self {
134        self.is_closable = value;
135        self
136    }
137
138    /// Sets whether the tab accepts pointer and keyboard input.
139    pub fn is_enabled(mut self, value: bool) -> Self {
140        self.is_enabled = value;
141        self
142    }
143
144    /// Sets whether the tab participates in layout and navigation.
145    pub fn is_visible(mut self, value: bool) -> Self {
146        self.is_visible = value;
147        self
148    }
149
150    /// Sets the unselected resting foreground.
151    pub fn foreground(mut self, value: Color) -> Self {
152        self.foreground = Some(value);
153        self
154    }
155
156    /// Overrides the automatic string header tooltip.
157    pub fn tool_tip(mut self, value: ToolTip) -> Self {
158        self.tool_tip = Some(value);
159        self
160    }
161
162    /// Receives close requests after the parent's event.
163    pub fn close_requested(mut self, callback: Listener) -> Self {
164        self.close_requested = Some(callback);
165        self
166    }
167}
168
169/// Source bottom border states for the item beside the selection.
170#[derive(Clone, Copy, Debug, PartialEq, Eq)]
171pub(crate) enum TabBottomBorderState {
172    /// Draws the continuous resting border.
173    Normal,
174
175    /// Draws the arc joining the selected tab on the right.
176    LeftOfSelectedTab,
177
178    /// Draws the arc joining the selected tab on the left.
179    RightOfSelectedTab,
180
181    /// Hides the border while selected or dragging.
182    NoBottomBorderLine,
183}
184
185/// Reports pointer entry and exit to the owning strip.
186type TabViewItemHoverChanged = Rc<dyn Fn(&mut App, bool)>;
187
188/// The realized header container; selection and item lifetime belong to its parent TabView.
189#[derive(Clone)]
190pub(crate) struct TabViewItemHeader {
191    /// Owner-supplied identity and visual content.
192    pub item: TabViewItem,
193
194    /// Whether this header represents the selected page.
195    pub selected: bool,
196
197    /// Controls compact icon-only presentation.
198    pub width_mode: TabViewWidthMode,
199
200    /// Controls close-button visibility.
201    pub close_overlay_mode: TabViewCloseButtonOverlayMode,
202
203    /// Position of this item relative to the selected tab.
204    pub bottom_border: TabBottomBorderState,
205
206    /// Whether the trailing separator is present in the resting state.
207    pub separator_visible: bool,
208
209    /// Header focus node retained by the owner strip.
210    pub focus_node: FocusNodeRef,
211
212    /// Close-button focus node retained by the owner strip.
213    pub close_focus_node: FocusNodeRef,
214
215    /// Requests selecting this item.
216    pub select: Listener,
217
218    /// Requests closing this item.
219    pub close: Listener,
220
221    /// Updates the strip’s hovered identity and width-deferral state.
222    pub hover_changed: TabViewItemHoverChanged,
223}
224
225impl fmt::Debug for TabViewItemHeader {
226    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
227        f.debug_struct("TabViewItemHeader")
228            .field("item", &self.item)
229            .finish_non_exhaustive()
230    }
231}
232
233impl StatelessWidget for TabViewItemHeader {
234    fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef {
235        let header = self.clone();
236        let content = CommonStates::new(self.select.clone(), move |app, context, states| {
237            header.template(app, context, states, true)
238        })
239        .is_enabled(self.item.is_enabled)
240        .is_tab_stop(self.selected)
241        .focus_node(self.focus_node.clone());
242        let enter = self.hover_changed.clone();
243        let leave = self.hover_changed.clone();
244        let close = self.close.clone();
245        let mut content = GestureDetector::new().child(content);
246        if self.item.is_enabled && self.item.is_closable {
247            content = content.on_tertiary_tap_up(Rc::new(move |app, _| close.call(app)));
248        }
249        let content = MouseRegion::new()
250            .on_enter(Rc::new(move |app, _| enter(app, true)))
251            .on_exit(Rc::new(move |app, _| leave(app, false)))
252            .child(content)
253            .into_widget();
254        let tooltip = self.item.tool_tip.clone().or_else(|| {
255            self.item
256                .header_text
257                .as_ref()
258                .filter(|text| !text.is_empty())
259                .map(|text| ToolTip::text(text).placement(PlacementMode::Mouse))
260        });
261        if let Some(tooltip) = tooltip {
262            ToolTipService::new(content, tooltip)
263                .is_enabled(self.item.is_enabled)
264                .into_widget()
265        } else {
266            content
267        }
268    }
269}
270
271impl TabViewItemHeader {
272    /// UpdateCloseButton: OnPointerOver still shows the close button on a selected tab.
273    fn close_visible(&self, states: ControlStates) -> bool {
274        self.item.is_closable
275            && (self.close_overlay_mode != TabViewCloseButtonOverlayMode::OnPointerOver
276                || self.selected
277                || matches!(
278                    states.common,
279                    CommonState::PointerOver | CommonState::Pressed
280                ))
281    }
282
283    /// Builds LayoutRoot's named parts with the source visual-state resource substitutions.
284    pub(crate) fn feedback(&self, app: &mut App, context: BuildContext) -> WidgetRef {
285        let mut visual = self.clone();
286        visual.item.header = self.item.header_text.as_ref().map_or_else(
287            || SizedBox::new().into_widget(),
288            |text| Text::new(text.clone()).into_widget(),
289        );
290        visual.item.icon_source = self.item.icon_source.as_ref().and_then(|icon| {
291            downcast_widget::<FontIcon>(icon.as_ref()).map(|icon| {
292                let mut icon = icon.clone();
293                icon.key = None;
294                icon.into_widget()
295            })
296        });
297        visual.template(
298            app,
299            context,
300            ControlStates {
301                common: CommonState::Normal,
302                focused: false,
303            },
304            false,
305        )
306    }
307
308    /// Builds the source template for the current layout and visual state.
309    fn template(
310        &self,
311        app: &mut App,
312        context: BuildContext,
313        states: ControlStates,
314        interactive: bool,
315    ) -> WidgetRef {
316        let theme = ThemeResources::of(app, context);
317        let r = &theme;
318        let selected = self.selected;
319        let compact = self.width_mode == TabViewWidthMode::Compact && !selected;
320        let close_visible = self.close_visible(states);
321        let (background, foreground, icon_foreground, close_background, close_foreground) =
322            if !self.item.is_enabled {
323                (
324                    r.tab_view_item_header_background_disabled,
325                    r.tab_view_item_header_foreground_disabled,
326                    r.tab_view_button_foreground_disabled,
327                    r.tab_view_item_header_disabled_close_button_background,
328                    r.tab_view_item_header_disabled_close_button_foreground,
329                )
330            } else if selected {
331                (
332                    r.tab_view_item_header_background,
333                    r.tab_view_item_header_foreground_selected,
334                    r.tab_view_item_icon_foreground_selected,
335                    r.tab_view_item_header_selected_close_button_background,
336                    r.tab_view_item_header_selected_close_button_foreground,
337                )
338            } else {
339                match states.common {
340                    CommonState::PointerOver => (
341                        r.tab_view_item_header_background_pointer_over,
342                        r.tab_view_item_header_foreground_pointer_over,
343                        r.tab_view_item_icon_foreground_pointer_over,
344                        r.tab_view_item_header_pointer_over_close_button_background,
345                        r.tab_view_item_header_pointer_over_close_button_foreground,
346                    ),
347                    CommonState::Pressed => (
348                        r.tab_view_item_header_background_pressed,
349                        r.tab_view_item_header_foreground_pressed,
350                        r.tab_view_item_icon_foreground_pressed,
351                        r.tab_view_item_header_pressed_close_button_background,
352                        r.tab_view_item_header_pressed_close_button_foreground,
353                    ),
354                    _ => (
355                        r.tab_view_item_header_background,
356                        self.item
357                            .foreground
358                            .unwrap_or(r.tab_view_item_header_foreground),
359                        self.item
360                            .foreground
361                            .unwrap_or(r.tab_view_item_icon_foreground),
362                        r.tab_view_item_header_close_button_background,
363                        r.tab_view_item_header_close_button_foreground,
364                    ),
365                }
366            };
367        let mut children = Vec::new();
368        if let Some(icon) = &self.item.icon_source {
369            // IconBox / IconControl, independently coloured from ContentPresenter.
370            let icon = SizedBox::new()
371                .width(r.tab_view_item_header_icon_size)
372                .height(r.tab_view_item_header_icon_size)
373                .child(FittedBox::new().child(DefaultTextStyle::new(
374                    control_text_style(
375                        &theme,
376                        r.tab_view_item_header_icon_size,
377                        FontWeight::NORMAL,
378                        icon_foreground,
379                    ),
380                    icon.clone(),
381                )));
382            children.push(
383                GridCell::new(
384                    Center::new().child(
385                        Padding::new(EdgeInsetsGeometry::only(
386                            0.0,
387                            0.0,
388                            if compact {
389                                0.0
390                            } else {
391                                r.tab_view_item_header_icon_margin[2]
392                            },
393                            0.0,
394                        ))
395                        .child(icon),
396                    ),
397                )
398                .column(0)
399                .into_widget(),
400            );
401        }
402        if !compact {
403            // ContentPresenter never implicitly binds to the tab's page content.
404            children.push(
405                GridCell::new(
406                    Align::new().alignment(Alignment::CENTER_LEFT.into()).child(
407                        DefaultTextStyle::new(
408                            control_text_style(
409                                &theme,
410                                r.tab_view_item_header_font_size,
411                                if selected {
412                                    FontWeight::W600
413                                } else {
414                                    FontWeight::NORMAL
415                                },
416                                foreground,
417                            ),
418                            self.item.header.clone(),
419                        )
420                        .max_lines(1)
421                        .overflow(waft_painting::TextOverflow::Ellipsis),
422                    ),
423                )
424                .column(1)
425                .into_widget(),
426            );
427        }
428        if close_visible {
429            let r2 = r.clone();
430            let theme_kind = theme.theme;
431            let close = if interactive {
432                Button::new(
433                    FontIcon::symbol(FluentSymbol::Dismiss)
434                        .font_size(r.tab_view_item_header_close_font_size),
435                    self.close.clone(),
436                )
437                .is_enabled(self.item.is_enabled)
438                .is_tab_stop(false)
439                .focus_node(self.close_focus_node.clone())
440                .template(move |_, _, states, content| {
441                    close_button_template(
442                        &r2,
443                        theme_kind,
444                        states,
445                        content,
446                        close_background,
447                        close_foreground,
448                    )
449                })
450                .into_widget()
451            } else {
452                close_button_template(
453                    r,
454                    theme_kind,
455                    ControlStates {
456                        common: CommonState::Normal,
457                        focused: false,
458                    },
459                    FontIcon::symbol(FluentSymbol::Dismiss)
460                        .font_size(r.tab_view_item_header_close_font_size)
461                        .into_widget(),
462                    close_background,
463                    close_foreground,
464                )
465            };
466            children.push(
467                GridCell::new(
468                    Padding::new(EdgeInsetsGeometry::only(
469                        r.tab_view_item_header_close_margin[0],
470                        0.0,
471                        0.0,
472                        0.0,
473                    ))
474                    .child(if interactive {
475                        ToolTipService::new(close, ToolTip::text("Close tab (Ctrl+F4)"))
476                            .into_widget()
477                    } else {
478                        close
479                    }),
480                )
481                .column(2)
482                .into_widget(),
483            );
484        }
485        let grid = Grid::new()
486            .column_definitions([
487                ColumnDefinition::new(if compact {
488                    GridLength::pixel(r.tab_view_item_header_icon_size)
489                } else {
490                    GridLength::AUTO
491                }),
492                ColumnDefinition::new(GridLength::star(1.0)),
493                ColumnDefinition::new(GridLength::AUTO),
494            ])
495            .children(children);
496        let border = if selected {
497            Brush::VerticalElevation {
498                stops: r.tab_view_selected_item_border_brush,
499                length: 4.0,
500            }
501        } else {
502            Brush::Solid(r.tab_view_item_border_brush)
503        };
504        // TabContainer: top corners only; the selected background supplies the lower outward curves.
505        let content = ControlBorder::new(Brush::Solid(background), border)
506            .border_thickness_ltrb(if selected {
507                r.tab_view_selected_item_border_thickness
508            } else {
509                r.tab_view_item_border_thickness
510            })
511            .corner_radius_corners([
512                r.overlay_corner_radius[0],
513                r.overlay_corner_radius[1],
514                0.0,
515                0.0,
516            ])
517            .padding(if close_visible {
518                r.tab_view_item_header_padding_with_close_button
519            } else {
520                r.tab_view_item_header_padding_without_close_button
521            })
522            .child(grid);
523        let content = Margin::new(
524            if selected {
525                r.tab_view_selected_item_header_margin
526            } else {
527                [0.0; 4]
528            },
529            content,
530        );
531        let content =
532            ConstrainedBox::new(BoxConstraints::new().min_height(r.tab_view_item_min_height))
533                .child(content);
534        let content = CustomPaint::new()
535            .painter(TabChromePainter {
536                selected,
537                border_state: self.bottom_border,
538                separator: self.separator_visible
539                    && !selected
540                    && !matches!(
541                        states.common,
542                        CommonState::PointerOver | CommonState::Pressed
543                    ),
544                selected_fill: r.tab_view_item_header_background_selected,
545                border: r.tab_view_border_brush,
546                separator_color: r.tab_view_item_separator,
547                separator_margin: r.tab_view_item_separator_margin,
548                selected_corner_radius: r.overlay_corner_radius,
549            })
550            .child(content);
551        FocusVisual::new(content, theme.theme)
552            .visible(states.focused)
553            .margin([-3.0; 4])
554            .corner_radius(r.overlay_corner_radius[0])
555            .into_widget()
556    }
557}
558
559/// TabViewCloseButtonStyle receives the parent item's rest brushes through template bindings.
560/// Builds the source close-button chrome independently of its interaction wrapper.
561fn close_button_template(
562    r: &ThemeResources,
563    theme: Theme,
564    states: ControlStates,
565    content: WidgetRef,
566    background: Color,
567    foreground: Color,
568) -> WidgetRef {
569    let (background, foreground, border) = match states.common {
570        CommonState::PointerOver => (
571            r.tab_view_item_header_close_button_background_pointer_over,
572            r.tab_view_item_header_close_button_foreground_pointer_over,
573            r.tab_view_item_header_close_button_border_brush_pointer_over,
574        ),
575        CommonState::Pressed => (
576            r.tab_view_item_header_close_button_background_pressed,
577            r.tab_view_item_header_close_button_foreground_pressed,
578            r.tab_view_item_header_close_button_border_brush_pressed,
579        ),
580        CommonState::Disabled => (
581            background,
582            foreground,
583            r.tab_view_item_header_close_button_border_brush_disabled,
584        ),
585        CommonState::Normal => (
586            background,
587            foreground,
588            r.tab_view_item_header_close_button_border_brush,
589        ),
590    };
591    let content = SizedBox::new()
592        .width(r.tab_view_item_header_close_button_width)
593        .height(r.tab_view_item_header_close_button_height)
594        .child(
595            ControlBorder::new(Brush::Solid(background), Brush::Solid(border))
596                .border_thickness_ltrb(r.tab_view_item_header_close_button_border_thickness)
597                .corner_radius(r.control_corner_radius[0])
598                .child(Center::new().child(DefaultTextStyle::new(
599                    control_text_style(
600                        r,
601                        r.tab_view_item_header_close_font_size,
602                        FontWeight::NORMAL,
603                        foreground,
604                    ),
605                    content,
606                ))),
607        );
608    FocusVisual::new(content, theme)
609        .visible(states.focused)
610        .margin([-3.0; 4])
611        .corner_radius(r.control_corner_radius[0])
612        .into_widget()
613}
614
615/// LayoutRoot's bottom line, separator, selected background and outward corner arcs.
616/// Draws the source selected geometry, adjacent arcs and trailing separator.
617#[derive(Clone, Debug, PartialEq)]
618struct TabChromePainter {
619    /// Whether to draw the selected background geometry.
620    selected: bool,
621
622    /// Controls the source bottom-border and arc state.
623    border_state: TabBottomBorderState,
624
625    /// Whether to draw the trailing vertical separator.
626    separator: bool,
627
628    /// Theme brush for the selected background.
629    selected_fill: Color,
630
631    /// Theme brush for the lower border and radius arcs.
632    border: Color,
633
634    /// Theme brush for the trailing separator.
635    separator_color: Color,
636
637    /// `TabViewItemSeparatorMargin`: the separator's inset in left, top, right, bottom order.
638    separator_margin: [f64; 4],
639
640    /// `OverlayCornerRadius`: the selected background's top corners.
641    selected_corner_radius: [f64; 4],
642}
643
644impl CustomPainter for TabChromePainter {
645    fn paint(&self, _app: &mut App, canvas: &mut Canvas, size: Size) {
646        let (w, h) = (size.width() as f32, size.height() as f32);
647        if self.selected {
648            canvas.draw_path(
649                &selected_tab_geometry(self.selected_corner_radius, w, h),
650                FillRule::NonZero,
651                &Paint::from_color(self.selected_fill.into()),
652            );
653            // LeftRadiusRenderArc and RightRadiusRenderArc: literal source cubic paths.
654            let mut left = PathBuilder::new();
655            left.move_to((0.0, h - 4.0))
656                .cubic_to(
657                    (0.0, h - 2.80531),
658                    (-0.52376, h - 1.73294),
659                    (-1.35418, h - 1.0),
660                )
661                .line_to((-4.0, h - 1.0))
662                .cubic_to((-2.34315, h - 1.0), (-1.0, h - 2.34315), (-1.0, h - 4.0))
663                .line_to((0.0, h - 4.0))
664                .close();
665            canvas.draw_path(
666                &left.build(),
667                FillRule::NonZero,
668                &Paint::from_color(self.border.into()),
669            );
670            let mut right = PathBuilder::new();
671            right
672                .move_to((w, h - 4.0))
673                .cubic_to(
674                    (w, h - 2.80531),
675                    (w + 0.523755, h - 1.73294),
676                    (w + 1.35418, h - 1.0),
677                )
678                .line_to((w + 4.0, h - 1.0))
679                .cubic_to(
680                    (w + 2.34315, h - 1.0),
681                    (w + 1.0, h - 2.34315),
682                    (w + 1.0, h - 4.0),
683                )
684                .line_to((w, h - 4.0))
685                .close();
686            canvas.draw_path(
687                &right.build(),
688                FillRule::NonZero,
689                &Paint::from_color(self.border.into()),
690            );
691        } else if self.border_state != TabBottomBorderState::NoBottomBorderLine {
692            let left = if self.border_state == TabBottomBorderState::RightOfSelectedTab {
693                2.0
694            } else {
695                0.0
696            };
697            let right = if self.border_state == TabBottomBorderState::LeftOfSelectedTab {
698                2.0
699            } else {
700                0.0
701            };
702            canvas.draw_rect(
703                waft_embedder::valo::Rect::new(left, h - 1.0, w - left - right, 1.0),
704                &Paint::from_color(self.border.into()),
705            );
706        }
707        if self.separator {
708            canvas.draw_rect(
709                waft_embedder::valo::Rect::new(
710                    w - 1.0,
711                    self.separator_margin[1] as f32,
712                    1.0,
713                    (h - self.separator_margin[1] as f32 - self.separator_margin[3] as f32)
714                        .max(0.0),
715                ),
716                &Paint::from_color(self.separator_color.into()),
717            );
718        }
719    }
720
721    fn should_repaint(&self, _app: &App, old: &dyn CustomPainter) -> bool {
722        old.as_any().downcast_ref::<Self>() != Some(self)
723    }
724
725    fn as_any(&self) -> &dyn Any {
726        self
727    }
728}
729
730/// UpdateTabGeometry: four-pixel outward lower corners and the theme's upper radii.
731fn selected_tab_geometry(
732    corner_radius: [f64; 4],
733    width: f32,
734    height: f32,
735) -> std::sync::Arc<waft_embedder::valo::Path> {
736    use std::f32::consts::{FRAC_PI_2, PI};
737    let left = corner_radius[0] as f32;
738    let right = corner_radius[1] as f32;
739    let mut path = PathBuilder::new();
740    path.move_to((-4.0, height))
741        .arc((-4.0, height - 4.0), 4.0, FRAC_PI_2, -FRAC_PI_2)
742        .line_to((0.0, left))
743        .arc((left, left), left, PI, FRAC_PI_2)
744        .line_to((width - right, 0.0))
745        .arc((width - right, right), right, -FRAC_PI_2, FRAC_PI_2)
746        .line_to((width, height - 4.0))
747        .arc((width + 4.0, height - 4.0), 4.0, PI, -FRAC_PI_2)
748        .close();
749    path.build()
750}