pub struct MathQuill(/* private fields */);
Expand description
The primary interface to the MathQuill library.
Implementations§
Source§impl MathQuill
impl MathQuill
Sourcepub fn get_global_interface() -> Self
pub fn get_global_interface() -> Self
JS errors if the MathQuill library is not loaded already.
Will reference a global stored in the mathquill library,
so you can call this as many times as you want and assume
each instance is the same as the last:
By default, MathQuill overwrites the global MathQuill variable when loaded
,
copied from https://docs.mathquill.com/en/latest/Api_Methods/#api-methods
Examples found in repository?
More examples
examples/field.rs (line 11)
7fn main() {
8 // getting this is usually the responsibility of
9 // a web framework, e.g. leptos
10 let element: web_sys::HtmlElement = todo!();
11 let mq = MathQuill::get_global_interface();
12
13 let mut config = Config::default();
14 config.handlers().on_edit_field(|| {
15 let field: Option<MathField> = MathQuill::get_global_interface().get_field(&element);
16 let latex = field.unwrap().latex();
17 check_answer(latex);
18 });
19
20 let _field = mq.mount_field(&element, &config);
21
22 // dropping config invalidates closures,
23 // read docs on Config
24}
Sourcepub fn mount_field(
&self,
html_element: &HtmlElement,
config: &Config<MathField>,
) -> MathField
pub fn mount_field( &self, html_element: &HtmlElement, config: &Config<MathField>, ) -> MathField
When config.handlers is dropped, the mounted field’s callbacks will be invalidated
Examples found in repository?
examples/field.rs (line 20)
7fn main() {
8 // getting this is usually the responsibility of
9 // a web framework, e.g. leptos
10 let element: web_sys::HtmlElement = todo!();
11 let mq = MathQuill::get_global_interface();
12
13 let mut config = Config::default();
14 config.handlers().on_edit_field(|| {
15 let field: Option<MathField> = MathQuill::get_global_interface().get_field(&element);
16 let latex = field.unwrap().latex();
17 check_answer(latex);
18 });
19
20 let _field = mq.mount_field(&element, &config);
21
22 // dropping config invalidates closures,
23 // read docs on Config
24}
Sourcepub fn mount_static_field(&self, html_element: &HtmlElement) -> StaticMath
pub fn mount_static_field(&self, html_element: &HtmlElement) -> StaticMath
Sourcepub fn get_field(&self, el: &HtmlElement) -> Option<MathField>
pub fn get_field(&self, el: &HtmlElement) -> Option<MathField>
Examples found in repository?
examples/field.rs (line 15)
7fn main() {
8 // getting this is usually the responsibility of
9 // a web framework, e.g. leptos
10 let element: web_sys::HtmlElement = todo!();
11 let mq = MathQuill::get_global_interface();
12
13 let mut config = Config::default();
14 config.handlers().on_edit_field(|| {
15 let field: Option<MathField> = MathQuill::get_global_interface().get_field(&element);
16 let latex = field.unwrap().latex();
17 check_answer(latex);
18 });
19
20 let _field = mq.mount_field(&element, &config);
21
22 // dropping config invalidates closures,
23 // read docs on Config
24}
pub fn get_static_field(&self, el: &HtmlElement) -> Option<StaticMath>
Auto Trait Implementations§
impl Freeze for MathQuill
impl RefUnwindSafe for MathQuill
impl !Send for MathQuill
impl !Sync for MathQuill
impl Unpin for MathQuill
impl UnwindSafe for MathQuill
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more