Support for large option lists
This commit is contained in:
parent
33185c30a0
commit
12a51b27eb
2 changed files with 15 additions and 7 deletions
|
|
@ -205,16 +205,14 @@ impl Highlighter {
|
||||||
// types
|
// types
|
||||||
r"\b[(u?int)(float)(double)(bool)(void)([ui]?vec[1-4]*)([ui]?mat[1-4]*)(texture[(2D)(3D)]?(Cube)?)([ui]?sampler[(2D)(3D)]?(Shadow)?)]\b",
|
r"\b[(u?int)(float)(double)(bool)(void)([ui]?vec[1-4]*)([ui]?mat[1-4]*)(texture[(2D)(3D)]?(Cube)?)([ui]?sampler[(2D)(3D)]?(Shadow)?)]\b",
|
||||||
// Builtins
|
// Builtins
|
||||||
r"\b[(dot)(cross)(textureSize)(normalize)(texelFetch)(textureProj)(max)(min)(clamp)(reflect)(mix)(distance)(length)(abs)(pow)(sign)(sin)(cos)(tan)(fract)(mod)]\b",
|
r"\b[(dot)(cross)(textureSize)(normalize)(texelFetch)(textureProj)(max)(min)(clamp)(reflect)(mix)(distance)(length)(abs)(pow)(sign)(sin)(cos)(tan)(fract)(mod)(round)(step)]\b",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toml() -> Self {
|
pub fn toml() -> Self {
|
||||||
Self::new_from_regex([
|
Self::new_from_regex([
|
||||||
// // Links
|
|
||||||
// (TokenKind::String, r"\[[^\]]*\](\([^\)]*\))?"),
|
|
||||||
// Header
|
// Header
|
||||||
(TokenKind::Doc, r#"^\[[^\]]*\]$"#),
|
(TokenKind::Doc, r#"^\[[^\n\]]*\]$"#),
|
||||||
// Delimiters
|
// Delimiters
|
||||||
(TokenKind::Delimiter, r"[\{\}\(\)\[\]]"),
|
(TokenKind::Delimiter, r"[\{\}\(\)\[\]]"),
|
||||||
// Operators
|
// Operators
|
||||||
|
|
@ -236,7 +234,7 @@ impl Highlighter {
|
||||||
// Identifier
|
// Identifier
|
||||||
(TokenKind::Ident, r"\b[a-z_][A-Za-z0-9_\-]*\b"),
|
(TokenKind::Ident, r"\b[a-z_][A-Za-z0-9_\-]*\b"),
|
||||||
// Comments
|
// Comments
|
||||||
(TokenKind::Comment, r"^#[^$]*$"),
|
(TokenKind::Comment, r"#[^$]*$"),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ impl Visual for Label {
|
||||||
|
|
||||||
/// List selection
|
/// List selection
|
||||||
pub struct Options<T> {
|
pub struct Options<T> {
|
||||||
|
pub focus: usize,
|
||||||
pub selected: usize,
|
pub selected: usize,
|
||||||
// (score, option)
|
// (score, option)
|
||||||
pub options: Vec<T>,
|
pub options: Vec<T>,
|
||||||
|
|
@ -116,6 +117,7 @@ impl<T> Options<T> {
|
||||||
pub fn new(options: impl IntoIterator<Item = T>) -> Self {
|
pub fn new(options: impl IntoIterator<Item = T>) -> Self {
|
||||||
let (ranking, options) = options.into_iter().enumerate().unzip();
|
let (ranking, options) = options.into_iter().enumerate().unzip();
|
||||||
Self {
|
Self {
|
||||||
|
focus: 0,
|
||||||
selected: 0,
|
selected: 0,
|
||||||
options,
|
options,
|
||||||
ranking,
|
ranking,
|
||||||
|
|
@ -188,10 +190,18 @@ impl<T: Visual> Visual for Options<T> {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (i, idx) in self.ranking.iter().enumerate() {
|
self.focus = self
|
||||||
|
.focus
|
||||||
|
.max(
|
||||||
|
self.selected
|
||||||
|
.saturating_sub(frame.size()[1].saturating_sub(1)),
|
||||||
|
)
|
||||||
|
.min(self.selected);
|
||||||
|
|
||||||
|
for (row, (i, idx)) in self.ranking.iter().enumerate().skip(self.focus).enumerate() {
|
||||||
let option = &mut self.options[*idx];
|
let option = &mut self.options[*idx];
|
||||||
frame
|
frame
|
||||||
.rect([0, i], [frame.size()[0], 1])
|
.rect([0, row], [frame.size()[0], 1])
|
||||||
.with_bg(if self.selected == i {
|
.with_bg(if self.selected == i {
|
||||||
state.theme.select_bg
|
state.theme.select_bg
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue