1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//! Host-independent paint-geometry helpers.
//!
//! # Why this module exists
//!
//! `src/macos/` is gated `#[cfg(all(feature = "macos", target_os = "macos"))]`
//! (see that arm's comment in `lib.rs`) — the whole module, not per-item the
//! way `src/win/` is. So a `cfg(test)` unit test written *inside*
//! `src/macos/` only compiles and runs on `macos-latest`, the one runner in
//! the fleet. Pure rect/inset arithmetic — "which rect gets `selected_bg`
//! behind it", "where does the translucent-blue selection highlight land"
//! — happened to live behind that gate and so had zero coverage anywhere
//! except a real Mac.
//!
//! `src/win/msg.rs` solved the equivalent problem for Windows: pull the part
//! of the platform-specific paint/bootstrap code that is plain arithmetic
//! out from behind the target gate into its own module, and unit-test it
//! where every host can run it. This module is that pattern applied to
//! macOS's paint geometry — deliberately host-independent (no
//! `cfg(target_os)`, no `objc2`/`core-graphics`/`core-text` import anywhere
//! in it) so `cargo test -p quadraui` runs its tests on this repo's ordinary
//! Linux CI leg, with no `--features macos` and no cross-target needed.
//!
//! The actual toolkit calls — `CGContextFillRect`, the real pixel-blend a
//! translucent fill produces — stay exactly where they were, in
//! `macos::text_selection`/`macos::form`, gated and real-Mac-only as before;
//! this module only owns the *computation* those calls consume. See
//! `mac_apply_selection_highlight_paints_over_the_background` in
//! `macos::backend`'s own tests for the real-pixel half that stays macOS-only
//! (alpha-compositing a translucent fill is genuine CoreGraphics behaviour,
//! not arithmetic this module can absorb).
//!
//! `macos::form`'s `toggle_group_on_item_paints_selected_bg` and
//! `segmented_control_selected_paints_selected_bg` stay macOS-only for a
//! *different* reason than the selection-highlight test above: they are not
//! alpha-compositing assertions (both fill solid `selected_bg`, no
//! translucency involved), they are real-`BitmapSurface`/CoreText pixel
//! probes — `region_has_color` scans for glyph-free pixels because Core
//! Text's own rasteriser, not this crate, decides exactly which pixels an
//! antialiased glyph touches. That is genuinely host-specific (a different
//! font rasteriser could shift the answer), so the *pixel* assertion can't
//! move. The *decision* those two tests are actually guarding — "does this
//! item get a `selected_bg` pill at all" — is not host-specific: the shared
//! `native_surface_paint::paint` painter, ported from the Windows copy,
//! never called *any* fill for an on-toggle/selected-segment. [`selected_item_fill`]
//! below is that decision, extracted so it runs on every host; `native_surface_paint::
//! paint`'s `ToggleGroup`/`SegmentedControl` arms call it directly instead
//! of re-deciding inline. Layered coverage, cheapest tier first:
//! [`selected_item_fill`]'s own tests (this module, every host, no
//! features) → `primitives::form::native_surface_paint::tests::
//! toggle_group_fills_selected_bg_behind_on_items_only` /
//! `segmented_control_fills_selected_bg_behind_the_selected_segment_only`
//! (full `paint()` pipeline via a `RecordingSurface` mock, needs
//! `--features {gtk,win,macos}`) → the two real-pixel `macos::form` tests
//! named above (needs a live Core Text rasteriser, `macos-latest` only).
//!
//! Every item here is `#[allow(dead_code)]`: on a `--features tui` or
//! `--features gtk,tui` build (or a bare, feature-less build), nothing calls
//! in — same shape `paint_surface.rs`'s own `#[allow(dead_code)]`
//! documents, one level up the call chain, and the same reason
//! `native_surface_paint` (`primitives::form.rs`) carries the same
//! attribute.
use crateRect;
use crateColor;
/// Vertical inset applied to a selected `ToggleGroup` / `SegmentedControl`
/// item's background pill, in points.
///
/// Shared with [`crate::primitives::form`]'s `native_surface_paint::paint`,
/// which is the actual call site for pixel backends (GTK/Win/macOS) — see
/// [`form_selection_pill`].
pub const FORM_PILL_INSET_Y: f32 = 2.0;
/// Shrink an item rect into the "pill" the *on* / *selected* state paints
/// its background into: full item width, inset [`FORM_PILL_INSET_Y`] at top
/// and bottom so consecutive items keep a visible gap between their
/// highlights.
///
/// Degenerate rows (height <= `2 * FORM_PILL_INSET_Y`) fall back to the
/// un-inset rect rather than producing a negative height.
pub
/// The widget-state → "does this item get a `selected_bg` pill"
/// decision, for one `ToggleGroup` toggle or `SegmentedControl` segment
/// whose caller has already computed `selected` (`toggle.value &&
/// !field.disabled`, or `index == selected_idx`) and translated `rect`
/// into the surface's coordinate space.
///
/// Returns `None` — no fill at all — for an unselected item, and
/// `Some((pill, selected_bg))` for a selected one, where `pill` is
/// [`form_selection_pill`]'s inset of `rect`.
///
/// `native_surface_paint::paint`'s `ToggleGroup`/`SegmentedControl` arms
/// call this directly rather than inlining `if selected { fill }`, so the
/// selection affordance decision is covered on every host, not only
/// wherever a pixel-backend's own probe happens to exist.
pub
/// Compute the fill rects a text-selection highlight paint should issue for
/// one selection's `(row_cell, col_start, col_end)` ranges (see
/// [`crate::text_selection::pixel_selection_ranges`]) — pure geometry, no
/// toolkit call in sight.
///
/// `region_bounds` is the selected `TextRegion`'s bounds in points;
/// `char_w`/`line_h` convert each cell-relative range back to points.
/// Mirrors `macos::text_selection::draw_selection_highlight`'s loop (the
/// call site — see that function), which now delegates the rect math here
/// and only issues the real `CGContextFillRect` call per rect returned.
///
/// Ranges with zero-or-negative width are skipped (matches the GTK/Win
/// twins' guard) — a caret with no selection, or a selection that starts
/// and ends in the same cell, paints nothing.
///
/// Computes in `f64` (matching `char_w`/`line_h`'s precision) but returns
/// [`Rect`], whose fields are `f32` — a round-trip the pre-extraction code
/// didn't have (it passed `f64` straight through to `CGContextFillRect`).
/// `draw_selection_highlight` casts back to `f64` to build the `CGRect`.
/// Immaterial at UI coordinate magnitudes (points, not device pixels at
/// extreme zoom), and intentional: matching [`Rect`]'s field type is what
/// lets every other pixel backend's caller consume this function's output
/// without its own conversion.
pub