001package polaris.sdk.ui.samples;
002
003import polaris.sdk.ui.*;
004import polaris.sdk.ui.controls.*;
005
006/** Optional standalone hosts for the reusable example scenes. No remote service is contacted. */
007public final class SampleWindows {
008 private SampleWindows(){}
009 /** Run all six examples with the scene selector; accepts --frames=N, --screenshot=PATH, --light and --grid. */
010 public static void gallery(String[] args)throws Exception{run(-1,args);}
011 /** Run a single app scene: food, chat, client, music, settings or files. */
012 public static void run(String sceneId,String[] args)throws Exception{run(SceneExamples.indexOf(sceneId),args);}
013 private static void run(int selected,String[] args)throws Exception{
014  DesktopWindow.Options options=new DesktopWindow.Options();options.title="LiquidGlass / "+(selected<0?"场景示例":SceneExamples.TITLES[selected]);options.width=1180;options.height=820;
015  for(String arg:args){if(arg.equals("--grid"))options.grid=true;else if(arg.equals("--light"))options.light=true;else if(arg.equals("--no-animation"))options.animate=false;
016   else if(arg.startsWith("--frames=")){options.frames=Integer.parseInt(arg.substring(9));if(options.frames<1)throw new IllegalArgumentException("frames must be positive");}
017   else if(arg.startsWith("--screenshot="))options.screenshot=arg.substring(13);else throw new IllegalArgumentException("Unknown sample argument: "+arg);
018  }
019  if(options.screenshot!=null&&options.frames==0)options.frames=18;
020  DesktopWindow.run(options,ui->{
021   final SceneExamples selector=selected<0?new SceneExamples():null;
022   final SceneSupport.AppScene app=selected<0?null:create(selected);
023   Panel body=new Panel(){@Override protected void layoutChildren(){Widget child=selector!=null?selector:app;float need=app!=null?app.preferredHeight(w):child.height();child.bounds(0,0,w,need);h=child.height();}};
024   body.glass(false).padding(0).clipChildren(false);body.add(selector!=null?selector:app);body.bounds(0,0,1100,900);
025   ScrollPane viewport=new ScrollPane();viewport.glass(false).padding(Spacing.INSET).gap(0).layout(Panel.Layout.COLUMN);viewport.add(body);ui.root().add(viewport);
026   Button material=new Button("LiquidGlass 设置");GlassSettingsDialog dialog=new GlassSettingsDialog();material.onClick(v->dialog.open(ui));ui.root().add(material);
027   Label label=new Label("本地交互示例 / 使用同一套图形库控件").size(12);ui.root().add(label);
028   if(selector!=null)selector.onChange(v->viewport.scroll(0));
029   Runnable layout=()->{viewport.bounds(12,62,Math.max(0,ui.width()-24),Math.max(0,ui.height()-74));material.bounds(ui.width()-208,16,180,34);label.bounds(28,20,Math.max(0,ui.width()-270),28);};ui.onResize=layout;layout.run();
030  });
031 }
032 private static SceneSupport.AppScene create(int index){switch(index){case 0:return new FoodScene();case 1:return new ChatScene();case 2:return new ClientScene();case 3:return new MusicScene();case 4:return new SettingsScene();case 5:return new FilesScene();default:throw new IllegalArgumentException("scene");}}
033}