cxx_qt_lib/core/
qpoint.rs1use cxx::{type_id, ExternType};
7use std::fmt;
8
9#[cxx::bridge]
10mod ffi {
11 unsafe extern "C++" {
12 include!("cxx-qt-lib/qpoint.h");
13 include!("cxx-qt-lib/qstring.h");
14
15 type QPoint = super::QPoint;
16 type QString = crate::QString;
17
18 include!("cxx-qt-lib/qpointf.h");
19 #[allow(dead_code)]
20 type QPointF = crate::QPointF;
21
22 #[rust_name = "is_null"]
24 fn isNull(self: &QPoint) -> bool;
25
26 #[rust_name = "manhattan_length"]
29 fn manhattanLength(self: &QPoint) -> i32;
30
31 #[rust_name = "set_x"]
33 fn setX(self: &mut QPoint, x: i32);
34
35 #[rust_name = "set_y"]
37 fn setY(self: &mut QPoint, y: i32);
38
39 #[cfg(any(cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_4))]
42 #[rust_name = "to_pointf"]
43 fn toPointF(self: &QPoint) -> QPointF;
44
45 fn transposed(self: &QPoint) -> QPoint;
47
48 fn x(self: &QPoint) -> i32;
50
51 fn y(self: &QPoint) -> i32;
53 }
54
55 #[namespace = "rust::cxxqtlib1"]
56 unsafe extern "C++" {
57 #[doc(hidden)]
58 #[rust_name = "qpoint_dot_product"]
59 fn qpointDotProduct(p1: &QPoint, p2: &QPoint) -> i32;
60 }
61
62 #[namespace = "rust::cxxqtlib1"]
63 unsafe extern "C++" {
64 include!("cxx-qt-lib/common.h");
65
66 #[doc(hidden)]
67 #[rust_name = "qpoint_init_default"]
68 fn construct() -> QPoint;
69 #[doc(hidden)]
70 #[rust_name = "qpoint_init"]
71 fn construct(x: i32, y: i32) -> QPoint;
72 #[doc(hidden)]
73 #[rust_name = "qpoint_to_qstring"]
74 fn toQString(value: &QPoint) -> QString;
75 #[doc(hidden)]
76 #[rust_name = "qpoint_plus"]
77 fn operatorPlus(a: &QPoint, b: &QPoint) -> QPoint;
78 #[doc(hidden)]
79 #[rust_name = "qpoint_minus"]
80 fn operatorMinus(a: &QPoint, b: &QPoint) -> QPoint;
81 #[doc(hidden)]
82 #[rust_name = "qpoint_mul_f32"]
83 fn operatorMul(a: f32, b: &QPoint) -> QPoint;
84 #[doc(hidden)]
85 #[rust_name = "qpoint_mul_f64"]
86 fn operatorMul(a: f64, b: &QPoint) -> QPoint;
87 #[doc(hidden)]
88 #[rust_name = "qpoint_mul_i32"]
89 fn operatorMul(a: i32, b: &QPoint) -> QPoint;
90 #[doc(hidden)]
91 #[rust_name = "qpoint_div"]
92 fn operatorDiv(a: f64, b: &QPoint) -> QPoint;
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq)]
98#[repr(C)]
99pub struct QPoint {
100 x: i32,
101 y: i32,
102}
103
104impl QPoint {
105 pub fn dot_product(p1: &QPoint, p2: &QPoint) -> i32 {
107 ffi::qpoint_dot_product(p1, p2)
108 }
109
110 pub fn new(x: i32, y: i32) -> Self {
112 ffi::qpoint_init(x, y)
113 }
114}
115
116impl Default for QPoint {
117 fn default() -> Self {
119 ffi::qpoint_init_default()
120 }
121}
122
123impl fmt::Display for QPoint {
124 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125 write!(f, "{}", ffi::qpoint_to_qstring(self))
126 }
127}
128
129impl std::ops::Add for QPoint {
130 type Output = Self;
131 fn add(self, other: Self) -> Self {
132 ffi::qpoint_plus(&self, &other)
133 }
134}
135
136impl std::ops::Sub for QPoint {
137 type Output = Self;
138 fn sub(self, other: Self) -> Self {
139 ffi::qpoint_minus(&self, &other)
140 }
141}
142
143impl std::ops::Mul<f32> for QPoint {
144 type Output = Self;
145 fn mul(self, rhs: f32) -> Self {
146 ffi::qpoint_mul_f32(rhs, &self)
147 }
148}
149
150impl std::ops::Mul<f64> for QPoint {
151 type Output = Self;
152 fn mul(self, rhs: f64) -> Self {
153 ffi::qpoint_mul_f64(rhs, &self)
154 }
155}
156
157impl std::ops::Mul<i32> for QPoint {
158 type Output = Self;
159 fn mul(self, rhs: i32) -> Self {
160 ffi::qpoint_mul_i32(rhs, &self)
161 }
162}
163
164impl std::ops::Div<f64> for QPoint {
165 type Output = Self;
166 fn div(self, rhs: f64) -> Self {
167 ffi::qpoint_div(rhs, &self)
168 }
169}
170
171unsafe impl ExternType for QPoint {
175 type Id = type_id!("QPoint");
176 type Kind = cxx::kind::Trivial;
177}