-
-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
questionQuestions about the libraryQuestions about the library
Description
Let's consider a simple progress bar component: I need to render a background bar and a bar above the background, which is easy. But if I try to create a handler for clicking on the progress bar, I can get the column -- bug I can't get percents from it (e.g. column 4 in a 10 wide progress bar is 40%). For example this is my implementation of a progress bar:
#[derive(Default, Props)]
pub struct ProgressBarProps {
pub progress: f32,
pub handler: Handler<'static, f32>,
}
#[component]
pub fn ProgressBar(mut hooks: Hooks, props: &ProgressBarProps) -> impl Into<AnyElement<'static>> {
let (width, _) = hooks.use_terminal_size();
let amount = props.progress.clamp(0.0, 1.0);
hooks.use_local_terminal_events(|event| match event {
TerminalEvent::FullscreenMouse(FullscreenMouseEvent {
column,
kind: MouseEventKind::Down(_),
..
}) => props.handler(/* ??? */),
_ => {},
});
element! {
View(width: Percent(100.0), height: 1, overflow: Overflow::Hidden) {
View(position: Position::Absolute) {
Text(content: "·".repeat(width as usize), weight: Weight::Light)
}
View(width: Percent(100.0 * amount), position: Position::Absolute) {
Text(content: "—".repeat(width as usize), color: Color::Magenta)
}
}
}
}I can render it fine, but since I can't seem to get width of the parent component, I'm required to use the whole terminal width -- which can work with Overflow::Hidden for other components, but won't work for math and events ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionQuestions about the libraryQuestions about the library