add Hint accessors
This commit is contained in:
parent
491c8eb6fb
commit
c7e8865d7e
@ -249,6 +249,26 @@ impl<'a> Hint<'a> {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const fn is_single(&self) -> bool { matches!(&self, &Hint::Single(_)) }
|
||||
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub const fn single(&self) -> Option<&&str> {
|
||||
if let Hint::Single(data) = self {
|
||||
Some(data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub const fn many(&self) -> Option<&&[&str]> {
|
||||
if let Hint::Many(data) = self {
|
||||
Some(data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
|
||||
|
||||
@ -3,7 +3,6 @@ use crate::function_entry::FunctionEntry;
|
||||
use crate::widgets::widgets_ontop;
|
||||
use egui::{Button, Id, Key, Modifiers, TextEdit, WidgetText};
|
||||
use emath::vec2;
|
||||
use parsing::Hint;
|
||||
use parsing::Movement;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::Deserialize;
|
||||
@ -104,7 +103,7 @@ impl FunctionManager {
|
||||
.id(*te_id) // Set widget's id to `te_id`
|
||||
.hint_text({
|
||||
// If there's a single hint, go ahead and apply the hint here, if not, set the hint to an empty string
|
||||
if let Hint::Single(single_hint) = function.autocomplete.hint {
|
||||
if let Some(single_hint) = function.autocomplete.hint.single() {
|
||||
*single_hint
|
||||
} else {
|
||||
""
|
||||
@ -138,7 +137,7 @@ impl FunctionManager {
|
||||
|
||||
function.autocomplete.register_movement(&movement);
|
||||
|
||||
if movement != Movement::Complete && let Hint::Many(hints) = function.autocomplete.hint {
|
||||
if movement != Movement::Complete && let Some(hints) = function.autocomplete.hint.many() {
|
||||
// Doesn't need to have a number in id as there should only be 1 autocomplete popup in the entire gui
|
||||
let popup_id = ui.make_persistent_id("autocomplete_popup");
|
||||
|
||||
|
||||
@ -273,3 +273,18 @@ fn get_last_term() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hint_accessor() {
|
||||
assert_eq!(Hint::Single("hint").many(), None);
|
||||
assert_eq!(Hint::Single("hint").single(), Some(&"hint"));
|
||||
|
||||
assert_eq!(Hint::Many(&["hint", "hint2"]).single(), None);
|
||||
assert_eq!(
|
||||
Hint::Many(&["hint", "hint2"]).many(),
|
||||
Some(&["hint", "hint2"].as_slice())
|
||||
);
|
||||
|
||||
assert_eq!(Hint::None.single(), None);
|
||||
assert_eq!(Hint::None.many(), None);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user