如何自定义 App Designer 图形的背景?
How to customize the background of an App Designer figure?
我想附加一个徽标或更改 App Designer 的整个背景 uifigure
。如何做到这一点?
如果要为整个图形设置纯色背景,存在a documented way可以做到这一点,例如:
% When creating a new uifigure:
fig = uifigure('Color',[R G B])
% if the uifigure already exists:
fig.Color = [R G B];
- 如果您只想更改某个区域的背景颜色,您可以添加一个没有标题或边框的
uipanel
(uipanel(...,'BorderType','none','Title','','BackgroundColor',[R G B])
)。
如果要设置一张图片作为整幅图的背景:
function q41602238a
%% Turn off some warnings:
warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
%% 0. Create a uifigure:
app = uifigure();
%% 1. Get a handle to the webwindow:
while true
try
win = struct(struct(app).Controller).Container.CEF;
break
catch
pause(0.1); % Give the figure (webpage) some more time to load
end
end
%% 2. Find the data_tag of the DOM element we want to edit:
data_tag = char(struct(app).Controller.ProxyView.PeerNode.getId);
%% 3. Manipulate the DOM via a JS command
while true
try
win.executeJS(['dojo.style(dojo.query("[data-tag^=''' data_tag ''']")[0],"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']);
break
catch
pause(0.1); % Maybe JS is still not ready.
end
end
结果:
如果您想将图像设置为某个区域的背景:
function q41602238b
%% Turn off some warnings:
warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
%% 0. Create a some element:
app = uifigure();
pnl = uipanel(app);
%% 1. Get a handle to the webwindow:
while true
try
win = struct(struct(app).Controller).Container.CEF;
% disp(win.URL);
break
catch
pause(0.1); % Give the figure (webpage) some more time to load
end
end
%% 2. Find the id of the DOM element we want to edit:
data_tag = char(struct(pnl).Controller.ProxyView.PeerNode.getId);
widgetId = win.executeJS(['dojo.getAttr(dojo.query("[data-tag^=''' data_tag ''']")[0],"widgetid")']);
%% 3. Manipulate the DOM via a JS command
dojo_style_prefix = ['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],'];
while true
try
win.executeJS([dojo_style_prefix '"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']);
break
catch
pause(0.1); % Maybe JS is still not ready.
end
end
结果:
备注:
很遗憾我还不能发表评论,所以这是另一个答案。
从 Matlab 2017a 开始,控制器不再有容器 属性。这有效:
warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
win = struct(struct(struct(app).Controller).PlatformHost).CEF;
data_tag = char(struct(app).Controller.ProxyView.PeerNode.getId);
win.executeJS(['dojo.style(dojo.query("[data-tag^=''' data_tag ''']")[0],"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']);
也可以使用
找到所有活跃的网站window
webWindows = matlab.internal.webwindowmanager.instance.findAllWebwindows();
可惜我还没有查到,哪个window属于哪个UIFigure(可以用Title或者Position来过滤,但是两个相同的UIFigure会出问题)。
免责声明,Davide Miani 在此处发布了该信息:https://undocumentedmatlab.com/blog/customizing-uifigures-part-1#comment-406524
我想附加一个徽标或更改 App Designer 的整个背景 uifigure
。如何做到这一点?
如果要为整个图形设置纯色背景,存在a documented way可以做到这一点,例如:
% When creating a new uifigure: fig = uifigure('Color',[R G B]) % if the uifigure already exists: fig.Color = [R G B];
- 如果您只想更改某个区域的背景颜色,您可以添加一个没有标题或边框的
uipanel
(uipanel(...,'BorderType','none','Title','','BackgroundColor',[R G B])
)。 如果要设置一张图片作为整幅图的背景:
function q41602238a %% Turn off some warnings: warning off Matlab:structOnObject warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame %% 0. Create a uifigure: app = uifigure(); %% 1. Get a handle to the webwindow: while true try win = struct(struct(app).Controller).Container.CEF; break catch pause(0.1); % Give the figure (webpage) some more time to load end end %% 2. Find the data_tag of the DOM element we want to edit: data_tag = char(struct(app).Controller.ProxyView.PeerNode.getId); %% 3. Manipulate the DOM via a JS command while true try win.executeJS(['dojo.style(dojo.query("[data-tag^=''' data_tag ''']")[0],"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']); break catch pause(0.1); % Maybe JS is still not ready. end end
结果:
如果您想将图像设置为某个区域的背景:
function q41602238b %% Turn off some warnings: warning off Matlab:structOnObject warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame %% 0. Create a some element: app = uifigure(); pnl = uipanel(app); %% 1. Get a handle to the webwindow: while true try win = struct(struct(app).Controller).Container.CEF; % disp(win.URL); break catch pause(0.1); % Give the figure (webpage) some more time to load end end %% 2. Find the id of the DOM element we want to edit: data_tag = char(struct(pnl).Controller.ProxyView.PeerNode.getId); widgetId = win.executeJS(['dojo.getAttr(dojo.query("[data-tag^=''' data_tag ''']")[0],"widgetid")']); %% 3. Manipulate the DOM via a JS command dojo_style_prefix = ['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],']; while true try win.executeJS([dojo_style_prefix '"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']); break catch pause(0.1); % Maybe JS is still not ready. end end
结果:
备注:
很遗憾我还不能发表评论,所以这是另一个答案。
从 Matlab 2017a 开始,控制器不再有容器 属性。这有效:
warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
win = struct(struct(struct(app).Controller).PlatformHost).CEF;
data_tag = char(struct(app).Controller.ProxyView.PeerNode.getId);
win.executeJS(['dojo.style(dojo.query("[data-tag^=''' data_tag ''']")[0],"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']);
也可以使用
找到所有活跃的网站windowwebWindows = matlab.internal.webwindowmanager.instance.findAllWebwindows();
可惜我还没有查到,哪个window属于哪个UIFigure(可以用Title或者Position来过滤,但是两个相同的UIFigure会出问题)。
免责声明,Davide Miani 在此处发布了该信息:https://undocumentedmatlab.com/blog/customizing-uifigures-part-1#comment-406524