Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive height with animation #143

Closed
wants to merge 7 commits into from
Closed

Conversation

filtsin
Copy link
Contributor

@filtsin filtsin commented Feb 25, 2023

Add animation.rs with some math for animations and new features:

Params

Global:

List items section

  • show_default: true | false (default true): enable or disable items list for empty input

New animation section (if it is present, then animations are enabled)

  • height_duration_ms: for height animation

src/main.rs Outdated Show resolved Hide resolved
src/animation.rs Outdated Show resolved Hide resolved
src/animation.rs Outdated Show resolved Hide resolved
src/animation.rs Outdated Show resolved Hide resolved
src/draw.rs Outdated Show resolved Hide resolved
let mut last_y = point.y as u32
- self.params.font_size as u32
- self.params.margin.bottom as u32
- ADDITIONAL_CAP;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this constant is needed

Copy link
Contributor Author

@filtsin filtsin Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why I choosed ADDITIONAL_CAP=10. But it is very little extra space just to make sure the last line fits in the window because of font draw that can move letters lower for correct layout

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it should be something proportional to font_size? E.g font_size / 2

) {
use std::iter::once;

state.process_entries();
state.process_entries(list_config.show_default);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something wrong with encapsulation here. List config is intended to be using only inside list_view.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think that state is global app with possible access to all configs. Additionaly it is very intuitive to see show_default parameter in [list_items] section, on my opinion. But I can move it to global section of Config if you want it.


// Hack for input_changed: If input buffer capacity is 0 then we do not typing
// anything, so disable animation for first calls of draw (for support
// ListItem::show_default)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This hack is inside input_changed, right?
  2. Why it's capacity and not length?
  3. Actually animation is added here, why it stated it's disabled then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this hack inside input_changed. Length of string will be zero if we are typing something and delete it. But capacity will not be zero anymore because we don't free string. It is for first draw of yofi.
Render:

  1. Run yofi
  2. Draw window with height from Config
  3. Try to place list_items in here
  4. Truncate height to new height with removing unused height space. If it is just a first render we do not want to see this "jumping" window, but only input, thats why i added this

@filtsin
Copy link
Contributor Author

filtsin commented Mar 13, 2023

Thank you for review. I committed my changes and updated pr description.

@l4l
Copy link
Owner

l4l commented Mar 16, 2023

Screenshot_2023 03 16_21:45:35

Something wrong with the end of border calculation here I guess? (it's half of the size, so yes animation is enabled)

Also when I was taking a screenshot for some reason it plays animation from the original size.

@filtsin
Copy link
Contributor Author

filtsin commented Mar 17, 2023

Sorry, I can't understand what is the problem. Did you turn on the animation and nothing happened?
What's your duration value?

[animation]
height_duration_ms = ?

There is one more param for height change: auto_height in global section. Did you set it? (Maybe remove this because we have height_duration_ms?)

@l4l
Copy link
Owner

l4l commented Mar 17, 2023

Sorry, I can't understand what is the problem. Did you turn on the animation and nothing happened?

Yeah, the screenshot was a really dumb way to explain the issue, sorry. I did enable animation and it mostly works. auto_height is also enabled. It should be independent of height_duration_ms value. See the demo:

demo.webm

@filtsin
Copy link
Contributor Author

filtsin commented Mar 17, 2023

Thank you. I reproduced it myself with hide_actions = false. I'll try to fix it

@filtsin
Copy link
Contributor Author

filtsin commented Mar 22, 2023

Can you check again with new changes?

Copy link
Owner

@l4l l4l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demo.webm

Sorry for the late reply. I'm still able to reproduce the issue. You could use seq 15 | yofi dialog for that.

let current_time = Instant::now();

for name in std::mem::take(&mut self.remove_later).into_iter() {
self.animations.remove(&name).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could get a panic here, reproduction:

seq 100 | cargo r dialog (debug build is important)

then quickly type any two digits

@@ -100,14 +108,19 @@ where
(self.selected_item - self.skip_offset, self.skip_offset)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether it's related but this piece of code above gives a panic now if running in debug build. So this code should work:

let displayed_items = (((space.height - margin.top - margin.bottom + item_spacing)
    / (entry_height + item_spacing)) as usize)
    .saturating_sub(has_subname as usize);

let max_offset = self.skip_offset + displayed_items;
let (selected_item, skip_offset) = if self.selected_item < self.skip_offset {
    (0, self.selected_item)
} else if max_offset <= self.selected_item {
    (
        displayed_items.saturating_sub(1),
        self.skip_offset + (self.selected_item - max_offset) + 1,
    )
} else {
    (self.selected_item - self.skip_offset, self.skip_offset)
};

@filtsin
Copy link
Contributor Author

filtsin commented Dec 17, 2023

Sorry no time for this pr and no interest. If someone want to continue work on animations welcome to take my code :). I'm using my branch for adaptive height but without animation (turns out it looks good)

@filtsin filtsin closed this Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for adaptive height when using layer shell mode
2 participants