Squashed 'libraries/ZWidget/' changes from b5ae8c8ab0..bac2a2edc5
bac2a2edc5 Exclude SDL2 from Windows compilation. 5b859bfd84 WaylandDisplayBackend: If the clicked window has a locked mouse, hide the cursor afterwards ce76df6aa6 WaylandDisplayBackend: Add a TODO about XDG_Activation a0ba04275b WaylandDisplayWindow: Move XDG Activation Token outside activate() git-subtree-dir: libraries/ZWidget git-subtree-split: bac2a2edc52cf12d1223244251876e9c4533e614
This commit is contained in:
parent
65cfb976fa
commit
991d522c57
7883 changed files with 331 additions and 1694333 deletions
34
include/zwidget/widgets/checkboxlabel/checkboxlabel.h
Normal file
34
include/zwidget/widgets/checkboxlabel/checkboxlabel.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
|
||||
class CheckboxLabel : public Widget
|
||||
{
|
||||
public:
|
||||
CheckboxLabel(Widget* parent = nullptr);
|
||||
|
||||
void SetText(const std::string& value);
|
||||
const std::string& GetText() const;
|
||||
|
||||
void SetChecked(bool value);
|
||||
bool GetChecked() const;
|
||||
void Toggle();
|
||||
|
||||
double GetPreferredHeight() const;
|
||||
std::function<void(bool)> FuncChanged;
|
||||
void SetRadioStyle(bool on) { radiostyle = on; }
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseLeave() override;
|
||||
void OnKeyUp(InputKey key) override;
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
bool checked = false;
|
||||
bool radiostyle = false;
|
||||
bool mouseDownActive = false;
|
||||
};
|
||||
69
include/zwidget/widgets/dropdown/dropdown.h
Normal file
69
include/zwidget/widgets/dropdown/dropdown.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../../widgets/listview/listview.h"
|
||||
|
||||
class DropdownList : public ListView
|
||||
{
|
||||
public:
|
||||
DropdownList(Widget* parent, Dropdown* owner);
|
||||
protected:
|
||||
void OnKeyDown(InputKey key) override;
|
||||
Dropdown* owner;
|
||||
};
|
||||
|
||||
class Dropdown : public Widget
|
||||
{
|
||||
public:
|
||||
Dropdown(Widget* parent);
|
||||
|
||||
void AddItem(const std::string& text, int index = -1);
|
||||
bool UpdateItem(const std::string& text, int index);
|
||||
bool RemoveItem(int index = -1);
|
||||
void ClearItems();
|
||||
const std::string& GetItem(int index);
|
||||
|
||||
void SetMaxDisplayItems(int items);
|
||||
void SetDropdownDirection(bool below);
|
||||
|
||||
int GetSelectedItem() const { return selectedItem; }
|
||||
void SetSelectedItem(int index);
|
||||
|
||||
double GetPreferredHeight() const;
|
||||
double GetPreferredWidth() const;
|
||||
|
||||
std::function<void(int)> OnChanged;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
void OnKeyDown(InputKey key) override;
|
||||
void OnGeometryChanged() override;
|
||||
void OnLostFocus() override;
|
||||
void Notify(Widget* source, const WidgetEvent type) override;
|
||||
|
||||
private:
|
||||
void ItemsChanged();
|
||||
bool OpenDropdown();
|
||||
bool CloseDropdown();
|
||||
void OnDropdownActivated();
|
||||
|
||||
size_t GetDisplayItems();
|
||||
|
||||
std::vector<std::string> items;
|
||||
int selectedItem = -1;
|
||||
std::string text;
|
||||
|
||||
bool dropdownOpen = false;
|
||||
Widget* dropdown = nullptr;
|
||||
DropdownList* listView = nullptr;
|
||||
|
||||
int maxDisplayItems = 0;
|
||||
bool dropdownDirection = true;
|
||||
|
||||
friend DropdownList;
|
||||
};
|
||||
31
include/zwidget/widgets/imagebox/imagebox.h
Normal file
31
include/zwidget/widgets/imagebox/imagebox.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../../core/image.h"
|
||||
|
||||
enum ImageBoxMode
|
||||
{
|
||||
Center,
|
||||
Contain,
|
||||
Cover
|
||||
};
|
||||
|
||||
class ImageBox : public Widget
|
||||
{
|
||||
public:
|
||||
ImageBox(Widget* parent);
|
||||
|
||||
void SetImage(std::shared_ptr<Image> newImage);
|
||||
void SetImageMode(ImageBoxMode mode);
|
||||
|
||||
double GetPreferredWidth() const;
|
||||
double GetPreferredHeight() const;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Image> image;
|
||||
ImageBoxMode mode = ImageBoxMode::Center;
|
||||
};
|
||||
158
include/zwidget/widgets/lineedit/lineedit.h
Normal file
158
include/zwidget/widgets/lineedit/lineedit.h
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../../core/timer.h"
|
||||
#include <functional>
|
||||
|
||||
class LineEdit : public Widget
|
||||
{
|
||||
public:
|
||||
LineEdit(Widget* parent);
|
||||
~LineEdit();
|
||||
|
||||
enum Alignment
|
||||
{
|
||||
align_left,
|
||||
align_center,
|
||||
align_right
|
||||
};
|
||||
|
||||
Alignment GetAlignment() const;
|
||||
bool IsReadOnly() const;
|
||||
bool IsLowercase() const;
|
||||
bool IsUppercase() const;
|
||||
bool IsPasswordMode() const;
|
||||
int GetMaxLength() const;
|
||||
|
||||
std::string GetText() const;
|
||||
int GetTextInt() const;
|
||||
float GetTextFloat() const;
|
||||
|
||||
std::string GetSelection() const;
|
||||
int GetSelectionStart() const;
|
||||
int GetSelectionLength() const;
|
||||
|
||||
int GetCursorPos() const;
|
||||
Size GetTextSize();
|
||||
|
||||
Size GetTextSize(const std::string& str);
|
||||
double GetPreferredContentWidth();
|
||||
double GetPreferredContentHeight(double width);
|
||||
|
||||
void SetSelectAllOnFocusGain(bool enable);
|
||||
void SelectAll();
|
||||
void SetAlignment(Alignment alignment);
|
||||
void SetReadOnly(bool enable = true);
|
||||
void SetLowercase(bool enable = true);
|
||||
void SetUppercase(bool enable = true);
|
||||
void SetPasswordMode(bool enable = true);
|
||||
void SetNumericMode(bool enable = true, bool decimals = false);
|
||||
void SetMaxLength(int length);
|
||||
void SetText(const std::string& text);
|
||||
void SetTextInt(int number);
|
||||
void SetTextFloat(float number, int num_decimal_places = 6);
|
||||
void SetSelection(int pos, int length);
|
||||
void ClearSelection();
|
||||
void SetCursorPos(int pos);
|
||||
void DeleteSelectedText();
|
||||
void SetInputMask(const std::string& mask);
|
||||
void SetDecimalCharacter(const std::string& decimal_char);
|
||||
|
||||
std::function<bool(InputKey key)> FuncIgnoreKeyDown;
|
||||
std::function<std::string(std::string text)> FuncFilterKeyChar;
|
||||
std::function<void()> FuncBeforeEditChanged;
|
||||
std::function<void()> FuncAfterEditChanged;
|
||||
std::function<void()> FuncSelectionChanged;
|
||||
std::function<void()> FuncFocusGained;
|
||||
std::function<void()> FuncFocusLost;
|
||||
std::function<void()> FuncEnterPressed;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseDoubleclick(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnKeyChar(std::string chars) override;
|
||||
void OnKeyDown(InputKey key) override;
|
||||
void OnKeyUp(InputKey key) override;
|
||||
void OnGeometryChanged() override;
|
||||
void OnEnableChanged() override;
|
||||
void OnSetFocus() override;
|
||||
void OnLostFocus() override;
|
||||
|
||||
private:
|
||||
void OnTimerExpired();
|
||||
void OnScrollTimerExpired();
|
||||
void UpdateTextClipping();
|
||||
|
||||
void Move(int steps, bool ctrl, bool shift);
|
||||
bool InsertText(int pos, const std::string& str);
|
||||
void Backspace();
|
||||
void Del();
|
||||
int GetCharacterIndex(double x);
|
||||
int FindNextBreakCharacter(int pos);
|
||||
int FindPreviousBreakCharacter(int pos);
|
||||
std::string GetVisibleTextBeforeSelection();
|
||||
std::string GetVisibleTextAfterSelection();
|
||||
std::string GetVisibleSelectedText();
|
||||
std::string CreatePassword(std::string::size_type num_letters) const;
|
||||
Size GetVisualTextSize(Canvas* canvas, int pos, int npos) const;
|
||||
Size GetVisualTextSize(Canvas* canvas) const;
|
||||
Rect GetCursorRect();
|
||||
Rect GetSelectionRect();
|
||||
bool InputMaskAcceptsInput(int cursor_pos, const std::string& str);
|
||||
void SetSelectionStart(int start);
|
||||
void SetSelectionLength(int length);
|
||||
void SetTextSelection(int start, int length);
|
||||
|
||||
static std::string ToFixed(float number, int num_decimal_places);
|
||||
static std::string ToLower(const std::string& text);
|
||||
static std::string ToUpper(const std::string& text);
|
||||
|
||||
Timer* timer = nullptr;
|
||||
std::string text;
|
||||
Alignment alignment = align_left;
|
||||
int cursor_pos = 0;
|
||||
int max_length = -1;
|
||||
bool mouse_selecting = false;
|
||||
bool lowercase = false;
|
||||
bool uppercase = false;
|
||||
bool password_mode = false;
|
||||
bool numeric_mode = false;
|
||||
bool numeric_mode_decimals = false;
|
||||
bool readonly = false;
|
||||
int selection_start = -1;
|
||||
int selection_length = 0;
|
||||
std::string input_mask;
|
||||
std::string decimal_char = ".";
|
||||
|
||||
VerticalTextPosition vertical_text_align;
|
||||
Timer* scroll_timer = nullptr;
|
||||
|
||||
bool mouse_moves_left = false;
|
||||
bool cursor_blink_visible = true;
|
||||
unsigned int blink_timer = 0;
|
||||
int clip_start_offset = 0;
|
||||
int clip_end_offset = 0;
|
||||
|
||||
struct UndoInfo
|
||||
{
|
||||
/* set undo text when:
|
||||
- added char after moving
|
||||
- destructive block operation (del, cut etc)
|
||||
- beginning erase
|
||||
*/
|
||||
std::string undo_text;
|
||||
bool first_erase = false;
|
||||
bool first_text_insert = false;
|
||||
};
|
||||
|
||||
UndoInfo undo_info;
|
||||
|
||||
bool select_all_on_focus_gain = true;
|
||||
|
||||
static const std::string break_characters;
|
||||
static const std::string numeric_mode_characters;
|
||||
};
|
||||
53
include/zwidget/widgets/listview/listview.h
Normal file
53
include/zwidget/widgets/listview/listview.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
class Scrollbar;
|
||||
class Dropdown;
|
||||
|
||||
class ListView : public Widget
|
||||
{
|
||||
public:
|
||||
ListView(Widget* parent = nullptr);
|
||||
|
||||
void SetColumnWidths(const std::vector<double>& widths);
|
||||
void AddItem(const std::string& text, int index = -1, int column = 0);
|
||||
void UpdateItem(const std::string& text, int index, int column = 0);
|
||||
void RemoveItem(int index = -1);
|
||||
size_t GetItemAmount() const { return items.size(); }
|
||||
size_t GetColumnAmount() const { return columnwidths.size(); }
|
||||
int GetSelectedItem() const { return selectedItem; }
|
||||
void SetSelectedItem(int index);
|
||||
void ScrollToItem(int index);
|
||||
|
||||
double GetPreferredWidth();
|
||||
double GetPreferredHeight();
|
||||
double GetMinimumHeight() const;
|
||||
|
||||
void Activate();
|
||||
|
||||
std::function<void(int)> OnChanged;
|
||||
std::function<void()> OnActivated;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseDoubleclick(const Point& pos, InputKey key) override;
|
||||
bool OnMouseWheel(const Point& pos, InputKey key) override;
|
||||
void OnKeyDown(InputKey key) override;
|
||||
void OnGeometryChanged() override;
|
||||
void OnScrollbarScroll();
|
||||
|
||||
static double getItemHeight();
|
||||
|
||||
Scrollbar* scrollbar = nullptr;
|
||||
|
||||
std::vector<std::vector<std::string>> items;
|
||||
std::vector<double> columnwidths;
|
||||
int selectedItem = 0;
|
||||
|
||||
friend Dropdown;
|
||||
};
|
||||
33
include/zwidget/widgets/mainwindow/mainwindow.h
Normal file
33
include/zwidget/widgets/mainwindow/mainwindow.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
|
||||
class Menubar;
|
||||
class Toolbar;
|
||||
class Statusbar;
|
||||
|
||||
class MainWindow : public Widget
|
||||
{
|
||||
public:
|
||||
MainWindow(RenderAPI api = RenderAPI::Unspecified);
|
||||
~MainWindow();
|
||||
|
||||
Menubar* GetMenubar() const { return MenubarWidget; }
|
||||
Toolbar* GetTopToolbar() const { return TopToolbarWidget; }
|
||||
Toolbar* GetLeftToolbar() const { return LeftToolbarWidget; }
|
||||
Statusbar* GetStatusbar() const { return StatusbarWidget; }
|
||||
Widget* GetCentralWidget() const { return CentralWidget; }
|
||||
|
||||
void SetCentralWidget(Widget* widget);
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
Menubar* MenubarWidget = nullptr;
|
||||
Toolbar* TopToolbarWidget = nullptr;
|
||||
Toolbar* LeftToolbarWidget = nullptr;
|
||||
Widget* CentralWidget = nullptr;
|
||||
Statusbar* StatusbarWidget = nullptr;
|
||||
};
|
||||
121
include/zwidget/widgets/menubar/menubar.h
Normal file
121
include/zwidget/widgets/menubar/menubar.h
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../textlabel/textlabel.h"
|
||||
#include "../imagebox/imagebox.h"
|
||||
#include <vector>
|
||||
|
||||
class Menu;
|
||||
class MenubarItem;
|
||||
class MenuItem;
|
||||
class MenuItemSeparator;
|
||||
|
||||
class Menubar : public Widget
|
||||
{
|
||||
public:
|
||||
Menubar(Widget* parent);
|
||||
~Menubar();
|
||||
|
||||
MenubarItem* AddItem(std::string text, std::function<void(Menu* menu)> onOpen, bool alignRight = false);
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnKeyDown(InputKey key) override;
|
||||
|
||||
private:
|
||||
void ShowMenu(MenubarItem* item);
|
||||
void CloseMenu();
|
||||
|
||||
MenubarItem* GetMenubarItemAt(const Point& pos);
|
||||
int GetItemIndex(MenubarItem* item);
|
||||
|
||||
std::vector<MenubarItem*> menuItems;
|
||||
int currentMenubarItem = -1;
|
||||
Menu* openMenu = nullptr;
|
||||
bool modalMode = false;
|
||||
|
||||
friend class MenubarItem;
|
||||
};
|
||||
|
||||
class MenubarItem : public Widget
|
||||
{
|
||||
public:
|
||||
MenubarItem(Menubar* menubar, std::string text, bool alignRight);
|
||||
|
||||
void SetOpenCallback(std::function<void(Menu* menu)> callback) { onOpen = std::move(callback); }
|
||||
const std::function<void(Menu* menu)>& GetOpenCallback() const { return onOpen; }
|
||||
|
||||
double GetPreferredWidth() const;
|
||||
|
||||
bool AlignRight = false;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
|
||||
private:
|
||||
Menubar* menubar = nullptr;
|
||||
std::function<void(Menu* menu)> onOpen;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class Menu : public Widget
|
||||
{
|
||||
public:
|
||||
Menu(Widget* parent);
|
||||
|
||||
void SetLeftPosition(const Point& globalPos);
|
||||
void SetRightPosition(const Point& globalPos);
|
||||
MenuItem* AddItem(std::shared_ptr<Image> icon, std::string text, std::function<void()> onClick = {});
|
||||
MenuItemSeparator* AddSeparator();
|
||||
|
||||
double GetPreferredWidth() const;
|
||||
double GetPreferredHeight() const;
|
||||
|
||||
void SetSelected(MenuItem* item);
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
std::function<void()> onCloseMenu;
|
||||
MenuItem* selectedItem = nullptr;
|
||||
|
||||
friend class Menubar;
|
||||
};
|
||||
|
||||
class MenuItem : public Widget
|
||||
{
|
||||
public:
|
||||
MenuItem(Menu* menu, std::function<void()> onClick);
|
||||
|
||||
void Click();
|
||||
|
||||
Menu* menu = nullptr;
|
||||
ImageBox* icon = nullptr;
|
||||
TextLabel* text = nullptr;
|
||||
|
||||
protected:
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
std::function<void()> onClick;
|
||||
};
|
||||
|
||||
class MenuItemSeparator : public Widget
|
||||
{
|
||||
public:
|
||||
MenuItemSeparator(Widget* parent);
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
};
|
||||
32
include/zwidget/widgets/pushbutton/pushbutton.h
Normal file
32
include/zwidget/widgets/pushbutton/pushbutton.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include <functional>
|
||||
|
||||
class PushButton : public Widget
|
||||
{
|
||||
public:
|
||||
PushButton(Widget* parent = nullptr);
|
||||
|
||||
void SetText(const std::string& value);
|
||||
const std::string& GetText() const;
|
||||
|
||||
double GetPreferredHeight() const;
|
||||
|
||||
void Click();
|
||||
|
||||
std::function<void()> OnClick;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
void OnKeyDown(InputKey key) override;
|
||||
void OnKeyUp(InputKey key) override;
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
};
|
||||
99
include/zwidget/widgets/scrollbar/scrollbar.h
Normal file
99
include/zwidget/widgets/scrollbar/scrollbar.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../../core/timer.h"
|
||||
#include <functional>
|
||||
|
||||
class Scrollbar : public Widget
|
||||
{
|
||||
public:
|
||||
Scrollbar(Widget* parent);
|
||||
~Scrollbar();
|
||||
|
||||
bool IsVertical() const;
|
||||
bool IsHorizontal() const;
|
||||
double GetMin() const;
|
||||
double GetMax() const;
|
||||
double GetLineStep() const;
|
||||
double GetPageStep() const;
|
||||
double GetPosition() const;
|
||||
|
||||
void SetVertical();
|
||||
void SetHorizontal();
|
||||
|
||||
void SetMin(double scroll_min);
|
||||
void SetMax(double scroll_max);
|
||||
void SetLineStep(double step);
|
||||
void SetPageStep(double step);
|
||||
|
||||
void SetRanges(double scroll_min, double scroll_max, double line_step, double page_step);
|
||||
void SetRanges(double view_size, double total_size);
|
||||
|
||||
void SetPosition(double pos);
|
||||
|
||||
double GetPreferredWidth() const { return 16.0; }
|
||||
double GetPreferredHeight() const { return 16.0; }
|
||||
|
||||
std::function<void()> FuncScroll;
|
||||
std::function<void()> FuncScrollMin;
|
||||
std::function<void()> FuncScrollMax;
|
||||
std::function<void()> FuncScrollLineDecrement;
|
||||
std::function<void()> FuncScrollLineIncrement;
|
||||
std::function<void()> FuncScrollPageDecrement;
|
||||
std::function<void()> FuncScrollPageIncrement;
|
||||
std::function<void()> FuncScrollThumbRelease;
|
||||
std::function<void()> FuncScrollThumbTrack;
|
||||
std::function<void()> FuncScrollEnd;
|
||||
|
||||
protected:
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
void OnEnableChanged() override;
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
bool UpdatePartPositions();
|
||||
double CalculateThumbSize(double track_size);
|
||||
double CalculateThumbPosition(double thumb_size, double track_size);
|
||||
Rect CreateRect(double start, double end);
|
||||
void InvokeScrollEvent(std::function<void()>* event_ptr);
|
||||
void OnTimerExpired();
|
||||
|
||||
bool vertical = true;
|
||||
double scroll_min = 0.0;
|
||||
double scroll_max = 1.0;
|
||||
double line_step = 1.0;
|
||||
double page_step = 10.0;
|
||||
double position = 0.0;
|
||||
|
||||
bool showbuttons = false;
|
||||
|
||||
enum MouseDownMode
|
||||
{
|
||||
mouse_down_none,
|
||||
mouse_down_button_decr,
|
||||
mouse_down_button_incr,
|
||||
mouse_down_track_decr,
|
||||
mouse_down_track_incr,
|
||||
mouse_down_thumb_drag
|
||||
} mouse_down_mode = mouse_down_none;
|
||||
|
||||
double thumb_start_position = 0.0;
|
||||
Point mouse_drag_start_pos;
|
||||
double thumb_start_pixel_position = 0.0;
|
||||
|
||||
Timer* mouse_down_timer = nullptr;
|
||||
double last_step_size = 0.0;
|
||||
|
||||
Rect rect_button_decrement;
|
||||
Rect rect_track_decrement;
|
||||
Rect rect_thumb;
|
||||
Rect rect_track_increment;
|
||||
Rect rect_button_increment;
|
||||
|
||||
std::function<void()>* FuncScrollOnMouseDown = nullptr;
|
||||
};
|
||||
19
include/zwidget/widgets/statusbar/statusbar.h
Normal file
19
include/zwidget/widgets/statusbar/statusbar.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
|
||||
class LineEdit;
|
||||
|
||||
class Statusbar : public Widget
|
||||
{
|
||||
public:
|
||||
Statusbar(Widget* parent);
|
||||
~Statusbar();
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
|
||||
private:
|
||||
LineEdit* CommandEdit = nullptr;
|
||||
};
|
||||
129
include/zwidget/widgets/tabwidget/tabwidget.h
Normal file
129
include/zwidget/widgets/tabwidget/tabwidget.h
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TabBar;
|
||||
class TabBarTab;
|
||||
class TabBarSpacer;
|
||||
class TabWidgetStack;
|
||||
class TextLabel;
|
||||
class ImageBox;
|
||||
class Image;
|
||||
|
||||
class TabWidget : public Widget
|
||||
{
|
||||
public:
|
||||
TabWidget(Widget* parent);
|
||||
|
||||
int AddTab(Widget* page, const std::string& label);
|
||||
int AddTab(Widget* page, const std::shared_ptr<Image>& icon, const std::string& label);
|
||||
|
||||
void SetTabText(int index, const std::string& text);
|
||||
void SetTabText(Widget* page, const std::string& text);
|
||||
void SetTabIcon(int index, const std::shared_ptr<Image>& icon);
|
||||
void SetTabIcon(Widget* page, const std::shared_ptr<Image>& icon);
|
||||
|
||||
int GetCurrentIndex() const;
|
||||
Widget* GetCurrentWidget() const;
|
||||
|
||||
int GetPageIndex(Widget* pageWidget) const;
|
||||
|
||||
void SetCurrentIndex(int pageIndex);
|
||||
void SetCurrentWidget(Widget* pageWidget);
|
||||
|
||||
std::function<void()> OnCurrentChanged;
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
void OnBarCurrentChanged();
|
||||
|
||||
TabBar* Bar = nullptr;
|
||||
TabWidgetStack* PageStack = nullptr;
|
||||
std::vector<Widget*> Pages;
|
||||
};
|
||||
|
||||
class TabBar : public Widget
|
||||
{
|
||||
public:
|
||||
TabBar(Widget* parent);
|
||||
|
||||
int AddTab(const std::string& label);
|
||||
int AddTab(const std::shared_ptr<Image>& icon, const std::string& label);
|
||||
|
||||
void SetTabText(int index, const std::string& text);
|
||||
void SetTabIcon(int index, const std::shared_ptr<Image>& icon);
|
||||
|
||||
int GetCurrentIndex() const;
|
||||
void SetCurrentIndex(int pageIndex);
|
||||
|
||||
double GetPreferredHeight() const { return 30.0; }
|
||||
|
||||
std::function<void()> OnCurrentChanged;
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
void OnTabClicked(TabBarTab* tab);
|
||||
int GetTabIndex(TabBarTab* tab);
|
||||
|
||||
int CurrentIndex = -1;
|
||||
std::vector<TabBarTab*> Tabs;
|
||||
TabBarSpacer* leftSpacer = nullptr;
|
||||
TabBarSpacer* rightSpacer = nullptr;
|
||||
};
|
||||
|
||||
class TabBarSpacer : public Widget
|
||||
{
|
||||
public:
|
||||
TabBarSpacer(Widget* parent);
|
||||
};
|
||||
|
||||
class TabBarTab : public Widget
|
||||
{
|
||||
public:
|
||||
TabBarTab(Widget* parent);
|
||||
|
||||
void SetText(const std::string& text);
|
||||
void SetIcon(const std::shared_ptr<Image>& icon);
|
||||
void SetCurrent(bool value);
|
||||
|
||||
double GetPreferredWidth() const;
|
||||
|
||||
std::function<void()> OnClick;
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
|
||||
private:
|
||||
bool IsCurrent = false;
|
||||
|
||||
ImageBox* Icon = nullptr;
|
||||
TextLabel* Label = nullptr;
|
||||
bool hot = false;
|
||||
};
|
||||
|
||||
class TabWidgetStack : public Widget
|
||||
{
|
||||
public:
|
||||
TabWidgetStack(Widget* parent);
|
||||
|
||||
void SetCurrentWidget(Widget* widget);
|
||||
Widget* GetCurrentWidget() const { return CurrentWidget; }
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
Widget* CurrentWidget = nullptr;
|
||||
};
|
||||
161
include/zwidget/widgets/textedit/textedit.h
Normal file
161
include/zwidget/widgets/textedit/textedit.h
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../../core/timer.h"
|
||||
#include "../../core/span_layout.h"
|
||||
#include "../../core/font.h"
|
||||
#include <functional>
|
||||
|
||||
class Scrollbar;
|
||||
|
||||
class TextEdit : public Widget
|
||||
{
|
||||
public:
|
||||
TextEdit(Widget* parent);
|
||||
~TextEdit();
|
||||
|
||||
bool IsReadOnly() const;
|
||||
bool IsLowercase() const;
|
||||
bool IsUppercase() const;
|
||||
int GetMaxLength() const;
|
||||
std::string GetText() const;
|
||||
int GetLineCount() const;
|
||||
std::string GetLineText(int line) const;
|
||||
std::string GetSelection() const;
|
||||
int GetSelectionStart() const;
|
||||
int GetSelectionLength() const;
|
||||
int GetCursorPos() const;
|
||||
int GetCursorLineNumber() const;
|
||||
double GetTotalHeight();
|
||||
|
||||
void SetSelectAllOnFocusGain(bool enable);
|
||||
void SelectAll();
|
||||
void SetReadOnly(bool enable = true);
|
||||
void SetLowercase(bool enable = true);
|
||||
void SetUppercase(bool enable = true);
|
||||
void SetMaxLength(int length);
|
||||
void SetText(const std::string& text);
|
||||
void AddText(const std::string& text);
|
||||
void SetSelection(int pos, int length);
|
||||
void ClearSelection();
|
||||
void SetCursorPos(int pos);
|
||||
void DeleteSelectedText();
|
||||
void SetInputMask(const std::string& mask);
|
||||
void SetCursorDrawingEnabled(bool enable);
|
||||
|
||||
std::function<std::string(std::string text)> FuncFilterKeyChar;
|
||||
std::function<void()> FuncBeforeEditChanged;
|
||||
std::function<void()> FuncAfterEditChanged;
|
||||
std::function<void()> FuncSelectionChanged;
|
||||
std::function<void()> FuncFocusGained;
|
||||
std::function<void()> FuncFocusLost;
|
||||
std::function<void()> FuncEnterPressed;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseDoubleclick(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnKeyChar(std::string chars) override;
|
||||
void OnKeyDown(InputKey key) override;
|
||||
void OnKeyUp(InputKey key) override;
|
||||
void OnGeometryChanged() override;
|
||||
void OnEnableChanged() override;
|
||||
void OnSetFocus() override;
|
||||
void OnLostFocus() override;
|
||||
|
||||
private:
|
||||
void LayoutLines(Canvas* canvas);
|
||||
|
||||
void OnTimerExpired();
|
||||
void OnScrollTimerExpired();
|
||||
void CreateComponents();
|
||||
void OnVerticalScroll();
|
||||
void UpdateVerticalScroll();
|
||||
void MoveVerticalScroll();
|
||||
double GetTotalLineHeight();
|
||||
|
||||
struct Line
|
||||
{
|
||||
std::string text;
|
||||
SpanLayout layout;
|
||||
Rect box;
|
||||
bool invalidated = true;
|
||||
|
||||
Line(const TextEdit *self)
|
||||
{
|
||||
layout.SetSelectionColors(self->selectionFG, self->selectionBG);
|
||||
}
|
||||
};
|
||||
|
||||
struct ivec2
|
||||
{
|
||||
ivec2() = default;
|
||||
ivec2(int x, int y) : x(x), y(y) { }
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
bool operator==(const ivec2& b) const { return x == b.x && y == b.y; }
|
||||
bool operator!=(const ivec2& b) const { return x != b.x || y != b.y; }
|
||||
};
|
||||
|
||||
Colorf selectionBG, selectionFG;
|
||||
Scrollbar* vert_scrollbar;
|
||||
Timer* timer = nullptr;
|
||||
std::vector<Line> lines = { Line{this} };
|
||||
ivec2 cursor_pos = { 0, 0 };
|
||||
int max_length = -1;
|
||||
bool mouse_selecting = false;
|
||||
bool lowercase = false;
|
||||
bool uppercase = false;
|
||||
bool readonly = false;
|
||||
ivec2 selection_start = { -1, 0 };
|
||||
int selection_length = 0;
|
||||
std::string input_mask;
|
||||
|
||||
static std::string break_characters;
|
||||
|
||||
void Move(int steps, bool shift, bool ctrl);
|
||||
void InsertText(ivec2 pos, const std::string& str);
|
||||
void Backspace();
|
||||
void Del();
|
||||
ivec2 GetCharacterIndex(Point mouse_wincoords);
|
||||
ivec2 FindNextBreakCharacter(ivec2 pos);
|
||||
ivec2 FindPreviousBreakCharacter(ivec2 pos);
|
||||
bool InputMaskAcceptsInput(ivec2 cursor_pos, const std::string& str);
|
||||
|
||||
std::string::size_type ToOffset(ivec2 pos) const;
|
||||
ivec2 FromOffset(std::string::size_type offset) const;
|
||||
|
||||
VerticalTextPosition vertical_text_align;
|
||||
Timer* scroll_timer = nullptr;
|
||||
|
||||
bool mouse_moves_left = false;
|
||||
bool cursor_blink_visible = true;
|
||||
unsigned int blink_timer = 0;
|
||||
int clip_start_offset = 0;
|
||||
int clip_end_offset = 0;
|
||||
bool ignore_mouse_events = false;
|
||||
|
||||
struct UndoInfo
|
||||
{
|
||||
/* set undo text when:
|
||||
- added char after moving
|
||||
- destructive block operation (del, cut etc)
|
||||
- beginning erase
|
||||
*/
|
||||
|
||||
std::string undo_text;
|
||||
bool first_erase = false;
|
||||
bool first_text_insert = false;
|
||||
} undo_info;
|
||||
|
||||
bool select_all_on_focus_gain = false;
|
||||
|
||||
std::shared_ptr<Font> font = Font::Create("NotoSans", 12.0);
|
||||
|
||||
template<typename T>
|
||||
static T clamp(T val, T minval, T maxval) { return std::max<T>(std::min<T>(val, maxval), minval); }
|
||||
};
|
||||
33
include/zwidget/widgets/textlabel/textlabel.h
Normal file
33
include/zwidget/widgets/textlabel/textlabel.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
|
||||
enum class TextLabelAlignment
|
||||
{
|
||||
Left,
|
||||
Center,
|
||||
Right
|
||||
};
|
||||
|
||||
class TextLabel : public Widget
|
||||
{
|
||||
public:
|
||||
TextLabel(Widget* parent = nullptr);
|
||||
|
||||
void SetText(const std::string& value);
|
||||
const std::string& GetText() const;
|
||||
|
||||
void SetTextAlignment(TextLabelAlignment alignment);
|
||||
TextLabelAlignment GetTextAlignment() const;
|
||||
|
||||
double GetPreferredWidth() const;
|
||||
double GetPreferredHeight() const;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
TextLabelAlignment textAlignment = TextLabelAlignment::Left;
|
||||
};
|
||||
31
include/zwidget/widgets/toolbar/toolbar.h
Normal file
31
include/zwidget/widgets/toolbar/toolbar.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
|
||||
enum class ToolbarDirection
|
||||
{
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
|
||||
class ToolbarButton;
|
||||
|
||||
class Toolbar : public Widget
|
||||
{
|
||||
public:
|
||||
Toolbar(Widget* parent);
|
||||
~Toolbar();
|
||||
|
||||
void SetDirection(ToolbarDirection direction);
|
||||
ToolbarDirection GetDirection(ToolbarDirection) const { return direction; }
|
||||
|
||||
ToolbarButton* AddButton(std::string icon, std::string text, std::function<void()> onClicked = {});
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
ToolbarDirection direction = ToolbarDirection::Horizontal;
|
||||
std::vector<ToolbarButton*> buttons;
|
||||
};
|
||||
34
include/zwidget/widgets/toolbar/toolbarbutton.h
Normal file
34
include/zwidget/widgets/toolbar/toolbarbutton.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../textlabel/textlabel.h"
|
||||
#include "../imagebox/imagebox.h"
|
||||
|
||||
class ToolbarButton : public Widget
|
||||
{
|
||||
public:
|
||||
ToolbarButton(Widget* parent);
|
||||
~ToolbarButton();
|
||||
|
||||
void SetIcon(std::string icon);
|
||||
void SetText(std::string text);
|
||||
|
||||
void Click();
|
||||
|
||||
double GetPreferredWidth();
|
||||
double GetPreferredHeight();
|
||||
|
||||
std::function<void()> OnClick;
|
||||
|
||||
protected:
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey key) override;
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
ImageBox* image = nullptr;
|
||||
TextLabel* label = nullptr;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue