-
Hello everybody, Let's say I have a simple project, with a Slint file like this: // appwindow.slint
import { ListView, VerticalBox, Switch } from "std-widgets.slint";
export component AppWindow inherits Window {
in property <[int]> model;
in-out property ascending <=> ascending-switch.checked;
callback ascending-changed <=> ascending-switch.toggled;
VerticalBox {
ascending-switch := Switch {
text: "Ascending";
}
ListView {
for item in root.model: Text {
text: item;
}
}
}
} On C++ side, this is the entire implementation: // main.cpp
#include <memory>
#include <utility>
#include "appwindow.h"
#include "slint.h"
class MySortModel: public slint::SortModel<int>
{
bool ascending{true};
[[nodiscard]] auto sort(const int& first, const int& second) const -> bool
{
return ascending ? first < second : first >= second;
}
public:
MySortModel(std::shared_ptr<Model<int>> source_model):
slint::SortModel<int>{std::move(source_model),
[this](const int& first, const int& second) { return sort(first, second); }}
{ }
[[nodiscard]] auto getAscending() const -> bool { return ascending; }
void setAscending(bool value)
{
ascending = value;
// Perform some kind of magic to force sorting re-evaluation
}
};
auto main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) -> int
{
auto appWindow{AppWindow::create()};
const auto model{std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2, 3, 4, 5})};
const auto sortModel{std::make_shared<MySortModel>(model)};
appWindow->set_ascending(sortModel->getAscending());
appWindow->set_model(sortModel);
appWindow->on_ascending_changed([appWindow, sortModel]() { sortModel->setAscending(appWindow->get_ascending()); });
appWindow->run();
return 0;
} Inside How to achieve this behavior? Reading the documentation, it seems that Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a bug in |
Beta Was this translation helpful? Give feedback.
Filled as an issue in #4968