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
|
||||
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
|
||||
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 {
|
||||
Self::new_from_regex([
|
||||
// // Links
|
||||
// (TokenKind::String, r"\[[^\]]*\](\([^\)]*\))?"),
|
||||
// Header
|
||||
(TokenKind::Doc, r#"^\[[^\]]*\]$"#),
|
||||
(TokenKind::Doc, r#"^\[[^\n\]]*\]$"#),
|
||||
// Delimiters
|
||||
(TokenKind::Delimiter, r"[\{\}\(\)\[\]]"),
|
||||
// Operators
|
||||
|
|
@ -236,7 +234,7 @@ impl Highlighter {
|
|||
// Identifier
|
||||
(TokenKind::Ident, r"\b[a-z_][A-Za-z0-9_\-]*\b"),
|
||||
// Comments
|
||||
(TokenKind::Comment, r"^#[^$]*$"),
|
||||
(TokenKind::Comment, r"#[^$]*$"),
|
||||
])
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ impl Visual for Label {
|
|||
|
||||
/// List selection
|
||||
pub struct Options<T> {
|
||||
pub focus: usize,
|
||||
pub selected: usize,
|
||||
// (score, option)
|
||||
pub options: Vec<T>,
|
||||
|
|
@ -116,6 +117,7 @@ impl<T> Options<T> {
|
|||
pub fn new(options: impl IntoIterator<Item = T>) -> Self {
|
||||
let (ranking, options) = options.into_iter().enumerate().unzip();
|
||||
Self {
|
||||
focus: 0,
|
||||
selected: 0,
|
||||
options,
|
||||
ranking,
|
||||
|
|
@ -188,10 +190,18 @@ impl<T: Visual> Visual for Options<T> {
|
|||
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];
|
||||
frame
|
||||
.rect([0, i], [frame.size()[0], 1])
|
||||
.rect([0, row], [frame.size()[0], 1])
|
||||
.with_bg(if self.selected == i {
|
||||
state.theme.select_bg
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue