Closed TimUntersberger closed 4 years ago
Idea
trait BarComponent {
fn get_width() -> i32;
fn render() -> String;
fn should_render(reason: RedrawAppBarReason) -> Bool;
}
The bar would then have a list of (Alignment, BarComponent)
where Alignment
is the following enum.
enum Alignment {
Left,
Center,
Right
}
Example: Date Component
define component
#[derive(Default)]
struct DateComponent;
impl BarComponent for DateComponent {
pub const fn get_width() -> i32 { 10 }
pub fn should_render(reason: RedrawReason) -> bool { reason == RedrawReason::Date }
pub fn render() -> String {
let config = &CONFIG.lock().unwrap();
now().format(config.app_bar_date_pattern)
}
}
register component
let bar = Bar::default();
bar.add_component((Alignment::Right, DateComponent::default));
config
bar #{
components: [
["Right", DateComponent()],
["Left", DateComponent("%v")]
]
}
I am not sure about the syntax for defining the components in the config. The current solution looks kind of ugly and is annoying to write. Any suggestions are welcomed (You can even define your own syntax :) )!
The appbar is now completely modular.
This is how it looks in the code
items.push(Item::new(Alignment::Left, workspaces::create()));
items.push(Item::new(Alignment::Center, time::create()));
items.push(Item::new(Alignment::Right, date::create()));
items.push(Item::new(Alignment::Right, padding::create(5)));
items.push(Item::new(Alignment::Right, mode::create()));
The problem now is: How can the user define this in the config?
Here is a statusline plugin I use for vim: https://github.com/itchyny/lightline.vim
Here is a sample config for it.
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename' ] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype', 'charvaluehex' ] ]
\ },
\ 'component': {
\ 'charvaluehex': '0x%B'
\ },
\ }
Maybe something like this could work. Plus since rhai is a scripting language would it be possible for the user to create their own widgets and push it to the app bar?
Maybe something like this could work. Plus since rhai is a scripting language would it be possible for the user to create their own widgets and push it to the app bar
Holy shit. I think you are right. I will have to test this.
The appbar is currently hardcoded and this makes it now very difficult to add features.
Somehow find a way to make the
appbar
as modular as reasonably possible.It should be possible to toggle every item and reposition them.
Adding a new feature also shouldn't be so annoying.