The `set_at` function for `requestty_ui::widgets::Select` adjusts the
page bounds if required. However, it wouldn't check if the component has
never been rendered (and so heights never calculated) and thus cause a
panic if called before ever being rendered. Now `set_at` can be called
at any point.
This commit is contained in:
Lutetium-Vanadium 2021-10-25 19:01:30 +05:30
parent 962cb819a8
commit e322486209
5 changed files with 17 additions and 6 deletions

View File

@ -1,5 +1,14 @@
# Changelog
## `0.1.3`
- `requestty`
- Fix #3
- `requestty-ui`
- Update crossterm dependency
## `0.1.2`
- `requestty`

View File

@ -1,6 +1,6 @@
[package]
name = "requestty"
version = "0.1.2"
version = "0.1.3"
authors = ["Lutetium Vanadium"]
edition = "2018"
description = "An easy-to-use collection of interactive cli prompts"
@ -22,7 +22,7 @@ members = [
[dependencies]
tempfile = "3"
ui = { package = "requestty-ui", path = "./requestty-ui", version = "=0.2.0" }
ui = { package = "requestty-ui", path = "./requestty-ui", version = "=0.2.1" }
macro = { package = "requestty-macro", path = "./requestty-macro", optional = true, version = "=0.1.1" }
smallvec = { version = "1.6", optional = true }

View File

@ -1,6 +1,6 @@
[package]
name = "requestty-ui"
version = "0.2.0"
version = "0.2.1"
authors = ["Lutetium Vanadium"]
edition = "2018"
description = "A widget based terminal ui rendering library."
@ -18,7 +18,7 @@ bitflags = "1.2"
textwrap = "0.14"
unicode-segmentation = "1.7"
crossterm = { version = "0.21", optional = true }
crossterm = { version = "0.22", optional = true }
termion = { version = "1.5", optional = true }
[dev-dependencies]

View File

@ -140,7 +140,7 @@ impl<L: List> Select<L> {
if self.is_paginating() {
if at >= self.list.len() {
self.init_page();
} else {
} else if self.heights.is_some() {
self.maybe_adjust_page(dir);
}
}

View File

@ -139,10 +139,12 @@ fn test_selectable() {
let list = select.into_inner().with_should_loop(false);
let mut select = Select::new(list);
select.set_at(2);
select.maybe_update_heights(Layout::new(0, (100, 20).into()));
select.init_page();
assert_eq!(select.get_at(), 1);
assert_eq!(select.get_at(), 2);
select.set_at(0);
assert_eq!(select.prev_selectable(), 1);
select.set_at(1);