Window
Native window.
Header | #include "nativeui/window.h" |
Namespace | namespace nu |
Type | class (RefCounted) |
Inherits | Responder |
Constructors
Window(const Window::Options& options)
Create a new window with options
.
Parameters
const Window::Options&
options
Class properties
const char*
kClassName
The class name of window.
Methods
void Close()
Request to close the window.
bool HasFrame() const
Return whether window has a native frame.
Return
bool
bool IsTransparent() const
Return whether window is transparent.
Return
bool
void SetHasShadow(bool has)
Set whether window should have shadow.
Depending on platform, this may not work.
Parameters
bool
has
bool HasShadow() const
Return whether window has shadow.
Return
bool
void SetContentView(scoped_refptr<View> view)
Set the content view of the window.
The content view will always be resized to fill window's client area.
Parameters
scoped_refptr<View>
view
View* GetContentView() const
Return the content view of the window.
Return
View*
void Center()
Move the window to the center of the screen.
void SetContentSize(const SizeF& size)
Resize window to make the content view fit size
.
Parameters
const SizeF&
size
SizeF GetContentSize() const
Return the size of content view.
Return
SizeF
void SetBounds(const RectF& bounds)
Change the position and size of the window.
Parameters
const RectF&
bounds
RectF GetBounds() const
Return the position and size of the window.
Return
RectF
void SetSizeConstraints(const SizeF& minsize, const SizeF& maxsize)
Set the minimum and maximum sizes of the window.
Passing an empty size means no constraint.
Parameters
const SizeF&
minsize - Minimum size.const SizeF&
maxsize - Maximum size.
std::tuple<SizeF, SizeF> GetSizeConstraints() const
Return minimum and maximum sizes of the window.
Return
std::tuple<SizeF, SizeF>
void SetContentSizeConstraints(const SizeF& minsize, const SizeF& maxsize)
Set the minimum and maximum content sizes of the window.
Passing an empty size means no constraint.
Parameters
const SizeF&
minsize - Minimum content size.const SizeF&
maxsize - Maximum content size.
std::tuple<SizeF, SizeF> GetContentSizeConstraints() const
Return minimum and maximum content sizes of the window.
Return
std::tuple<SizeF, SizeF>
void Activate()
Show the window and activate it.
void Deactivate()
Move the focus away from the window.
bool IsActive() const
Return whether window has focus.
Return
bool
void SetVisible(bool visible)
Show/hide the window.
Parameters
bool
visible
bool IsVisible() const
Return whether window is visible.
Return
bool
void SetAlwaysOnTop(bool top)
Make the window always show above other normal windows.
Parameters
bool
top
bool IsAlwaysOnTop() const
Return whether window is always above other normal windows.
Return
bool
void SetFullscreen(bool fullscreen)
Enter/leave fullscreen state.
Parameters
bool
fullscreen
bool IsFullscreen() const
Return whether window is in fullscreen.
Return
bool
void Maximize()
Maximize the window.
void Unmaximize()
Unmaximize the window.
bool IsMaximized() const
Return whether window is maximized.
Return
bool
void Minimize()
Minimize the window.
void Restore()
Restore the minimized window.
bool IsMinimized() const
Return whether window is minimized.
Return
bool
void SetResizable(bool resizable)
Set whether window can be resized.
Parameters
bool
resizable
bool IsResizable() const
Return whether window can be resized.
Return
bool
void SetMaximizable(bool maximizable)
Set whether window can be maximize.
Parameters
bool
maximizable
bool IsMaximizable() const
Return whether window can be maximize.
Return
bool
void SetMinimizable(bool minimizable)
Set whether window can be minimized.
Parameters
bool
minimizable
bool IsMinimizable() const
Return whether window can be minimized.
Return
bool
void SetMovable(bool movable)
Set whether window can be moved.
Parameters
bool
movable
bool IsMovable() const
Return whether window can be moved.
Return
bool
void SetTitle(const std::string& title)
Set window title.
Parameters
const std::string&
title
std::string GetTitle() const
Get window title.
Return
std::string
void SetBackgroundColor(Color color)
Set the background color of the window.
Parameters
Color
color
float GetScaleFactor() const
Return the scale factor of the window.
Return
float
macOS
void SetToolbar(scoped_refptr<Toolbar> toolbar)Set the window toolbar.
Parameters
scoped_refptr<Toolbar>
toolbar
macOS
Toolbar* GetToolbar() constReturn the window toolbar.
Return
Toolbar*
macOS
void SetTitleVisible(bool visible)Set whether the title is visible, when title was hidden the toolber would be moved into the area previously occupied by the title.
Parameters
bool
visible
macOS
bool IsTitleVisible() const;Return whether title is visible.
Return
bool
macOS
void SetFullSizeContentView(bool full)Set the NSWindowStyleMaskFullSizeContentView
style on the window.
Parameters
bool
full
macOS
bool IsFullSizeContentView() constReturn whether the window has NSWindowStyleMaskFullSizeContentView
style.
Return
bool
Windows Linux
void SetSkipTaskbar(bool skip)Set whether to hide the window from taskbar.
Parameters
bool
skip
Windows Linux
void SetIcon(scoped_refptr<Image> icon)Set the window icon.
Parameters
scoped_refptr<Image>
icon
Windows Linux
void SetMenuBar(scoped_refptr<MenuBar> menubar)Set the window menu bar.
Parameters
scoped_refptr<MenuBar>
menubar
Windows Linux
MenuBar* GetMenuBar() constReturn the window menu bar.
Return
MenuBar*
Windows Linux
void SetMenuBarVisible(bool visible)Set whether the window menu bar is visible.
The accelerators of menu items will still work when menu bar is hidden.
Calling SetMenu
will reset the menu bar to visible.
Parameters
bool
visible
Windows
HWND GetHWND() constReturn the HWND of the native window.
Return
HWND
Window* GetParentWindow() const
Return the parent window.
Return
Window*
void AddChildWindow(scoped_refptr<Window> child)
Make child
a child window of this window.
This method will do nothing if child
already has a parent window.
Parameters
scoped_refptr<Window>
child
void RemoveChildWindow(Window* child)
Remove this window as child
's parent window.
Parameters
Window*
child
std::vector<Window*> GetChildWindows() const
Return all the child windows of this window.
Return
std::vector<Window*>
Events
void on_close(Window* self)
Emitted when the window is closed.
Parameters
Window*
self
Preventable
No.void on_focus(Window* self)
Emitted when the window is focused.
Parameters
Window*
self
Preventable
No.void on_blur(Window* self)
Emitted when the window lost focus.
Parameters
Window*
self
Preventable
No.Delegates
bool should_close(Window* self)
Called when user requests to close the window, should return whether the window can be closed.
Parameters
Window*
self
Return
bool