jabyengine/src/Tools/tim_tool/ui/tab/file-tab.slint

283 lines
10 KiB
Plaintext

import { Button, TabWidget, LineEdit, GroupBox, ComboBox } from "std-widgets.slint";
export enum State {
Project,
ConvertImage,
}
component ProjectWidget inherits Rectangle {
Text {
text: "Projects not supported yet";
color: #FF0000;
font-size: 30pt;
font-weight: 800;
}
}
component ConvertImageWidget inherits Rectangle {
in-out property <[string]> encoding_options: [];
in-out property <string> image_path;
in-out property <string> image_name;
in-out property <image> image_data;
in-out property <int> image-width;
in-out property <int> image-height;
in-out property <image> palette_data;
in-out property <int> palette_width: 0;
in-out property <int> palette_height: 0;
in-out property <string> selected_encoding;
in-out property <bool> enable_view: false;
in-out property <bool> palette_visible: false;
callback browse_clicked();
callback add_clicked();
callback update_palette_size(int, int);
background: #D0D0D0;
VerticalLayout {
alignment: start;
GroupBox {
title: "Add image file";
VerticalLayout {
alignment: start;
padding: 4px;
Text {
text: "Select image file to convert to be used with TIM Tool";
}
HorizontalLayout {
alignment: start;
padding: 4px;
LineEdit {
width: 300pt;
text: image_path;
}
Button {
text: "Browse";
clicked => {browse_clicked();}
}
}
}
}
GroupBox {
title: "Loaded image and palette";
VerticalLayout {
alignment: start;
padding: 4px;
HorizontalLayout {
alignment: center;
VerticalLayout {
Rectangle {
width: 256px + 2*4px; // < Because of border
height: 256px + 2*4px; // < Because of border
background: #404040;
border-color: #808080;
border-width: 4px;
Image {
width: 256px;
height: 256px;
source: root.image_data;
image-fit: contain;
image-rendering: pixelated;
}
}
VerticalLayout {
alignment: center;
Text {
text: "Width: " + root.image-width;
}
}
VerticalLayout {
alignment: center;
Text {
text: "Height: " + root.image-height;
}
}
VerticalLayout {
alignment: center;
ComboBox {
model: root.encoding_options;
enabled: root.enable_view;
selected(current-value) => {
root.selected_encoding = current-value;
}
}
}
}
Rectangle {
// Fake padding because the padding setting for the HorizontalLayout would not work
width: 4px;
height: 1px;
}
VerticalLayout {
Rectangle {
width: 256px + 2*4px; // < Because of border
height: 256px + 2*4px; // < Because of border
background: #404040;
border-color: #808080;
border-width: 4px;
palette_image := Image {
width: 256px;
height: 256px;
source: root.palette_data;
visible: root.palette_visible;
image-fit: contain;
image-rendering: pixelated;
}
}
HorizontalLayout {
alignment: start;
VerticalLayout {
VerticalLayout {
alignment: center;
Text {
text: "Width: ";
}
}
VerticalLayout {
alignment: center;
Text {
text: "Height: ";
}
}
}
VerticalLayout {
palette_width_edit := LineEdit {
width: 40pt;
input-type: number;
enabled: root.palette_visible;
text: root.palette_width;
accepted(text) => {
update_palette_size(palette_width_edit.text.to-float(), palette_height_edit.text.to-float());
}
}
palette_height_edit := LineEdit {
width: 40pt;
input-type: number;
enabled: root.palette_visible;
text: root.palette_height;
accepted(text) => {
update_palette_size(palette_width_edit.text.to-float(), palette_height_edit.text.to-float());
}
}
}
}
}
}
HorizontalLayout {
alignment: start;
padding: 4px;
VerticalLayout {
alignment: center;
Text {
text: "Name: ";
}
}
LineEdit {
text: root.image_name;
}
}
HorizontalLayout {
alignment: start;
padding: 4px;
Button {
text: "Add Image";
enabled: root.enable_view;
clicked => {root.add_clicked();}
}
}
}
}
}
public function set_palette_image(image: image) {
palette_image.source = image;
palette_image.visible = true;
}
public function clear_palette_image() {
palette_image.visible = false;
}
}
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_name;
in-out property <image> conv-image_data;
in-out property <int> conv-image_width;
in-out property <int> conv-image_height;
in-out property <image> conv-palette_data;
in-out property <int> conv-palette_width;
in-out property <int> conv-palette_height;
in-out property <string> conv-selected_encoding;
in-out property <bool> conv-palette_enable;
in-out property <bool> conv-enable_view;
in-out property <State> state;
callback conv-image_update_palette_size(int, int);
callback conv-image_browse_clicked;
callback conv-image_add_clicked;
x: 0px;
y: 0px;
HorizontalLayout {
padding: 4px;
VerticalLayout {
padding: 4px;
width: 20%;
alignment: start;
Button {
text: "Projects";
clicked => {
root.state = State.Project;
}
}
Button {
text: "Add Image";
clicked => {
root.state = State.ConvertImage;
}
}
}
VerticalLayout {
padding: 4px;
alignment: start;
if root.state == State.Project : ProjectWidget {
}
if root.state == State.ConvertImage : ConvertImageWidget {
encoding_options <=> root.conv-encoding_options;
image_path <=> root.conv-image_path;
image_data <=> root.conv-image_data;
image-width <=> root.conv-image_width;
image-height <=> root.conv-image_height;
palette_data <=> root.conv-palette_data;
palette_width <=> root.conv-palette_width;
palette_height <=> root.conv-palette_height;
palette_visible <=> root.conv-palette_enable;
selected_encoding <=> root.conv-selected_encoding;
image_name <=> root.conv-image_name;
enable_view <=> root.conv-enable_view;
update_palette_size(width, height) => {
root.conv-image_update_palette_size(width, height);
}
browse_clicked => {
root.conv-image_browse_clicked();
}
add_clicked => {
root.conv-image_add_clicked();
}
}
}
}
}