You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.8 KiB
Rust

//use glium::glutin::window::Window as GlutinWindow;
use glium::Display;
use imgui::{Window, Ui, Condition};
use crate::ui_generic::drag_area::DragArea;
use crate::ui_generic::keyframe_editor::KeyframeEditor;
use crate::storage::Storage;
const DRAG_AREA_MIN_SIZE: [f32; 2] = [300.0, 300.0];
const WIN_SIZE: [f32; 2] = [
DRAG_AREA_MIN_SIZE[0] + 15.0,
DRAG_AREA_MIN_SIZE[1] + 100.0
];
const WIN_MIN_SIZE: [f32; 2] = WIN_SIZE;
pub struct MainWindow {
pub size: [f32; 2],
default_size: [f32; 2],
min_size: [f32; 2],
editor: KeyframeEditor,
string_buf: String
}
impl MainWindow {
pub fn init() -> MainWindow {
MainWindow {
size: WIN_SIZE,
default_size: WIN_SIZE,
min_size: WIN_MIN_SIZE,
editor: KeyframeEditor::new(DRAG_AREA_MIN_SIZE),
string_buf: String::new()
}
}
pub fn build(
&mut self,
ui: &Ui,
display: &Display,
storage: &mut Storage
) {
Window::new("Main Window")
.size(self.size, Condition::FirstUseEver)
.size_constraints(self.min_size, [1000.0, 1000.0])
.build(&ui, || {
MainWindow::build_window_contents(
self,
ui,
display,
storage
)
});
}
fn build_window_contents(
self: &mut MainWindow,
ui: &Ui,
display: &Display,
storage: &mut Storage
) {
let win_size = ui.window_size();
self.editor.drag_area.size = [
win_size[0] - 20.0,
win_size[1] - 100.0
];
ui.same_line();
let dec_bpm = ui.button("-");
ui.same_line();
ui.text(format!("{} bpm", storage.initial_bpm()));
ui.same_line();
let inc_bpm = ui.button("+");
if dec_bpm { storage.bpm_changes[0].bpm -= 1; }
if inc_bpm { storage.bpm_changes[0].bpm += 1; }
ui.same_line();
let kf_name_input = ui
.input_text("", &mut self.string_buf)
.hint(format!(
"name new keyframe channel · {} in current project",
storage.keyframe_channels.len()
))
.enter_returns_true(true)
.build();
ui.same_line();
let add_kf_chan = ui.button("add keyframe channel");
if (kf_name_input || add_kf_chan) && !self.string_buf.is_empty() {
storage.add_keyframe_channel(String::from(&self.string_buf));
self.string_buf.clear();
}
ui.separator();
self.editor.build(ui, display, storage);
draw_mouse_pos_text(ui);
}
}
fn draw_mouse_pos_text(ui: &Ui) {
let mouse_pos = ui.io().mouse_pos;
ui.text(format!(
"mouse pos: ({:.1}, {:.1})",
mouse_pos[0], mouse_pos[1]
));
}