feat(dtmm): Improve mod list visuals
- add checkbox for enable/disable - highlight the selected mod - adding visual spacing - add alternating row background color Ref: #15.
This commit is contained in:
parent
d208c51cb4
commit
e88bc7fb9b
1 changed files with 33 additions and 23 deletions
|
@ -1,11 +1,11 @@
|
||||||
use druid::im::Vector;
|
use druid::im::Vector;
|
||||||
use druid::widget::{
|
use druid::widget::{
|
||||||
Align, Button, CrossAxisAlignment, Flex, Label, LineBreaking, List, MainAxisAlignment, Maybe,
|
Align, Button, Checkbox, CrossAxisAlignment, Flex, Label, LineBreaking, List,
|
||||||
Scroll, SizedBox, Split, TextBox, ViewSwitcher,
|
MainAxisAlignment, Maybe, Scroll, SizedBox, Split, TextBox, ViewSwitcher,
|
||||||
};
|
};
|
||||||
use druid::{
|
use druid::{
|
||||||
lens, FileDialogOptions, FileSpec, FontDescriptor, FontFamily, Insets, LensExt, SingleUse,
|
lens, Color, FileDialogOptions, FileSpec, FontDescriptor, FontFamily, Insets, Key, LensExt,
|
||||||
Widget, WidgetExt, WindowDesc,
|
SingleUse, Widget, WidgetExt, WindowDesc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::state::{ModInfo, PathBufFormatter, State, View, ACTION_START_RESET_DEPLOYMENT};
|
use crate::state::{ModInfo, PathBufFormatter, State, View, ACTION_START_RESET_DEPLOYMENT};
|
||||||
|
@ -21,6 +21,8 @@ const TITLE: &str = "Darktide Mod Manager";
|
||||||
const WINDOW_SIZE: (f64, f64) = (800.0, 600.0);
|
const WINDOW_SIZE: (f64, f64) = (800.0, 600.0);
|
||||||
const MOD_DETAILS_MIN_WIDTH: f64 = 325.0;
|
const MOD_DETAILS_MIN_WIDTH: f64 = 325.0;
|
||||||
|
|
||||||
|
const KEY_MOD_LIST_ITEM_BG_COLOR: Key<Color> = Key::new("dtmm.mod-list.item.background-color");
|
||||||
|
|
||||||
pub(crate) fn new() -> WindowDesc<State> {
|
pub(crate) fn new() -> WindowDesc<State> {
|
||||||
WindowDesc::new(build_window())
|
WindowDesc::new(build_window())
|
||||||
.title(TITLE)
|
.title(TITLE)
|
||||||
|
@ -75,34 +77,42 @@ fn build_top_bar() -> impl Widget<State> {
|
||||||
|
|
||||||
fn build_mod_list() -> impl Widget<State> {
|
fn build_mod_list() -> impl Widget<State> {
|
||||||
let list = List::new(|| {
|
let list = List::new(|| {
|
||||||
|
let checkbox =
|
||||||
|
Checkbox::new("").lens(lens!((usize, ModInfo, bool), 1).then(ModInfo::enabled));
|
||||||
|
let name = Label::raw().lens(lens!((usize, ModInfo, bool), 1).then(ModInfo::name));
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.must_fill_main_axis(true)
|
.must_fill_main_axis(true)
|
||||||
.with_child(
|
.with_child(checkbox)
|
||||||
Label::dynamic(|enabled, _env| {
|
.with_child(name)
|
||||||
if *enabled {
|
.padding((5.0, 4.0))
|
||||||
"Enabled".into()
|
.background(KEY_MOD_LIST_ITEM_BG_COLOR)
|
||||||
|
.on_click(|ctx, (i, _, _), _env| ctx.submit_command(ACTION_SELECT_MOD.with(*i)))
|
||||||
|
.env_scope(|env, (i, _, selected)| {
|
||||||
|
if *selected {
|
||||||
|
env.set(KEY_MOD_LIST_ITEM_BG_COLOR, Color::NAVY);
|
||||||
|
} else if (i % 2) == 1 {
|
||||||
|
env.set(KEY_MOD_LIST_ITEM_BG_COLOR, Color::WHITE.with_alpha(0.05));
|
||||||
} else {
|
} else {
|
||||||
"Disabled".into()
|
env.set(KEY_MOD_LIST_ITEM_BG_COLOR, Color::TRANSPARENT);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.lens(lens!((usize, ModInfo), 1).then(ModInfo::enabled)),
|
|
||||||
)
|
|
||||||
.with_child(Label::raw().lens(lens!((usize, ModInfo), 1).then(ModInfo::name)))
|
|
||||||
.on_click(|ctx, (i, _info), _env| ctx.submit_command(ACTION_SELECT_MOD.with(*i)))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let scroll = Scroll::new(list)
|
let scroll = Scroll::new(list)
|
||||||
.vertical()
|
.vertical()
|
||||||
.lens(State::mods.map(
|
.lens(lens::Identity.map(
|
||||||
|mods| {
|
|state: &State| {
|
||||||
mods.iter()
|
state
|
||||||
|
.mods
|
||||||
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, val)| (i, val.clone()))
|
.map(|(i, val)| (i, val.clone(), Some(i) == state.selected_mod_index))
|
||||||
.collect::<Vector<_>>()
|
.collect::<Vector<_>>()
|
||||||
},
|
},
|
||||||
|mods, infos| {
|
|state, infos| {
|
||||||
infos.into_iter().for_each(|(i, info)| {
|
infos.into_iter().for_each(|(i, info, _)| {
|
||||||
mods.set(i, info);
|
state.mods.set(i, info);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue