Start block implementation
This commit is contained in:
parent
0191579f4d
commit
3d1c73ee2a
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::cmp::max;
|
||||||
|
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
@ -22,9 +23,10 @@ pub struct Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Level {
|
impl Level {
|
||||||
pub fn from(ctx: &CmdLineContext, render_state: &shell::RenderState) -> Self {
|
pub fn from_ctx(ctx: &CmdLineContext, render_state: &shell::RenderState) -> Self {
|
||||||
//TODO: double width chars render, also note in text wrapping
|
//TODO: double width chars render, also note in text wrapping
|
||||||
//TODO: im
|
//TODO: im
|
||||||
|
//TODO: cursor
|
||||||
|
|
||||||
let content_line: Vec<(Option<Attrs>, Vec<char>)> = ctx.content
|
let content_line: Vec<(Option<Attrs>, Vec<char>)> = ctx.content
|
||||||
.iter()
|
.iter()
|
||||||
@ -53,11 +55,7 @@ impl Level {
|
|||||||
let mut model_layout = ModelLayout::new();
|
let mut model_layout = ModelLayout::new();
|
||||||
let (columns, rows) = model_layout.layout(content, max_width_chars);
|
let (columns, rows) = model_layout.layout(content, max_width_chars);
|
||||||
|
|
||||||
let columns = if columns < 5 {
|
let columns = max(columns, 5);
|
||||||
5
|
|
||||||
} else {
|
|
||||||
columns
|
|
||||||
};
|
|
||||||
|
|
||||||
let preferred_width = (char_width * columns as f64) as i32;
|
let preferred_width = (char_width * columns as f64) as i32;
|
||||||
let preferred_height = (line_height * rows as f64) as i32;
|
let preferred_height = (line_height * rows as f64) as i32;
|
||||||
@ -98,6 +96,7 @@ fn prompt_lines(firstc: &str, prompt: &str, indent: u64) -> Vec<(Option<Attrs>,
|
|||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
levels: Vec<Level>,
|
levels: Vec<Level>,
|
||||||
|
block: Option<Level>,
|
||||||
render_state: Rc<RefCell<shell::RenderState>>,
|
render_state: Rc<RefCell<shell::RenderState>>,
|
||||||
drawing_area: gtk::DrawingArea,
|
drawing_area: gtk::DrawingArea,
|
||||||
}
|
}
|
||||||
@ -106,6 +105,7 @@ impl State {
|
|||||||
fn new(drawing_area: gtk::DrawingArea, render_state: Rc<RefCell<shell::RenderState>>) -> Self {
|
fn new(drawing_area: gtk::DrawingArea, render_state: Rc<RefCell<shell::RenderState>>) -> Self {
|
||||||
State {
|
State {
|
||||||
levels: Vec::new(),
|
levels: Vec::new(),
|
||||||
|
block: None,
|
||||||
render_state,
|
render_state,
|
||||||
drawing_area,
|
drawing_area,
|
||||||
}
|
}
|
||||||
@ -152,16 +152,10 @@ impl CmdLine {
|
|||||||
pub fn show_level(&mut self, ctx: &CmdLineContext) {
|
pub fn show_level(&mut self, ctx: &CmdLineContext) {
|
||||||
let mut state = self.state.borrow_mut();
|
let mut state = self.state.borrow_mut();
|
||||||
|
|
||||||
let mut level = Level::from(ctx, &*state.render_state.borrow());
|
let mut level = Level::from_ctx(ctx, &*state.render_state.borrow());
|
||||||
level.update_cache(&*state.render_state.borrow());
|
level.update_cache(&*state.render_state.borrow());
|
||||||
|
|
||||||
let preferred_height = if level.preferred_height < 40 {
|
state.drawing_area.set_size_request(level.preferred_width, max(level.preferred_height, 40));
|
||||||
40
|
|
||||||
} else {
|
|
||||||
level.preferred_height
|
|
||||||
};
|
|
||||||
|
|
||||||
state.drawing_area.set_size_request(level.preferred_width, preferred_height);
|
|
||||||
|
|
||||||
if ctx.level_idx as usize == state.levels.len() {
|
if ctx.level_idx as usize == state.levels.len() {
|
||||||
// TODO: update level
|
// TODO: update level
|
||||||
@ -195,6 +189,10 @@ impl CmdLine {
|
|||||||
self.displyed = false;
|
self.displyed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn show_block(&mut self, content: Vec<Vec<(HashMap<String, Value>, String)>>) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtk_draw(
|
fn gtk_draw(
|
||||||
|
@ -76,10 +76,17 @@ pub trait RedrawEvents {
|
|||||||
indent: u64,
|
indent: u64,
|
||||||
level: u64,
|
level: u64,
|
||||||
) -> RepaintMode;
|
) -> RepaintMode;
|
||||||
|
|
||||||
fn cmdline_hide(
|
fn cmdline_hide(&mut self, level: u64) -> RepaintMode;
|
||||||
|
|
||||||
|
fn cmdline_block_show(
|
||||||
&mut self,
|
&mut self,
|
||||||
level: u64,
|
content: Vec<Vec<(HashMap<String, Value>, String)>>,
|
||||||
|
) -> RepaintMode;
|
||||||
|
|
||||||
|
fn cmdline_block_append(
|
||||||
|
&mut self,
|
||||||
|
content: Vec<Vec<(HashMap<String, Value>, String)>>,
|
||||||
) -> RepaintMode;
|
) -> RepaintMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,6 +268,8 @@ pub fn call(
|
|||||||
ui.mode_info_set(try_bool!(args[0]), mode_info)
|
ui.mode_info_set(try_bool!(args[0]), mode_info)
|
||||||
}
|
}
|
||||||
"cmdline_show" => call!(ui->cmdline_show(args: ext, uint, str, str, uint, uint)),
|
"cmdline_show" => call!(ui->cmdline_show(args: ext, uint, str, str, uint, uint)),
|
||||||
|
"cmdline_block_show" => call!(ui->cmdline_block_show(args: ext)),
|
||||||
|
"cmdline_block_append" => call!(ui->cmdline_block_append(args: ext)),
|
||||||
"cmdline_hide" => call!(ui->cmdline_hide(args: uint)),
|
"cmdline_hide" => call!(ui->cmdline_hide(args: uint)),
|
||||||
_ => {
|
_ => {
|
||||||
println!("Event {}({:?})", method, args);
|
println!("Event {}({:?})", method, args);
|
||||||
@ -292,4 +301,3 @@ impl<'a> CompleteItem<'a> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
src/shell.rs
15
src/shell.rs
@ -1211,6 +1211,21 @@ impl RedrawEvents for State {
|
|||||||
self.cmd_line.hide_level(level);
|
self.cmd_line.hide_level(level);
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cmdline_block_show(
|
||||||
|
&mut self,
|
||||||
|
content: Vec<Vec<(HashMap<String, Value>, String)>>,
|
||||||
|
) -> RepaintMode {
|
||||||
|
self.cmd_line.show_block(content);
|
||||||
|
RepaintMode::Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cmdline_block_append(
|
||||||
|
&mut self,
|
||||||
|
content: Vec<Vec<(HashMap<String, Value>, String)>>,
|
||||||
|
) -> RepaintMode {
|
||||||
|
RepaintMode::Nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CursorRedrawCb for State {
|
impl CursorRedrawCb for State {
|
||||||
|
Loading…
Reference in New Issue
Block a user