mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +00:00
Refactor the whole structure, no more separation for C++ and Slint files
This commit is contained in:
parent
d6c781faa2
commit
893fcc11e3
35 changed files with 920 additions and 518 deletions
28
src/SeleniteSetup.cpp
Normal file
28
src/SeleniteSetup.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "SeleniteSetup.h"
|
||||
#include "selenite/palette.h"
|
||||
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color)
|
||||
{
|
||||
return slint::Color::from_rgb_uint8(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
void setSelenitePalette(const ui::Palette &uiPalette, const selenite::Palette &palette)
|
||||
{
|
||||
uiPalette.set_accent(seleniteColorToSlint(palette.primary));
|
||||
uiPalette.set_background(seleniteColorToSlint(palette.background));
|
||||
uiPalette.set_pane(seleniteColorToSlint(palette.pane));
|
||||
uiPalette.set_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_foreground_hint(seleniteColorToSlint(palette.foregroundHint));
|
||||
uiPalette.set_control_background(seleniteColorToSlint(palette.background3));
|
||||
uiPalette.set_control_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_card_background(seleniteColorToSlint(palette.background2));
|
||||
uiPalette.set_green(seleniteColorToSlint(palette.green));
|
||||
uiPalette.set_orange(seleniteColorToSlint(palette.orange));
|
||||
uiPalette.set_red(seleniteColorToSlint(palette.red));
|
||||
}
|
|
@ -6,26 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "slint_color.h"
|
||||
#include "ui.h"
|
||||
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color)
|
||||
{
|
||||
return slint::Color::from_rgb_uint8(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
void setSelenitePalette(const ui::Palette &uiPalette, const selenite::Palette &palette)
|
||||
{
|
||||
uiPalette.set_accent(seleniteColorToSlint(palette.primary));
|
||||
uiPalette.set_background(seleniteColorToSlint(palette.background));
|
||||
uiPalette.set_pane(seleniteColorToSlint(palette.pane));
|
||||
uiPalette.set_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_foreground_hint(seleniteColorToSlint(palette.foregroundHint));
|
||||
uiPalette.set_control_background(seleniteColorToSlint(palette.background3));
|
||||
uiPalette.set_control_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_card_background(seleniteColorToSlint(palette.background2));
|
||||
uiPalette.set_green(seleniteColorToSlint(palette.green));
|
||||
uiPalette.set_orange(seleniteColorToSlint(palette.orange));
|
||||
uiPalette.set_red(seleniteColorToSlint(palette.red));
|
||||
}
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color);
|
||||
void setSelenitePalette(const ui::Palette &uiPalette, const selenite::Palette &palette);
|
||||
|
|
112
src/components/Calendar.slint
Normal file
112
src/components/Calendar.slint
Normal file
|
@ -0,0 +1,112 @@
|
|||
import { ScrollView, Date, Time } from "std-widgets.slint";
|
||||
import { VCheckBox, VButton, VActionButton, Svg, VTag, VPopupIconMenu, VText, Palette } from "@selenite";
|
||||
import { Utils } from "../shared/Utils.slint";
|
||||
|
||||
export struct CalendarDayEvent {
|
||||
title: string,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export struct CalendarDay {
|
||||
events: [CalendarDayEvent],
|
||||
date: Date,
|
||||
header: string,
|
||||
}
|
||||
|
||||
export enum CalendarDateDisplayFormat {
|
||||
Relative,
|
||||
Normal
|
||||
}
|
||||
|
||||
export component Calendar inherits Rectangle {
|
||||
in property<[CalendarDay]> days;
|
||||
in property <CalendarDateDisplayFormat> format;
|
||||
private property <length> header-height: 64px;
|
||||
private property <length> available-day-space: self.height - header-height;
|
||||
private property <length> day-start-y: header-height;
|
||||
private property <length> hour-spacing: available-day-space / 24;
|
||||
background: Palette.pane;
|
||||
|
||||
HorizontalLayout {
|
||||
Rectangle {
|
||||
//background: red;
|
||||
width: 48px;
|
||||
VerticalLayout {
|
||||
y: 0;
|
||||
height: header-height;
|
||||
padding-right: 8px;
|
||||
VText {
|
||||
vertical-alignment: center;
|
||||
horizontal-alignment: right;
|
||||
text: "";
|
||||
}
|
||||
}
|
||||
|
||||
for index in 24: VerticalLayout {
|
||||
y: day-start-y + index * hour-spacing - (hour-spacing / 2);
|
||||
height: hour-spacing;
|
||||
padding-right: 8px;
|
||||
VText {
|
||||
vertical-alignment: center;
|
||||
horizontal-alignment: right;
|
||||
text: "\{index}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Rectangle {
|
||||
//background: green;
|
||||
HorizontalLayout {
|
||||
for day[day-index] in root.days: Rectangle {
|
||||
if day-index > 0 : Rectangle {
|
||||
x: 0;
|
||||
y: header-height - 32px;
|
||||
width: 1px;
|
||||
height: parent.height;
|
||||
background: Palette.card-background.transparentize(0.5);
|
||||
}
|
||||
VerticalLayout {
|
||||
y: 0;
|
||||
height: header-height;
|
||||
padding-right: 8px;
|
||||
VText {
|
||||
vertical-alignment: center;
|
||||
horizontal-alignment: center;
|
||||
text: day.header;
|
||||
}
|
||||
}
|
||||
for hour[hour-index] in 24 : Rectangle {
|
||||
background: Palette.card-background.transparentize(0.5);
|
||||
x: 0px;
|
||||
width: parent.width;
|
||||
y: day-start-y + hour-spacing * hour-index;
|
||||
height: 1px;
|
||||
}
|
||||
for event[event-index] in day.events : Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 4px;
|
||||
x: 8px;
|
||||
width: parent.width - 16px;
|
||||
y: day-start-y + hour-spacing * event.startsAt.hour;
|
||||
height: hour-spacing * (event.endsAt.hour - event.startsAt.hour) - 2px;
|
||||
clip: true;
|
||||
HorizontalLayout {
|
||||
Rectangle {
|
||||
width: 4px;
|
||||
background: Palette.accent;
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
VText {
|
||||
text: event.title;
|
||||
wrap: TextWrap.word-wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
src/components/CreateTaskOrEvent.slint
Normal file
123
src/components/CreateTaskOrEvent.slint
Normal file
|
@ -0,0 +1,123 @@
|
|||
import { AppWindowModels } from "../windows/AppWindow/Models.slint";
|
||||
import { Date, Time, Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VActionButton, VTag, VText, Svg, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export struct CreateTaskData {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date
|
||||
}
|
||||
|
||||
export struct CreateEventData {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export component CreateTaskOrEvent inherits Rectangle {
|
||||
|
||||
in property <[string]> sources;
|
||||
private property <int> task-or-event: 1;
|
||||
|
||||
callback create-task(CreateTaskData);
|
||||
callback create-event(CreateEventData);
|
||||
|
||||
function accepted() {
|
||||
if (task-or-event == 1) {
|
||||
root.create-task({
|
||||
sourceId: AppWindowModels.get-source-id-from-name(sourceInput.current-value),
|
||||
title: newTaskTitleInput.text,
|
||||
date: taskDateInput.date
|
||||
})
|
||||
} else {
|
||||
root.create-event({
|
||||
sourceId: AppWindowModels.get-source-id-from-name(sourceInput.current-value),
|
||||
title: newTaskTitleInput.text,
|
||||
date: taskDateInput.date,
|
||||
startsAt: eventStartTimeInput.time,
|
||||
endsAt: eventEndTimeInput.time
|
||||
})
|
||||
}
|
||||
newTaskTitleInput.edit-text("");
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
border-color: newTaskTitleInput.text != "" ? Palette.card-background : transparent;
|
||||
border-width: newTaskTitleInput.text != "" ? 4px : 0px;
|
||||
border-radius: newTaskTitleInput.text != "" ? 8px : 0px;
|
||||
animate border-color, border-width {
|
||||
duration: 250ms;
|
||||
}
|
||||
VerticalLayout {
|
||||
spacing: 8px;
|
||||
padding: newTaskTitleInput.text != "" ? 16px : 0px;
|
||||
animate padding {
|
||||
duration: 250ms;
|
||||
}
|
||||
newTaskTitleInput := VTextInput {
|
||||
placeholder: "Add new Task / Event";
|
||||
started-writting() => {
|
||||
sourceInput.current-index = AppWindowModels.default-source-index;
|
||||
}
|
||||
accepted => { accepted() }
|
||||
}
|
||||
Rectangle {
|
||||
min-height: 0px;
|
||||
max-height: newTaskTitleInput.text != "" ? 512px : 0px;
|
||||
opacity: newTaskTitleInput.text != "" ? 1 : 0;
|
||||
clip: true;
|
||||
animate max-height, opacity {
|
||||
duration: 250ms;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
VerticalLayout {
|
||||
alignment: end;
|
||||
VButton {
|
||||
text: task-or-event == 1 ? "Task" : "Event";
|
||||
clicked => { task-or-event = task-or-event == 1 ? 0 : 1 }
|
||||
}
|
||||
}
|
||||
VText { text: "for"; vertical-alignment: bottom;}
|
||||
VerticalLayout {
|
||||
alignment: end;
|
||||
sourceInput := ComboBox {
|
||||
model: root.sources;
|
||||
|
||||
}
|
||||
}
|
||||
VText { text: "on"; vertical-alignment: bottom;}
|
||||
taskDateInput := VDatePicker {
|
||||
enabled: true;
|
||||
}
|
||||
Rectangle {
|
||||
min-width: 0;
|
||||
max-width: task-or-event == 0 ? 9999px : 0px;
|
||||
opacity: task-or-event == 0 ? 1 : 0;
|
||||
clip: true;
|
||||
animate max-width, opacity {
|
||||
duration: 250ms;
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 4px;
|
||||
VText { text: "between"; vertical-alignment: bottom; }
|
||||
eventStartTimeInput := VTimePicker { }
|
||||
VText { text: "and"; vertical-alignment: bottom; }
|
||||
eventEndTimeInput := VTimePicker { }
|
||||
}
|
||||
}
|
||||
VButton {
|
||||
text: "Create";
|
||||
icon-svg: Svg.correct;
|
||||
icon-colorize: greenyellow;
|
||||
clicked => { accepted() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
127
src/components/EventGroup.slint
Normal file
127
src/components/EventGroup.slint
Normal file
|
@ -0,0 +1,127 @@
|
|||
import { Event } from "../windows/AppWindow/Models.slint";
|
||||
import { ScrollView } from "std-widgets.slint";
|
||||
import { VCheckBox, VTextInput, VButton, VActionButton, Svg, VTag, VPopupIconMenu, VText, Palette } from "@selenite";
|
||||
import { TaskLine } from "./TaskLine.slint";
|
||||
import { Utils } from "../shared/Utils.slint";
|
||||
|
||||
export struct EventGroupAddTask {
|
||||
title: string
|
||||
}
|
||||
|
||||
export component EventGroup {
|
||||
in property<Event> event;
|
||||
private property <bool> show-add-task: false;
|
||||
private property <bool> edit-name: false;
|
||||
|
||||
callback add-task(EventGroupAddTask);
|
||||
callback edit-task(int, EventGroupAddTask);
|
||||
callback delete-task(int);
|
||||
callback delete();
|
||||
callback edit(EventGroupAddTask);
|
||||
callback toggle-check-task(int);
|
||||
|
||||
eventPopup := VPopupIconMenu {
|
||||
VActionButton {
|
||||
icon-svg: Svg.plus;
|
||||
icon-colorize: Colors.greenyellow;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
root.show-add-task = true;
|
||||
}
|
||||
}
|
||||
VActionButton {
|
||||
icon-svg: Svg.pen;
|
||||
icon-colorize: Colors.grey;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => { edit-name = true; }
|
||||
}
|
||||
|
||||
VActionButton {
|
||||
icon-svg: Svg.trash;
|
||||
icon-colorize: Colors.pink;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => { root.delete() }
|
||||
}
|
||||
}
|
||||
|
||||
ta := TouchArea {
|
||||
pointer-event(e) => {
|
||||
if (e.button == PointerEventButton.right && e.kind == PointerEventKind.up) {
|
||||
eventPopup.show(ta.mouse-x, ta.mouse-y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
VerticalLayout {
|
||||
spacing: 4px;
|
||||
VText {
|
||||
text: Utils.time-to-string(event.startsAt);
|
||||
horizontal-alignment: center;
|
||||
color: Palette.accent;
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 2px;
|
||||
background: Palette.accent;
|
||||
}
|
||||
}
|
||||
VText {
|
||||
text: Utils.time-to-string(event.endsAt);
|
||||
color: Palette.accent;
|
||||
font-size: 0.9rem;
|
||||
horizontal-alignment: center;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
padding: 16px;
|
||||
padding-top: 32px;
|
||||
padding-bottom: 32px;
|
||||
padding-right: 0px;
|
||||
if !edit-name : VText {
|
||||
text: event.title;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
if edit-name : title := VTextInput {
|
||||
text: event.title;
|
||||
accepted => {
|
||||
root.edit({
|
||||
title: title.text
|
||||
});
|
||||
root.edit-name = false;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in event.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
delete => {
|
||||
root.delete-task(task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
root.toggle-check-task(task.id)
|
||||
}
|
||||
edited(data) => {
|
||||
root.edit-task(task.id, {
|
||||
title: data.title
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if show-add-task : taskInput := VTextInput {
|
||||
accepted => {
|
||||
root.add-task({
|
||||
title: taskInput.text
|
||||
});
|
||||
root.show-add-task = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
src/components/TaskEdit.slint
Normal file
64
src/components/TaskEdit.slint
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { Button, VerticalBox, CheckBox, Date, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
|
||||
export struct TaskEditData {
|
||||
title: string,
|
||||
date: Date,
|
||||
}
|
||||
|
||||
export component TaskEdit inherits VerticalLayout {
|
||||
out property <bool> should-show;
|
||||
in property <bool> allow-edit-date;
|
||||
in-out property <TaskEditData> task;
|
||||
|
||||
callback accepted(TaskEditData);
|
||||
|
||||
private property <Date> newDate: task.date;
|
||||
|
||||
public function show(task: TaskEditData) {
|
||||
root.task = task;
|
||||
should-show = true;
|
||||
}
|
||||
public function close() {
|
||||
should-show = false;
|
||||
}
|
||||
|
||||
// Render
|
||||
|
||||
if !should-show : Rectangle {}
|
||||
|
||||
if should-show : Rectangle {
|
||||
function modify() {
|
||||
root.accepted({
|
||||
title: newTaskTitleInput.text,
|
||||
date: newDate
|
||||
});
|
||||
}
|
||||
background: Palette.background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
|
||||
newTaskTitleInput := VTextInput {
|
||||
text: root.task.title;
|
||||
accepted => { modify() }
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
if root.allow-edit-date : taskDateInput := VDatePicker {
|
||||
date: task.date;
|
||||
enabled: true;
|
||||
edited(date) => { newDate = date; }
|
||||
}
|
||||
VButton {
|
||||
text: "Modify";
|
||||
icon-svg: Svg.correct;
|
||||
icon-colorize: greenyellow;
|
||||
clicked => { modify() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
94
src/components/TaskLine.slint
Normal file
94
src/components/TaskLine.slint
Normal file
|
@ -0,0 +1,94 @@
|
|||
import { ToggleButton } from "@selenite";
|
||||
import { VPopupIconMenu, VTag, VButton, VActionButton, VCheckBox, Svg, Palette } from "@selenite";
|
||||
import { TaskEdit } from "./TaskEdit.slint";
|
||||
import { Date } from "std-widgets.slint";
|
||||
|
||||
export struct TaskLineEditData {
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date,
|
||||
checked: bool
|
||||
}
|
||||
|
||||
export component TaskLine inherits VerticalLayout {
|
||||
in property<string> title;
|
||||
in property<bool> scheduled;
|
||||
in property<Date> date;
|
||||
in property<bool> checked;
|
||||
in property<bool> allow-edit-date;
|
||||
|
||||
callback delete();
|
||||
callback edit();
|
||||
callback toggle-check();
|
||||
callback edited(TaskLineEditData);
|
||||
|
||||
private property<length> popup-x: 200px;
|
||||
private property<length> popup-y: 200px;
|
||||
|
||||
taskEdit := TaskEdit {
|
||||
allow-edit-date: root.allow-edit-date;
|
||||
accepted(task) => {
|
||||
root.edited({
|
||||
title: task.title,
|
||||
scheduled: task.date.year != 0,
|
||||
date: task.date
|
||||
});
|
||||
taskEdit.close();
|
||||
}
|
||||
}
|
||||
|
||||
if !taskEdit.should-show : Rectangle {
|
||||
popup := VPopupIconMenu {
|
||||
VActionButton {
|
||||
icon-svg: Svg.pen;
|
||||
icon-colorize: Colors.grey;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
taskEdit.show({
|
||||
title: title,
|
||||
date: date
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
VActionButton {
|
||||
icon-svg: Svg.trash;
|
||||
icon-colorize: Colors.pink;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
root.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ta := TouchArea {
|
||||
clicked => {
|
||||
checkbox.checked = !checkbox.checked;
|
||||
root.toggle-check();
|
||||
}
|
||||
pointer-event(e) => {
|
||||
if (e.button == PointerEventButton.right && e.kind == PointerEventKind.up) {
|
||||
popup.show(ta.mouse-x, ta.mouse-y);
|
||||
}
|
||||
}
|
||||
z: 10;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
alignment: space-between;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
checkbox := VCheckBox {
|
||||
text: root.title;
|
||||
checked: root.checked;
|
||||
toggled => {
|
||||
root.toggle-check()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,10 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "AppWindowBackend.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "ui.h"
|
||||
#include "windows/AppWindow/AppWindow.h"
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
|
@ -15,7 +16,7 @@ int main(int argc, char **argv)
|
|||
evalyte::createRequiredDirectories("mirai");
|
||||
const auto configFilePath = evalyte::configDirectoryPath("mirai") + "/config.json";
|
||||
mirai::Mirai mirai{configFilePath};
|
||||
AppWindowBackend appWindow{&mirai};
|
||||
AppWindow appWindow{&mirai};
|
||||
appWindow.run();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,18 @@
|
|||
#include <format>
|
||||
#include <string>
|
||||
|
||||
void bindSlintUtils(const ui::Utils &utils)
|
||||
{
|
||||
utils.on_format_date([&](const ui::Date &date) {
|
||||
std::chrono::year_month_day chronoDate{
|
||||
std::chrono::year(date.year),
|
||||
std::chrono::month(date.month),
|
||||
std::chrono::day(date.day),
|
||||
};
|
||||
return std::format("{:%B %d}", chronoDate);
|
||||
});
|
||||
}
|
||||
|
||||
std::string formatZeroPadding(const int number)
|
||||
{
|
||||
if (number < 10) {
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.h"
|
||||
#include "mirai-core/DateTime.h"
|
||||
#include "ui.h"
|
||||
#include <string>
|
||||
|
||||
void bindSlintUtils(const ui::Utils &utils);
|
||||
|
||||
std::string formatZeroPadding(const int number);
|
||||
std::string formatDateRelative(const ui::Date &date);
|
||||
std::string capitalize(std::string str);
|
19
src/shared/Utils.slint
Normal file
19
src/shared/Utils.slint
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
|
||||
export global Utils {
|
||||
pure function format-zero-padding(number: int) -> string {
|
||||
if (number < 10) {
|
||||
return "0\{number}";
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
public pure function time-to-string(time: Time) -> string {
|
||||
if (time.minute == 0) {
|
||||
return "\{time.hour}";
|
||||
}
|
||||
return "\{time.hour}:\{format-zero-padding(time.minute)}";
|
||||
}
|
||||
|
||||
pure callback format-date(Date) -> string;
|
||||
}
|
10
src/ui.slint
Normal file
10
src/ui.slint
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { AppWindowModels } from "windows/AppWindow/Models.slint";
|
||||
import { AppWindowActions } from "windows/AppWindow/Actions.slint";
|
||||
import { AppWindow } from "windows/AppWindow/AppWindow.slint";
|
||||
import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint";
|
||||
import { AddSourceWindow } from "windows/AddSourceWindow//AddSourceWindow.slint";
|
||||
import { EditSourceWindow } from "windows/EditSourceWindow/EditSourceWindow.slint";
|
||||
import { Utils } from "shared/Utils.slint";
|
||||
import { Palette } from "@selenite";
|
||||
|
||||
export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditSourceWindow }
|
59
src/windows/AddSourceWindow/AddSourceWindow.cpp
Normal file
59
src/windows/AddSourceWindow/AddSourceWindow.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "AddSourceWindow.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <string>
|
||||
|
||||
AddSourceWindow::AddSourceWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
window_->set_default_source_path(slint::SharedString(evalyte::dataDirectoryPath("mirai") + "/")
|
||||
);
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
||||
if (palette.has_value()) {
|
||||
setSelenitePalette(window_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
setupCallbacks();
|
||||
}
|
||||
|
||||
void AddSourceWindow::setupCallbacks()
|
||||
{
|
||||
window_->on_add_source([&](ui::AddSourceParam params) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(std::string(params.path));
|
||||
miraiInstance_->addSource(
|
||||
std::string(params.name), std::string(params.type), std::move(file)
|
||||
);
|
||||
window_->hide();
|
||||
});
|
||||
}
|
||||
|
||||
void AddSourceWindow::open()
|
||||
{
|
||||
window_->show();
|
||||
}
|
||||
|
||||
void AddSourceWindow::close()
|
||||
{
|
||||
window_->hide();
|
||||
}
|
28
src/windows/AddSourceWindow/AddSourceWindow.h
Normal file
28
src/windows/AddSourceWindow/AddSourceWindow.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class AddSourceWindow
|
||||
{
|
||||
|
||||
public:
|
||||
AddSourceWindow(mirai::Mirai *mirai);
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
slint::ComponentHandle<ui::AddSourceWindow> window_ = ui::AddSourceWindow::create();
|
||||
mirai::Mirai *miraiInstance_;
|
||||
};
|
46
src/windows/AddSourceWindow/AddSourceWindow.slint
Normal file
46
src/windows/AddSourceWindow/AddSourceWindow.slint
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { VButton, VText, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export struct AddSourceParam {
|
||||
name: string,
|
||||
type: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
export component AddSourceWindow inherits Window {
|
||||
|
||||
title: "Mirai - Add source";
|
||||
min-height: 100px;
|
||||
max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
|
||||
min-width: 400px;
|
||||
default-font-size: 16px;
|
||||
background: Palette.background;
|
||||
|
||||
in-out property <string> default-source-path;
|
||||
callback add-source(AddSourceParam);
|
||||
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
nameInput := VTextInput {
|
||||
label: "Name";
|
||||
text: "todo";
|
||||
}
|
||||
pathInput := VTextInput {
|
||||
label: "Path";
|
||||
text: root.default-source-path + nameInput.text + ".md";
|
||||
}
|
||||
VButton {
|
||||
text: "Create";
|
||||
clicked => {
|
||||
root.add-source({
|
||||
name: nameInput.text,
|
||||
type: "FileSystemMarkdown",
|
||||
path: pathInput.text
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { Palette } // Export to make it visible to the C++ backend
|
61
src/windows/AppWindow/Actions.slint
Normal file
61
src/windows/AppWindow/Actions.slint
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
import { CalendarDay } from "../../components/Calendar.slint";
|
||||
|
||||
export struct NewTaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date
|
||||
}
|
||||
|
||||
export struct SaveTaskData {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date,
|
||||
}
|
||||
|
||||
export struct NewEventParams {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export struct SaveEventParams {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
struct OpenNewTaskFormParams {
|
||||
eventSourceId: int,
|
||||
eventId: int,
|
||||
}
|
||||
|
||||
export global AppWindowActions {
|
||||
callback task-clicked(int, int);
|
||||
callback source-clicked(int);
|
||||
callback open-settings-window();
|
||||
callback open-add-source-window();
|
||||
callback open-edit-source-window(int);
|
||||
|
||||
callback open-new-task-form(OpenNewTaskFormParams);
|
||||
callback open-edit-task-form(int, int);
|
||||
callback open-new-event-form();
|
||||
callback open-edit-event-form(int, int);
|
||||
callback toggle-show-completed-tasks();
|
||||
callback delete-task-clicked(int, int);
|
||||
callback delete-event-clicked(int, int);
|
||||
|
||||
callback create-task(NewTaskData);
|
||||
callback save-task(SaveTaskData);
|
||||
callback create-event(NewEventParams);
|
||||
callback save-event(SaveEventParams);
|
||||
}
|
|
@ -4,18 +4,17 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "AppWindowBackend.h"
|
||||
#include "AppWindow.h"
|
||||
#include "SeleniteSetup.h"
|
||||
#include "Utils.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "../../shared/Utils.h"
|
||||
#include "mirai-core/DateTime.h"
|
||||
#include "mirai-core/Day.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <charconv>
|
||||
|
@ -23,7 +22,6 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
@ -34,14 +32,14 @@
|
|||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
AppWindowBackend::AppWindowBackend(mirai::Mirai *miraiInstance)
|
||||
: miraiInstance_(miraiInstance), view_(miraiInstance)
|
||||
AppWindow::AppWindow(mirai::Mirai *miraiInstance)
|
||||
: miraiInstance_(miraiInstance), addSourceWindow_(miraiInstance),
|
||||
editSourceWindow_(miraiInstance), settingsWindow_(miraiInstance), view_(miraiInstance)
|
||||
{
|
||||
sources_ = std::make_shared<slint::VectorModel<ui::Source>>();
|
||||
days_ = std::make_shared<slint::VectorModel<ui::Day>>();
|
||||
calendar_ = std::make_shared<slint::VectorModel<ui::CalendarDay>>();
|
||||
unscheduledTasks_ = std::make_shared<slint::VectorModel<ui::TaskData>>();
|
||||
tags_ = std::make_shared<slint::VectorModel<slint::SharedString>>();
|
||||
auto sourcesNames = std::make_shared<slint::MapModel<ui::Source, slint::SharedString>>(
|
||||
sources_,
|
||||
[&](const ui::Source &a) {
|
||||
|
@ -49,29 +47,19 @@ AppWindowBackend::AppWindowBackend(mirai::Mirai *miraiInstance)
|
|||
}
|
||||
);
|
||||
|
||||
addSourceWindow_->set_default_source_path(
|
||||
slint::SharedString(evalyte::dataDirectoryPath("mirai") + "/")
|
||||
);
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
if (palette.has_value()) {
|
||||
std::println(std::cerr, "Warning, no {} found", palettePath);
|
||||
setSelenitePalette(mainWindow_->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette(settingsWindow_->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette(addSourceWindow_->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette(editSourceWindow_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_sources(sourcesNames);
|
||||
settingsWindow_->global<ui::Backend>().set_sources(sourcesNames);
|
||||
bindSlintUtils(mainWindow_->global<ui::Utils>());
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_sources_selected(sources_);
|
||||
settingsWindow_->global<ui::Backend>().set_sources_selected(sources_);
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_tags(tags_);
|
||||
mainWindow_->global<ui::Backend>().set_days(days_);
|
||||
mainWindow_->global<ui::Backend>().set_calendar(calendar_);
|
||||
models().set_sources(sourcesNames);
|
||||
models().set_sources_selected(sources_);
|
||||
models().set_days(days_);
|
||||
models().set_calendar(calendar_);
|
||||
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
|
@ -103,64 +91,30 @@ std::optional<ui::Date> stringToDate(const std::string &dateStr)
|
|||
return ui::Date{.year = year, .month = month, .day = day};
|
||||
}
|
||||
|
||||
void AppWindowBackend::setupUtilsCallbacks()
|
||||
void AppWindow::setupCallbacks()
|
||||
{
|
||||
mainWindow_->global<ui::Backend>().on_format_date([&](const ui::Date &date) {
|
||||
std::chrono::year_month_day chronoDate{
|
||||
std::chrono::year(date.year),
|
||||
std::chrono::month(date.month),
|
||||
std::chrono::day(date.day),
|
||||
};
|
||||
return std::format("{:%B %d}", chronoDate);
|
||||
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
||||
refreshModels();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_format_date_relative([&](const ui::Date &date) {
|
||||
return formatDateRelative(date);
|
||||
miraiInstance_->onSourceEdited([&](mirai::Source *source) {
|
||||
refreshModels();
|
||||
});
|
||||
}
|
||||
|
||||
void AppWindowBackend::setupCallbacks()
|
||||
{
|
||||
mainWindow_->global<ui::Backend>().on_settings_clicked([&]() {
|
||||
settingsWindow_->show();
|
||||
miraiInstance_->onSourceDeleted([&](int id) {
|
||||
refreshModels();
|
||||
});
|
||||
mainWindow_->global<ui::Backend>().on_add_source_clicked([&]() {
|
||||
addSourceWindow_->show();
|
||||
actions().on_open_settings_window([&]() {
|
||||
settingsWindow_.open();
|
||||
});
|
||||
mainWindow_->global<ui::Backend>().on_edit_source_clicked([&](int sourceId) {
|
||||
actions().on_open_add_source_window([&]() {
|
||||
addSourceWindow_.open();
|
||||
});
|
||||
actions().on_open_edit_source_window([&](int sourceId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto markdownSource = dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||
editSourceWindow_->set_id(source->id);
|
||||
editSourceWindow_->set_name(slint::SharedString(source->name()));
|
||||
editSourceWindow_->set_path(slint::SharedString(markdownSource->path()));
|
||||
editSourceWindow_->show();
|
||||
editSourceWindow_.open(source);
|
||||
});
|
||||
addSourceWindow_->global<ui::Backend>().on_add_source([&](ui::AddSourceParam params) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(std::string(params.path));
|
||||
miraiInstance_->addSource(
|
||||
std::string(params.name), std::string(params.type), std::move(file)
|
||||
);
|
||||
addSourceWindow_->hide();
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
editSourceWindow_->global<ui::Backend>().on_modify_source([&](ui::ModifySourceParam params) {
|
||||
miraiInstance_->editSource(params.id, std::string(params.name), std::string(params.path));
|
||||
editSourceWindow_->hide();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
editSourceWindow_->global<ui::Backend>().on_delete_source([&](int sourceId) {
|
||||
miraiInstance_->deleteSource(sourceId);
|
||||
editSourceWindow_->hide();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
mainWindow_->global<ui::Backend>().on_task_clicked([&](int sourceId, int taskId) {
|
||||
|
||||
actions().on_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
|
@ -174,7 +128,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_source_clicked([&](int index) {
|
||||
actions().on_source_clicked([&](int index) {
|
||||
// index with value -1 is equal to no selection, aka "All"
|
||||
if (index == -1) {
|
||||
view_.setAllSources();
|
||||
|
@ -183,13 +137,13 @@ void AppWindowBackend::setupCallbacks()
|
|||
const mirai::Source *source = miraiInstance_->getSourceById(index);
|
||||
view_.addSource(*source);
|
||||
}
|
||||
mainWindow_->global<ui::Backend>().set_default_source_index(index == -1 ? 0 : index);
|
||||
models().set_default_source_index(index == -1 ? 0 : index);
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||
actions().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
|
@ -200,13 +154,13 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_toggle_show_completed_tasks([&] {
|
||||
actions().on_toggle_show_completed_tasks([&] {
|
||||
view_.hideCompletedTasks(!view_.shouldHideCompletedTasks());
|
||||
view_.update();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_save_task([&](ui::SaveTaskData newTaskData) {
|
||||
actions().on_save_task([&](ui::SaveTaskData newTaskData) {
|
||||
auto source = miraiInstance_->getSourceById(newTaskData.sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(newTaskData.id);
|
||||
|
@ -228,7 +182,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_create_task([&](ui::NewTaskData newTaskData) {
|
||||
actions().on_create_task([&](ui::NewTaskData newTaskData) {
|
||||
std::optional<mirai::Date> date = std::nullopt;
|
||||
if (newTaskData.date.year != 0) {
|
||||
date = SlintDateToMiraiDate(newTaskData.date);
|
||||
|
@ -251,7 +205,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_delete_event_clicked([&](int sourceId, int eventId) {
|
||||
actions().on_delete_event_clicked([&](int sourceId, int eventId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto event = source->getEventById(eventId);
|
||||
|
@ -262,7 +216,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_create_event([&](ui::NewEventParams newEventParams) {
|
||||
actions().on_create_event([&](ui::NewEventParams newEventParams) {
|
||||
const ui::Date &date = newEventParams.date;
|
||||
const std::string dateStr = SlintDateToStdString(date);
|
||||
auto source = miraiInstance_->getSourceById(newEventParams.sourceId);
|
||||
|
@ -278,7 +232,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_save_event([&](ui::SaveEventParams newEventParams) {
|
||||
actions().on_save_event([&](ui::SaveEventParams newEventParams) {
|
||||
const ui::Date &date = newEventParams.date;
|
||||
const std::string dateStr = SlintDateToStdString(date);
|
||||
auto source = miraiInstance_->getSourceById(newEventParams.sourceId);
|
||||
|
@ -295,7 +249,6 @@ void AppWindowBackend::setupCallbacks()
|
|||
view_.update();
|
||||
reloadTasks();
|
||||
});
|
||||
setupUtilsCallbacks();
|
||||
}
|
||||
|
||||
std::shared_ptr<slint::VectorModel<slint::SharedString>>
|
||||
|
@ -308,7 +261,7 @@ stdToSlintStringVector(const std::vector<std::string> &stdVector)
|
|||
return slintVector;
|
||||
}
|
||||
|
||||
void AppWindowBackend::reloadTasks()
|
||||
void AppWindow::reloadTasks()
|
||||
{
|
||||
days_->clear();
|
||||
if (miraiInstance_->getSources().size() == 0) {
|
||||
|
@ -374,7 +327,7 @@ void AppWindowBackend::reloadTasks()
|
|||
}
|
||||
}
|
||||
days_ = slintDays;
|
||||
mainWindow_->global<ui::Backend>().set_days(days_);
|
||||
models().set_days(days_);
|
||||
|
||||
auto unscheduledTasksView = view_.getUnscheduledTasks();
|
||||
unscheduledTasks_->clear();
|
||||
|
@ -388,7 +341,7 @@ void AppWindowBackend::reloadTasks()
|
|||
.checked = task.checked(),
|
||||
});
|
||||
}
|
||||
mainWindow_->global<ui::Backend>().set_unscheduled_tasks(unscheduledTasks_);
|
||||
models().set_unscheduled_tasks(unscheduledTasks_);
|
||||
|
||||
calendar_->clear();
|
||||
for (int dayIndex = 0; dayIndex < 7; ++dayIndex) {
|
||||
|
@ -427,7 +380,7 @@ void AppWindowBackend::reloadTasks()
|
|||
}
|
||||
}
|
||||
|
||||
void AppWindowBackend::reloadSources()
|
||||
void AppWindow::reloadSources()
|
||||
{
|
||||
sources_->clear();
|
||||
bool noSourceSelected = miraiInstance_->getSources().size() == view_.activeSourceCount();
|
||||
|
@ -442,10 +395,28 @@ void AppWindowBackend::reloadSources()
|
|||
.path = slint::SharedString(sourceProvider->path())}
|
||||
);
|
||||
}
|
||||
mainWindow_->global<ui::Backend>().set_no_source_selected(noSourceSelected);
|
||||
models().set_no_source_selected(noSourceSelected);
|
||||
}
|
||||
|
||||
void AppWindowBackend::run()
|
||||
void AppWindow::refreshModels()
|
||||
{
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
}
|
||||
|
||||
void AppWindow::run()
|
||||
{
|
||||
mainWindow_->run();
|
||||
}
|
||||
|
||||
const ui::AppWindowModels &AppWindow::models()
|
||||
{
|
||||
return mainWindow_->global<ui::AppWindowModels>();
|
||||
}
|
||||
|
||||
const ui::AppWindowActions &AppWindow::actions()
|
||||
{
|
||||
return mainWindow_->global<ui::AppWindowActions>();
|
||||
}
|
|
@ -6,36 +6,40 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.h"
|
||||
#include "../AddSourceWindow/AddSourceWindow.h"
|
||||
#include "../EditSourceWindow/EditSourceWindow.h"
|
||||
#include "../SettingsWindow/SettingsWindow.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/View.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class AppWindowBackend
|
||||
class AppWindow
|
||||
{
|
||||
|
||||
public:
|
||||
AppWindowBackend(mirai::Mirai *mirai);
|
||||
AppWindow(mirai::Mirai *mirai);
|
||||
|
||||
void run();
|
||||
|
||||
void reloadSources();
|
||||
void reloadTasks();
|
||||
void refreshModels();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
void setupUtilsCallbacks();
|
||||
const ui::AppWindowModels &models();
|
||||
const ui::AppWindowActions &actions();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
std::shared_ptr<slint::VectorModel<slint::SharedString>> tags_;
|
||||
std::shared_ptr<slint::VectorModel<ui::Day>> days_;
|
||||
std::shared_ptr<slint::VectorModel<ui::CalendarDay>> calendar_;
|
||||
std::shared_ptr<slint::VectorModel<ui::TaskData>> unscheduledTasks_;
|
||||
|
||||
slint::ComponentHandle<ui::AppWindow> mainWindow_ = ui::AppWindow::create();
|
||||
slint::ComponentHandle<ui::SettingsWindow> settingsWindow_ = ui::SettingsWindow::create();
|
||||
slint::ComponentHandle<ui::AddSourceWindow> addSourceWindow_ = ui::AddSourceWindow::create();
|
||||
slint::ComponentHandle<ui::EditSourceWindow> editSourceWindow_ = ui::EditSourceWindow::create();
|
||||
SettingsWindow settingsWindow_;
|
||||
AddSourceWindow addSourceWindow_;
|
||||
EditSourceWindow editSourceWindow_;
|
||||
|
||||
mirai::Mirai *miraiInstance_;
|
||||
mirai::View view_;
|
26
src/windows/AppWindow/AppWindow.slint
Normal file
26
src/windows/AppWindow/AppWindow.slint
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { AppWindowModels } from "Models.slint";
|
||||
import { Button, VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "views/SideBar.slint";
|
||||
import { MainView } from "views/TasksView.slint";
|
||||
import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint";
|
||||
import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint";
|
||||
import { EditSourceWindow } from "../EditSourceWindow/EditSourceWindow.slint";
|
||||
import { Palette } from "@selenite";
|
||||
|
||||
export component AppWindow inherits Window {
|
||||
|
||||
title: "Mirai";
|
||||
min-height: 100px;
|
||||
max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
|
||||
default-font-size: 16px;
|
||||
|
||||
HorizontalLayout {
|
||||
SideBar {}
|
||||
MainView {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AppWindowModels, Palette, SettingsWindow, AddSourceWindow, EditSourceWindow } // Export to make it visible to the C++ backend
|
50
src/windows/AppWindow/Models.slint
Normal file
50
src/windows/AppWindow/Models.slint
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
import { CalendarDay } from "../../components/Calendar.slint";
|
||||
|
||||
export struct Source {
|
||||
id: int,
|
||||
name: string,
|
||||
selected: bool,
|
||||
path: string
|
||||
}
|
||||
|
||||
export struct TaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
checked: bool,
|
||||
}
|
||||
|
||||
export struct Event {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
startsAt: Time,
|
||||
endsAt: Time,
|
||||
tasks: [TaskData],
|
||||
}
|
||||
|
||||
export struct Day {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
date: Date,
|
||||
events: [Event],
|
||||
tasks: [TaskData],
|
||||
isLate: bool,
|
||||
isToday: bool,
|
||||
relativeDaysDiff: int
|
||||
}
|
||||
|
||||
export global AppWindowModels {
|
||||
in-out property<[Source]> sources-selected;
|
||||
in-out property<int> default-source-index;
|
||||
in-out property<[string]> sources;
|
||||
in-out property<bool> no-source-selected;
|
||||
in-out property<[Day]> days;
|
||||
in-out property<[CalendarDay]> calendar;
|
||||
in-out property<[TaskData]> unscheduled-tasks;
|
||||
|
||||
callback get-source-id-from-name(string) -> int;
|
||||
}
|
65
src/windows/AppWindow/views/SideBar.slint
Normal file
65
src/windows/AppWindow/views/SideBar.slint
Normal file
|
@ -0,0 +1,65 @@
|
|||
import { AppWindowModels, TaskData } from "../Models.slint";
|
||||
import { AppWindowActions } from "../Actions.slint";
|
||||
import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite";
|
||||
|
||||
export component SideBar inherits Rectangle {
|
||||
background: Palette.pane;
|
||||
|
||||
VerticalLayout {
|
||||
height: parent.height;
|
||||
padding: 16px;
|
||||
spacing: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: space-between;
|
||||
spacing: 64px;
|
||||
VText {
|
||||
text: "Sources";
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
VActionButton {
|
||||
icon-svg: Svg.plus;
|
||||
icon-colorize: Palette.green;
|
||||
background: transparent;
|
||||
clicked => { AppWindowActions.open-add-source-window() }
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: space-between;
|
||||
vertical-stretch: 1;
|
||||
VerticalLayout {
|
||||
vertical-stretch: 1;
|
||||
spacing: 4px;
|
||||
ToggleButton {
|
||||
text: "All";
|
||||
text-alignment: left;
|
||||
active: AppWindowModels.no-source-selected;
|
||||
clicked => { AppWindowActions.source-clicked(-1) }
|
||||
|
||||
|
||||
}
|
||||
for item[index] in AppWindowModels.sources-selected: ToggleButton {
|
||||
text: item.name;
|
||||
text-alignment: left;
|
||||
active: item.selected;
|
||||
clicked => { AppWindowActions.source-clicked(item.id) }
|
||||
VActionButton {
|
||||
visible: parent.active;
|
||||
icon-svg: Svg.cog;
|
||||
background: transparent;
|
||||
clicked => { AppWindowActions.open-edit-source-window(item.id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
spacing: 4px;
|
||||
/*VButton {
|
||||
icon-svg: Svg.cog;
|
||||
text: "Settings";
|
||||
background: transparent;
|
||||
clicked => { AppWindowModels.open-settings-window() }
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
221
src/windows/AppWindow/views/TasksView.slint
Normal file
221
src/windows/AppWindow/views/TasksView.slint
Normal file
|
@ -0,0 +1,221 @@
|
|||
import { AppWindowModels, TaskData } from "../Models.slint";
|
||||
import { AppWindowActions, NewTaskData, SaveTaskData } from "../Actions.slint";
|
||||
import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { TaskLine } from "../../../components/TaskLine.slint";
|
||||
import { EventGroup } from "../../../components/EventGroup.slint";
|
||||
import { Calendar } from "../../../components/Calendar.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
import { CreateTaskOrEvent } from "../../../components/CreateTaskOrEvent.slint";
|
||||
import { Utils } from "../../../shared/Utils.slint";
|
||||
|
||||
export component MainView inherits Rectangle {
|
||||
|
||||
background: Palette.background;
|
||||
private property<string> icon-visible: Svg.visible;
|
||||
private property<string> icon-not-visible: Svg.not-visible;
|
||||
private property<bool> completed-tasks-visible: false;
|
||||
|
||||
HorizontalLayout {
|
||||
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
padding: 16px;
|
||||
spacing: 16px;
|
||||
HorizontalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
VButton {
|
||||
text: "Show/Hide completed tasks";
|
||||
clicked => {
|
||||
AppWindowActions.toggle-show-completed-tasks();
|
||||
completed-tasks-visible = !completed-tasks-visible;
|
||||
}
|
||||
icon-svg: completed-tasks-visible ? icon-visible : icon-not-visible;
|
||||
icon-colorize: Palette.control-foreground;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
background: Palette.background.brighter(0.2);
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
CreateTaskOrEvent {
|
||||
sources: AppWindowModels.sources;
|
||||
create-task(data) => {
|
||||
AppWindowActions.create-task({
|
||||
sourceId: data.sourceId,
|
||||
eventId: -1,
|
||||
title: data.title,
|
||||
scheduled: data.date.year != 0,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
|
||||
create-event(data) => {
|
||||
AppWindowActions.create-event({
|
||||
sourceId: data.sourceId,
|
||||
title: data.title,
|
||||
date: data.date,
|
||||
startsAt: data.startsAt,
|
||||
endsAt: data.endsAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
horizontal-stretch: 1;
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
spacing: 16px;
|
||||
if AppWindowModels.days.length == 0 && AppWindowModels.unscheduled-tasks.length == 0 : VText {
|
||||
text: "There is no task to show";
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
for day[dayIndex] in AppWindowModels.days: VerticalLayout {
|
||||
Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: Utils.format-date(day.date);
|
||||
color: day.isLate ? Palette.orange : Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
VText {
|
||||
text: day.relativeDaysDiff == 0 ? " - today" :
|
||||
day.relativeDaysDiff == 1 ? " - tomorrow" :
|
||||
day.relativeDaysDiff == -1 ? " - yesterday" :
|
||||
day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
|
||||
" - \{-day.relativeDaysDiff} days ago";
|
||||
color: Palette.foreground-hint;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
for event[eventIndex] in day.events: VerticalLayout {
|
||||
padding-top: 16px;
|
||||
EventGroup {
|
||||
event: event;
|
||||
add-task(data) => {
|
||||
AppWindowActions.create-task({
|
||||
sourceId: event.sourceId,
|
||||
eventId: event.id,
|
||||
title: data.title,
|
||||
});
|
||||
}
|
||||
edit-task(taskId, data) => {
|
||||
AppWindowActions.save-task({
|
||||
id: taskId,
|
||||
sourceId: event.sourceId,
|
||||
title: data.title,
|
||||
});
|
||||
}
|
||||
delete-task(taskId) => {
|
||||
AppWindowActions.delete-task-clicked(event.sourceId, taskId)
|
||||
}
|
||||
toggle-check-task(taskId) => {
|
||||
AppWindowActions.task-clicked(event.sourceId, taskId);
|
||||
}
|
||||
delete => {
|
||||
AppWindowActions.delete-event-clicked(event.sourceId, event.id)
|
||||
}
|
||||
edit(data) => {
|
||||
AppWindowActions.save-event({
|
||||
sourceId: event.sourceId,
|
||||
id: event.id,
|
||||
title: data.title,
|
||||
//date: event.date,
|
||||
startsAt: event.startsAt,
|
||||
endsAt: event.endsAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in day.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
scheduled: task.date.year != 0;
|
||||
date: day.date;
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppWindowActions.delete-task-clicked(task.sourceId, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppWindowActions.task-clicked(task.sourceId, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppWindowActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if AppWindowModels.unscheduled-tasks.length > 0 : VerticalLayout {
|
||||
Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: "Unscheduled";
|
||||
color: Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in AppWindowModels.unscheduled-tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppWindowActions.delete-task-clicked(task.sourceId, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppWindowActions.task-clicked(task.sourceId, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppWindowActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Calendar {
|
||||
init => { debug("cal len", AppWindowModels.calendar.length) }
|
||||
days: AppWindowModels.calendar;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
src/windows/EditSourceWindow/EditSourceWindow.cpp
Normal file
61
src/windows/EditSourceWindow/EditSourceWindow.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "EditSourceWindow.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <string>
|
||||
|
||||
EditSourceWindow::EditSourceWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
||||
if (palette.has_value()) {
|
||||
setSelenitePalette(window_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
setupCallbacks();
|
||||
}
|
||||
|
||||
void EditSourceWindow::setupCallbacks()
|
||||
{
|
||||
window_->on_modify_source([&](ui::ModifySourceParam params) {
|
||||
miraiInstance_->editSource(params.id, std::string(params.name), std::string(params.path));
|
||||
close();
|
||||
});
|
||||
window_->on_delete_source([&](int sourceId) {
|
||||
miraiInstance_->deleteSource(sourceId);
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
void EditSourceWindow::open(mirai::Source *source)
|
||||
{
|
||||
assert(source != nullptr);
|
||||
auto markdownSource = dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||
window_->set_id(source->id);
|
||||
window_->set_name(slint::SharedString(source->name()));
|
||||
window_->set_path(slint::SharedString(markdownSource->path()));
|
||||
window_->show();
|
||||
}
|
||||
|
||||
void EditSourceWindow::close()
|
||||
{
|
||||
window_->hide();
|
||||
}
|
29
src/windows/EditSourceWindow/EditSourceWindow.h
Normal file
29
src/windows/EditSourceWindow/EditSourceWindow.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/Source.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class EditSourceWindow
|
||||
{
|
||||
|
||||
public:
|
||||
EditSourceWindow(mirai::Mirai *mirai);
|
||||
|
||||
void open(mirai::Source *source);
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
slint::ComponentHandle<ui::EditSourceWindow> window_ = ui::EditSourceWindow::create();
|
||||
mirai::Mirai *miraiInstance_;
|
||||
};
|
54
src/windows/EditSourceWindow/EditSourceWindow.slint
Normal file
54
src/windows/EditSourceWindow/EditSourceWindow.slint
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { VButton, VText, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export struct ModifySourceParam {
|
||||
id: int,
|
||||
name: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
export component EditSourceWindow inherits Window {
|
||||
in-out property <int> id;
|
||||
in-out property name <=> nameInput.text;
|
||||
in-out property path <=> pathInput.text;
|
||||
|
||||
title: "Mirai - Edit source";
|
||||
min-height: 100px;
|
||||
max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
|
||||
min-width: 400px;
|
||||
default-font-size: 16px;
|
||||
background: Palette.background;
|
||||
|
||||
callback modify-source(ModifySourceParam);
|
||||
callback delete-source(int);
|
||||
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
nameInput := VTextInput {
|
||||
label: "Name";
|
||||
}
|
||||
pathInput := VTextInput {
|
||||
label: "Path";
|
||||
}
|
||||
VButton {
|
||||
text: "Save";
|
||||
clicked => {
|
||||
root.modify-source({
|
||||
id: root.id,
|
||||
name: nameInput.text,
|
||||
path: pathInput.text
|
||||
})
|
||||
}
|
||||
}
|
||||
VButton {
|
||||
text: "Delete";
|
||||
background-color: Palette.red;
|
||||
double-clicked => {
|
||||
root.delete-source(root.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { Palette } // Export to make it visible to the C++ backend
|
50
src/windows/SettingsWindow/SettingsWindow.cpp
Normal file
50
src/windows/SettingsWindow/SettingsWindow.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "SettingsWindow.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <string>
|
||||
|
||||
SettingsWindow::SettingsWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
||||
if (palette.has_value()) {
|
||||
setSelenitePalette(window_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
setupCallbacks();
|
||||
}
|
||||
|
||||
void SettingsWindow::setupCallbacks()
|
||||
{
|
||||
}
|
||||
|
||||
void SettingsWindow::open()
|
||||
{
|
||||
window_->show();
|
||||
}
|
||||
|
||||
void SettingsWindow::close()
|
||||
{
|
||||
window_->hide();
|
||||
}
|
28
src/windows/SettingsWindow/SettingsWindow.h
Normal file
28
src/windows/SettingsWindow/SettingsWindow.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class SettingsWindow
|
||||
{
|
||||
|
||||
public:
|
||||
SettingsWindow(mirai::Mirai *mirai);
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
slint::ComponentHandle<ui::SettingsWindow> window_ = ui::SettingsWindow::create();
|
||||
mirai::Mirai *miraiInstance_;
|
||||
};
|
27
src/windows/SettingsWindow/SettingsWindow.slint
Normal file
27
src/windows/SettingsWindow/SettingsWindow.slint
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { AppWindowModels } from "../AppWindow/Models.slint";
|
||||
import { Button, VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { VText, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export component SettingsWindow inherits Window {
|
||||
|
||||
title: "Mirai - Settings";
|
||||
min-height: 100px;
|
||||
max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
|
||||
default-font-size: 16px;
|
||||
background: Palette.background;
|
||||
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
for source[source-index] in AppWindowModels.sources-selected: VerticalLayout {
|
||||
VText {
|
||||
text: source.name;
|
||||
}
|
||||
VTextInput {
|
||||
text: source.path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { AppWindowModels, Palette } // Export to make it visible to the C++ backend
|
Loading…
Add table
Add a link
Reference in a new issue