Returns the actual thickness of the axis.
(self, ui: &mut Ui, axis: Axis)
| 204 | |
| 205 | /// Returns the actual thickness of the axis. |
| 206 | pub fn ui(self, ui: &mut Ui, axis: Axis) -> (Response, f32) { |
| 207 | let response = ui.allocate_rect(self.rect, Sense::hover()); |
| 208 | |
| 209 | if !ui.is_rect_visible(response.rect) { |
| 210 | return (response, 0.0); |
| 211 | } |
| 212 | |
| 213 | let Some(transform) = self.transform else { |
| 214 | return (response, 0.0); |
| 215 | }; |
| 216 | let tick_labels_thickness = self.add_tick_labels(ui, transform, axis); |
| 217 | |
| 218 | if self.hints.label.is_empty() { |
| 219 | return (response, tick_labels_thickness); |
| 220 | } |
| 221 | |
| 222 | let galley = self |
| 223 | .hints |
| 224 | .label |
| 225 | .into_galley(ui, Some(TextWrapMode::Extend), f32::INFINITY, TextStyle::Body); |
| 226 | |
| 227 | let text_pos = match self.hints.placement { |
| 228 | Placement::LeftBottom => match axis { |
| 229 | Axis::X => { |
| 230 | let pos = response.rect.center_bottom(); |
| 231 | Pos2 { |
| 232 | x: pos.x - galley.size().x * 0.5, |
| 233 | y: pos.y - galley.size().y * (1.0 + AXIS_LABEL_GAP), |
| 234 | } |
| 235 | } |
| 236 | Axis::Y => { |
| 237 | let pos = response.rect.left_center(); |
| 238 | Pos2 { |
| 239 | x: pos.x - galley.size().y * AXIS_LABEL_GAP, |
| 240 | y: pos.y + galley.size().x * 0.5, |
| 241 | } |
| 242 | } |
| 243 | }, |
| 244 | Placement::RightTop => match axis { |
| 245 | Axis::X => { |
| 246 | let pos = response.rect.center_top(); |
| 247 | Pos2 { |
| 248 | x: pos.x - galley.size().x * 0.5, |
| 249 | y: pos.y + galley.size().y * AXIS_LABEL_GAP, |
| 250 | } |
| 251 | } |
| 252 | Axis::Y => { |
| 253 | let pos = response.rect.right_center(); |
| 254 | Pos2 { |
| 255 | x: pos.x - galley.size().y * (1.0 - AXIS_LABEL_GAP), |
| 256 | y: pos.y + galley.size().x * 0.5, |
| 257 | } |
| 258 | } |
| 259 | }, |
| 260 | }; |
| 261 | let axis_label_thickness = galley.size().y * (1.0 + AXIS_LABEL_GAP); |
| 262 | let angle = match axis { |
| 263 | Axis::X => 0.0, |
no test coverage detected