feat(dtmm): Automatically scroll log view
This commit is contained in:
parent
f7627c091b
commit
d208c51cb4
2 changed files with 25 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
use druid::widget::{Button, Controller};
|
||||
use druid::{Data, Env, Event, EventCtx, LifeCycle, LifeCycleCtx, UpdateCtx, Widget};
|
||||
use druid::widget::{Button, Controller, Scroll};
|
||||
use druid::{Data, Env, Event, EventCtx, LifeCycle, LifeCycleCtx, Rect, UpdateCtx, Widget};
|
||||
|
||||
pub struct DisabledButtonController;
|
||||
|
||||
|
@ -45,3 +45,23 @@ impl<T: Data> Controller<T, Button<T>> for DisabledButtonController {
|
|||
child.update(ctx, old_data, data, env)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AutoScrollController;
|
||||
|
||||
impl<T: Data, W: Widget<T>> Controller<T, Scroll<T, W>> for AutoScrollController {
|
||||
fn update(
|
||||
&mut self,
|
||||
child: &mut Scroll<T, W>,
|
||||
ctx: &mut UpdateCtx,
|
||||
old_data: &T,
|
||||
data: &T,
|
||||
env: &Env,
|
||||
) {
|
||||
if !ctx.is_disabled() {
|
||||
let size = child.child_size();
|
||||
let end_region = Rect::new(size.width - 1., size.height - 1., size.width, size.height);
|
||||
child.scroll_to(ctx, end_region);
|
||||
}
|
||||
child.update(ctx, old_data, data, env)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use crate::state::{
|
|||
ACTION_START_DELETE_SELECTED_MOD, ACTION_START_DEPLOY,
|
||||
};
|
||||
use crate::ui::theme;
|
||||
use crate::ui::widget::controller::AutoScrollController;
|
||||
use crate::ui::widget::ExtraWidgetExt;
|
||||
|
||||
const TITLE: &str = "Darktide Mod Manager";
|
||||
|
@ -267,7 +268,8 @@ fn build_log_view() -> impl Widget<State> {
|
|||
.with_line_break_mode(LineBreaking::WordWrap)
|
||||
.lens(State::log)
|
||||
.scroll()
|
||||
.vertical();
|
||||
.vertical()
|
||||
.controller(AutoScrollController);
|
||||
|
||||
SizedBox::new(label).expand_width().height(128.0)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue