Update to latest ZWidget
This commit is contained in:
parent
6dd59c7787
commit
d24d5ae2c8
16 changed files with 578 additions and 36 deletions
|
|
@ -41,10 +41,23 @@ public:
|
|||
|
||||
// Widget noncontent area
|
||||
void SetNoncontentSizes(double left, double top, double right, double bottom);
|
||||
double GetNoncontentLeft() const { return GetStyleDouble("noncontent-left"); }
|
||||
double GetNoncontentTop() const { return GetStyleDouble("noncontent-top"); }
|
||||
double GetNoncontentRight() const { return GetStyleDouble("noncontent-right"); }
|
||||
double GetNoncontentBottom() const { return GetStyleDouble("noncontent-bottom"); }
|
||||
double GetNoncontentLeft() const { return GridFitSize(GetStyleDouble("noncontent-left")); }
|
||||
double GetNoncontentTop() const { return GridFitSize(GetStyleDouble("noncontent-top")); }
|
||||
double GetNoncontentRight() const { return GridFitSize(GetStyleDouble("noncontent-right")); }
|
||||
double GetNoncontentBottom() const { return GridFitSize(GetStyleDouble("noncontent-bottom")); }
|
||||
|
||||
// Get the DPI scale factor for the window the widget is located on
|
||||
double GetDpiScale() const;
|
||||
|
||||
// Align point to the nearest physical screen pixel
|
||||
double GridFitPoint(double p) const;
|
||||
Point GridFitPoint(double x, double y) const { return GridFitPoint(Point(x, y)); }
|
||||
Point GridFitPoint(Point p) const { return Point(GridFitPoint(p.x), GridFitPoint(p.y)); }
|
||||
|
||||
// Convert size to exactly covering physical screen pixels
|
||||
double GridFitSize(double s) const;
|
||||
Size GridFitSize(double w, double h) const { return GridFitSize(Size(w, h)); }
|
||||
Size GridFitSize(Size s) const { return Size(GridFitSize(s.width), GridFitSize(s.height)); }
|
||||
|
||||
// Widget frame box
|
||||
Rect GetFrameGeometry() const;
|
||||
|
|
@ -108,7 +121,7 @@ public:
|
|||
std::string GetClipboardText();
|
||||
void SetClipboardText(const std::string& text);
|
||||
|
||||
Widget* Window();
|
||||
Widget* Window() const;
|
||||
Canvas* GetCanvas() const;
|
||||
Widget* ChildAt(double x, double y) { return ChildAt(Point(x, y)); }
|
||||
Widget* ChildAt(const Point& pos);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public:
|
|||
|
||||
void SetImage(std::shared_ptr<Image> newImage);
|
||||
|
||||
double GetPreferredWidth() const;
|
||||
double GetPreferredHeight() const;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include "../textlabel/textlabel.h"
|
||||
#include "../imagebox/imagebox.h"
|
||||
|
||||
class Menu;
|
||||
class MenubarItem;
|
||||
class MenuItem;
|
||||
class MenuItemSeparator;
|
||||
|
||||
class Menubar : public Widget
|
||||
{
|
||||
|
|
@ -9,6 +16,83 @@ public:
|
|||
Menubar(Widget* parent);
|
||||
~Menubar();
|
||||
|
||||
MenubarItem* AddItem(std::string text, std::function<void(Menu* menu)> onOpen, bool alignRight = false);
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
void ShowMenu(MenubarItem* item);
|
||||
void CloseMenu();
|
||||
|
||||
std::vector<MenubarItem*> menuItems;
|
||||
Menu* openMenu = nullptr;
|
||||
|
||||
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;
|
||||
|
||||
protected:
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
std::function<void()> onCloseMenu;
|
||||
|
||||
friend class Menubar;
|
||||
};
|
||||
|
||||
class MenuItem : public Widget
|
||||
{
|
||||
public:
|
||||
MenuItem(Widget* parent);
|
||||
|
||||
ImageBox* icon = nullptr;
|
||||
TextLabel* text = nullptr;
|
||||
|
||||
protected:
|
||||
void OnMouseMove(const Point& pos) override;
|
||||
void OnMouseLeave() override;
|
||||
void OnGeometryChanged() override;
|
||||
};
|
||||
|
||||
class MenuItemSeparator : public Widget
|
||||
{
|
||||
public:
|
||||
MenuItemSeparator(Widget* parent);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public:
|
|||
class DisplayWindow
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<DisplayWindow> Create(DisplayWindowHost* windowHost);
|
||||
static std::unique_ptr<DisplayWindow> Create(DisplayWindowHost* windowHost, bool popupWindow);
|
||||
|
||||
static void ProcessEvents();
|
||||
static void RunLoop();
|
||||
|
|
@ -157,6 +157,9 @@ public:
|
|||
virtual int GetPixelHeight() const = 0;
|
||||
virtual double GetDpiScale() const = 0;
|
||||
|
||||
virtual Point MapFromGlobal(const Point& pos) const = 0;
|
||||
virtual Point MapToGlobal(const Point& pos) const = 0;
|
||||
|
||||
virtual void SetBorderColor(uint32_t bgra8) = 0;
|
||||
virtual void SetCaptionColor(uint32_t bgra8) = 0;
|
||||
virtual void SetCaptionTextColor(uint32_t bgra8) = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue