Add combobox for encoding type
This commit is contained in:
parent
6375183624
commit
454fa43492
|
@ -1,27 +1,63 @@
|
||||||
use crate::MainWindow;
|
use crate::MainWindow;
|
||||||
use super::{GUIElements, GUIElementsRef, MainWindowRef, display_error};
|
use super::{GUIElements, GUIElementsRef, MainWindowRef, display_error};
|
||||||
use slint::Image;
|
use slint::{Image, SharedString};
|
||||||
|
use std::rc::Rc;
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
pub struct FileTab {
|
pub struct FileTab {
|
||||||
main_window: MainWindowRef
|
main_window: MainWindowRef,
|
||||||
|
encoding_options: Rc<slint::VecModel<SharedString>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileTab {
|
impl FileTab {
|
||||||
|
fn update_encoding_options(&self, width: u32, height: u32, has_palette: bool) -> Result<(), Error> {
|
||||||
|
self.encoding_options.clear();
|
||||||
|
|
||||||
|
if has_palette {
|
||||||
|
let has_4bit = width%4 == 0;
|
||||||
|
let has_8bit = width%2 == 0;
|
||||||
|
|
||||||
|
if !has_4bit && !has_8bit {
|
||||||
|
return Err(Error::from_text(format!("Image width must be multiple of 2 and or 4 ({}/{})", width, height)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if has_4bit {
|
||||||
|
self.encoding_options.push(SharedString::from(format!("4 bit ({}/{})", width/4, height)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if has_8bit {
|
||||||
|
self.encoding_options.push(SharedString::from(format!("8 bit ({}/{})", width/2, height)));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
self.encoding_options.push(SharedString::from(format!("16 bit ({}/{})", width, height)));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(main_window: MainWindowRef) -> FileTab {
|
pub fn new(main_window: MainWindowRef) -> FileTab {
|
||||||
FileTab{main_window}
|
let encoding_options = Rc::new(slint::VecModel::from(Vec::<SharedString>::new()));
|
||||||
|
|
||||||
|
main_window.borrow().set_file_tab_encoding_options(encoding_options.clone().into());
|
||||||
|
FileTab{main_window, encoding_options}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_load(&self) {
|
pub fn clear_load(&self) {
|
||||||
let main_window = self.main_window.borrow();
|
let main_window = self.main_window.borrow();
|
||||||
|
|
||||||
|
self.encoding_options.clear();
|
||||||
main_window.set_file_tab_browse_path("".into());
|
main_window.set_file_tab_browse_path("".into());
|
||||||
main_window.set_file_tab_image_data(Image::default());
|
main_window.set_file_tab_image_data(Image::default());
|
||||||
|
main_window.set_file_tab_palette_data(Image::default());
|
||||||
main_window.set_file_tab_image_name("".into());
|
main_window.set_file_tab_image_name("".into());
|
||||||
main_window.set_file_tab_enable(false);
|
main_window.set_file_tab_enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_new_loaded_file(&self, file_name: Option<String>, image: Image, palette: Option<Image>) {
|
pub fn update_new_loaded_file(&self, file_name: Option<String>, image: Image, palette: Option<Image>) -> Result<(), Error> {
|
||||||
|
let has_palette = palette.is_some();
|
||||||
|
|
||||||
self.update_palette(palette);
|
self.update_palette(palette);
|
||||||
|
|
||||||
let main_window = self.main_window.borrow();
|
let main_window = self.main_window.borrow();
|
||||||
|
@ -37,7 +73,10 @@ impl FileTab {
|
||||||
else {
|
else {
|
||||||
main_window.set_file_tab_image_name("".into());
|
main_window.set_file_tab_image_name("".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_encoding_options(image_size.width, image_size.height, has_palette)?;
|
||||||
main_window.set_file_tab_enable(true);
|
main_window.set_file_tab_enable(true);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_palette(&self, palette: Option<Image>) {
|
pub fn update_palette(&self, palette: Option<Image>) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
|
||||||
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
||||||
return Err(Error::from_text(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT)));
|
return Err(Error::from_text(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT)));
|
||||||
}
|
}
|
||||||
file_tab.update_new_loaded_file(file_name, image, palette);
|
return file_tab.update_new_loaded_file(file_name, image, palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -13,6 +13,7 @@ export component MainWindow inherits Window {
|
||||||
callback move_vram_image <=> main_tab.move_vram_image;
|
callback move_vram_image <=> main_tab.move_vram_image;
|
||||||
|
|
||||||
// Convert Image values
|
// Convert Image values
|
||||||
|
in-out property file_tab-encoding_options <=> file_tab.conv-encoding_options;
|
||||||
in-out property file_tab-browse_path <=> file_tab.conv-image_path;
|
in-out property file_tab-browse_path <=> file_tab.conv-image_path;
|
||||||
in-out property file_tab-image_data <=> file_tab.conv-image_data;
|
in-out property file_tab-image_data <=> file_tab.conv-image_data;
|
||||||
in-out property file_tab-image_width <=> file_tab.conv-image_width;
|
in-out property file_tab-image_width <=> file_tab.conv-image_width;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Button, TabWidget, LineEdit, GroupBox } from "std-widgets.slint";
|
import { Button, TabWidget, LineEdit, GroupBox, ComboBox } from "std-widgets.slint";
|
||||||
|
|
||||||
export enum State {
|
export enum State {
|
||||||
Project,
|
Project,
|
||||||
|
@ -12,6 +12,7 @@ component ProjectWidget inherits Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
component ConvertImageWidget inherits Rectangle {
|
component ConvertImageWidget inherits Rectangle {
|
||||||
|
in-out property <[string]> encoding_options: [];
|
||||||
in-out property <string> image_path;
|
in-out property <string> image_path;
|
||||||
in-out property <string> image_name;
|
in-out property <string> image_name;
|
||||||
in-out property <image> image_data;
|
in-out property <image> image_data;
|
||||||
|
@ -88,6 +89,13 @@ component ConvertImageWidget inherits Rectangle {
|
||||||
text: "Height: " + root.image-height;
|
text: "Height: " + root.image-height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VerticalLayout {
|
||||||
|
alignment: center;
|
||||||
|
ComboBox {
|
||||||
|
model: root.encoding_options;
|
||||||
|
enabled: root.enable_view;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Rectangle {
|
Rectangle {
|
||||||
// Fake padding because the padding setting for the HorizontalLayout would not work
|
// Fake padding because the padding setting for the HorizontalLayout would not work
|
||||||
|
@ -188,6 +196,7 @@ component ConvertImageWidget inherits Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
export component FileTab inherits Rectangle {
|
export component FileTab inherits Rectangle {
|
||||||
|
in-out property <[string]> conv-encoding_options;
|
||||||
in-out property <string> conv-image_path;
|
in-out property <string> conv-image_path;
|
||||||
in-out property <string> conv-image_name;
|
in-out property <string> conv-image_name;
|
||||||
in-out property <image> conv-image_data;
|
in-out property <image> conv-image_data;
|
||||||
|
@ -233,7 +242,9 @@ export component FileTab inherits Rectangle {
|
||||||
alignment: start;
|
alignment: start;
|
||||||
if root.state == State.Project : ProjectWidget {
|
if root.state == State.Project : ProjectWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
if root.state == State.ConvertImage : ConvertImageWidget {
|
if root.state == State.ConvertImage : ConvertImageWidget {
|
||||||
|
encoding_options <=> root.conv-encoding_options;
|
||||||
image_path <=> root.conv-image_path;
|
image_path <=> root.conv-image_path;
|
||||||
image_data <=> root.conv-image_data;
|
image_data <=> root.conv-image_data;
|
||||||
image-width <=> root.conv-image_width;
|
image-width <=> root.conv-image_width;
|
||||||
|
|
Loading…
Reference in New Issue