mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
ModelGallery: Add the new Model Gallery application :^)
This is an application analogous to WidgetGallery, in that it tests various capabilities of LibGUI models. Right now it is pretty bare, but as more work towards LibGUI models is done regarding persistent model indices, more demos will be added.
This commit is contained in:
parent
a8967388d3
commit
b30b7de2d2
11 changed files with 327 additions and 0 deletions
41
Userland/Demos/ModelGallery/BasicModel.h
Normal file
41
Userland/Demos/ModelGallery/BasicModel.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
||||
class BasicModel final : public GUI::Model {
|
||||
public:
|
||||
static NonnullRefPtr<BasicModel> create()
|
||||
{
|
||||
return adopt_ref(*new BasicModel());
|
||||
}
|
||||
|
||||
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return m_items.size(); }
|
||||
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return 1; }
|
||||
virtual String column_name(int) const override { return "Item"; }
|
||||
|
||||
virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole = GUI::ModelRole::Display) const override;
|
||||
virtual TriState data_matches(GUI::ModelIndex const&, GUI::Variant const&) const override;
|
||||
virtual void invalidate() override;
|
||||
virtual GUI::ModelIndex index(int row, int column = 0, GUI::ModelIndex const& parent = GUI::ModelIndex()) const override;
|
||||
|
||||
Function<void()> on_invalidate;
|
||||
|
||||
void add_item(String const& item);
|
||||
void remove_item(GUI::ModelIndex const&);
|
||||
|
||||
private:
|
||||
BasicModel()
|
||||
{
|
||||
}
|
||||
|
||||
Vector<String> m_items;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue