mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-30 13:04:13 +00:00
update navigation buttons state
This commit is contained in:
parent
a25c171e0e
commit
dfa8c7a998
@ -64,7 +64,7 @@ impl Form {
|
|||||||
match_case.is_active(),
|
match_case.is_active(),
|
||||||
);
|
);
|
||||||
input.update(!matches.is_empty());
|
input.update(!matches.is_empty());
|
||||||
navigation.update(matches);
|
navigation.renew(matches);
|
||||||
if !this.text().is_empty() {
|
if !this.text().is_empty() {
|
||||||
result.update(navigation.position(), navigation.total());
|
result.update(navigation.position(), navigation.total());
|
||||||
result.label.set_visible(true);
|
result.label.set_visible(true);
|
||||||
@ -109,7 +109,7 @@ impl Form {
|
|||||||
this.is_active(),
|
this.is_active(),
|
||||||
);
|
);
|
||||||
input.update(!matches.is_empty());
|
input.update(!matches.is_empty());
|
||||||
navigation.update(matches);
|
navigation.renew(matches);
|
||||||
if !input.entry.text().is_empty() {
|
if !input.entry.text().is_empty() {
|
||||||
result.update(navigation.position(), navigation.total());
|
result.update(navigation.position(), navigation.total());
|
||||||
result.label.set_visible(true);
|
result.label.set_visible(true);
|
||||||
@ -129,6 +129,7 @@ impl Form {
|
|||||||
Some(subject) => {
|
Some(subject) => {
|
||||||
match navigation.back(subject) {
|
match navigation.back(subject) {
|
||||||
Some((mut start, _)) => {
|
Some((mut start, _)) => {
|
||||||
|
navigation.update();
|
||||||
result.update(navigation.position(), navigation.total());
|
result.update(navigation.position(), navigation.total());
|
||||||
scroll_to_iter(&subject.text_view, &mut start)
|
scroll_to_iter(&subject.text_view, &mut start)
|
||||||
}
|
}
|
||||||
@ -146,6 +147,7 @@ impl Form {
|
|||||||
move |_| match subject.borrow().as_ref() {
|
move |_| match subject.borrow().as_ref() {
|
||||||
Some(subject) => match navigation.forward(subject) {
|
Some(subject) => match navigation.forward(subject) {
|
||||||
Some((mut start, _)) => {
|
Some((mut start, _)) => {
|
||||||
|
navigation.update();
|
||||||
result.update(navigation.position(), navigation.total());
|
result.update(navigation.position(), navigation.total());
|
||||||
scroll_to_iter(&subject.text_view, &mut start)
|
scroll_to_iter(&subject.text_view, &mut start)
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,17 @@ impl Navigation {
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
/// Update widget state, including child components
|
/// Update navigation model
|
||||||
pub fn update(&self, matches: Vec<(TextIter, TextIter)>) {
|
pub fn renew(&self, matches: Vec<(TextIter, TextIter)>) {
|
||||||
self.back.update(!matches.is_empty());
|
|
||||||
self.forward.update(!matches.is_empty());
|
|
||||||
self.model.replace(Model::new(matches));
|
self.model.replace(Model::new(matches));
|
||||||
|
self.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update widget including child components
|
||||||
|
pub fn update(&self) {
|
||||||
|
let model = self.model.borrow();
|
||||||
|
self.back.update(model.is_back());
|
||||||
|
self.forward.update(model.is_next());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Navigate back in matches, apply tags to the buffer
|
/// Navigate back in matches, apply tags to the buffer
|
||||||
|
@ -7,6 +7,7 @@ pub struct Model<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Model<T> {
|
impl<T> Model<T> {
|
||||||
|
// Constructors
|
||||||
pub fn new(vector: Vec<T>) -> Self {
|
pub fn new(vector: Vec<T>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
cursor: Cursor::new(vector.len()),
|
cursor: Cursor::new(vector.len()),
|
||||||
@ -14,6 +15,8 @@ impl<T> Model<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
pub fn back(&mut self) -> Option<&T> {
|
pub fn back(&mut self) -> Option<&T> {
|
||||||
self.cursor.back();
|
self.cursor.back();
|
||||||
self.vector.get(self.cursor.as_index())
|
self.vector.get(self.cursor.as_index())
|
||||||
@ -24,6 +27,8 @@ impl<T> Model<T> {
|
|||||||
self.vector.get(self.cursor.as_index())
|
self.vector.get(self.cursor.as_index())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
|
||||||
pub fn position(&self) -> Option<usize> {
|
pub fn position(&self) -> Option<usize> {
|
||||||
self.cursor.as_position()
|
self.cursor.as_position()
|
||||||
}
|
}
|
||||||
@ -31,4 +36,12 @@ impl<T> Model<T> {
|
|||||||
pub fn total(&self) -> usize {
|
pub fn total(&self) -> usize {
|
||||||
self.vector.len()
|
self.vector.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_back(&self) -> bool {
|
||||||
|
self.cursor.is_back()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_next(&self) -> bool {
|
||||||
|
self.cursor.is_next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ pub struct Cursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Cursor {
|
impl Cursor {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
pub fn new(len: usize) -> Self {
|
pub fn new(len: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
current: 0,
|
current: 0,
|
||||||
@ -11,6 +13,8 @@ impl Cursor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
pub fn back(&mut self) {
|
pub fn back(&mut self) {
|
||||||
self.current = if self.current > 0 {
|
self.current = if self.current > 0 {
|
||||||
self.current - 1
|
self.current - 1
|
||||||
@ -27,6 +31,8 @@ impl Cursor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
|
||||||
pub fn as_index(&self) -> usize {
|
pub fn as_index(&self) -> usize {
|
||||||
if self.current > 0 {
|
if self.current > 0 {
|
||||||
self.current - 1
|
self.current - 1
|
||||||
@ -42,4 +48,12 @@ impl Cursor {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_back(&self) -> bool {
|
||||||
|
self.current > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_next(&self) -> bool {
|
||||||
|
self.current < self.last
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user