public override void InitElements() { base.InitElements(); if (_isInit) { return; } Window.SetBackground(60, 60, 60); Label _name = new Label(); _name.SetFont(DefaultsService.GetDefaultFont(FontStyle.Bold, 28)); _name.SetText("My Albums"); _name.SetMargin(0, 0, 0, 0); _name.SetMargin(0, 25, 0, 0); _name.SetPadding(10, 10, 10, 0); _name.SetHeightPolicy(SizePolicy.Fixed); _name.SetHeight(70); _albumList.SetSelectionVisible(false); _albumList.SetVScrollBarPolicy(VisibilityPolicy.AsNeeded); _albumList.SetHScrollBarPolicy(VisibilityPolicy.Never); _albumList.SetBackground(Color.Transparent); _albumList.SetMargin(10, 100, 10, 50); _albumList.VScrollBar.SetStyle(Style.GetSimpleVerticalScrollBarStyle()); Style style = new Style(); style.Background = Color.Transparent; style.Foreground = Color.Black; style.Font = DefaultsService.GetDefaultFont(); style.SetSizePolicy(SizePolicy.Fixed, SizePolicy.Fixed); style.SetSize(40, 40); style.SetAlignment(ItemAlignment.Right, ItemAlignment.Bottom); style.SetTextAlignment(ItemAlignment.Right, ItemAlignment.Bottom); style.SetPadding(4, 4, 4, 4); style.SetMargin(0, 0, 10, 10); style.SetSpacing(0, 0); style.SetBorder(new Border(Color.Transparent, new CornerRadius(20), 0)); style.AddItemState(ItemStateType.Hovered, new ItemState(Color.FromArgb(100, 255, 255, 255))); style.AddItemState(ItemStateType.Pressed, new ItemState(Color.FromArgb(100, 0, 0, 0))); _addButton.SetStyle(style); CustomShape plus = new CustomShape(GraphicsMathService.GetCross(30, 30, 4, 0)); plus.SetAlignment(ItemAlignment.HCenter, ItemAlignment.VCenter); plus.SetBackground(100, 100, 100); plus.SetSizePolicy(SizePolicy.Expand, SizePolicy.Expand); AddItems( _name, _albumList, _addButton ); _addButton.AddItem(plus); _addButton.EventMouseClick += (sender, args) => { Hide(); OpenEntryDialog browse = new OpenEntryDialog("Open Folder:", FileSystemEntryType.Directory, OpenDialogType.Open); browse.OnCloseDialog += () => { if (browse.GetResult() == null || browse.GetResult().Equals(String.Empty)) { Show(); return; } Album album = new Album(new DirectoryInfo(browse.GetResult()).Name, browse.GetResult()); AddAlbum(album); album.OnDoubleClick += (s) => { Hide(); Model.FillImageArea(GetHandler(), _area, _preview, (s as Album).GetPath()); }; }; browse.Show(GetHandler()); }; if (_list.Count > 0) { foreach (Album item in _list) { _albumList.AddItem(item); item._expand.EventToggle += (sender, args) => { _albumList.GetWrapper(item).UpdateSize(); _albumList.GetArea().UpdateLayout(); }; } } _isInit = true; }
public override void InitWindow() { SetParameters(nameof(MainWindow), nameof(MainWindow), 1240, 750, false); IsCentered = true; var icon = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("SimpleImageViewer.Resources.icon.png")); TitleBar title = new TitleBar("Simple Image Viewer - C#"); title.SetIcon(icon, 24, 24); title.SetPadding(4, 0, 5, 0); Frame layout = new Frame(); layout.SetMargin(0, title.GetHeight(), 0, 0); layout.SetPadding(0, 0, 0, 0); layout.SetSpacing(6); layout.SetBackground(60, 60, 60); VerticalStack vToolbar = new VerticalStack(); vToolbar.SetWidthPolicy(SizePolicy.Fixed); vToolbar.SetWidth(30); vToolbar.SetBackground(32, 32, 32); vToolbar.SetPadding(0, 30, 0, 0); HorizontalSplitArea splitArea = new HorizontalSplitArea(); splitArea.SetMargin(vToolbar.GetWidth(), 0, 0, 0); splitArea.SetSplitThickness(5); imageArea = new WrapGrid(160, 120, Orientation.Horizontal); imageArea.SetBackground(Color.Transparent); imageArea.SetPadding(15, 6, 6, 6); imageArea.GetArea().SetSpacing(6, 6); imageArea.VScrollBar.SetStyle(Style.GetSimpleVerticalScrollBarStyle()); imageArea.SetStretch(true); previewArea = new PreviewArea(imageArea); side = new AlbumSideList(this, Side.Left, imageArea, previewArea); side.SetAreaSize(400); Album defaultAlbum = new Album("MyPictures", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + Path.DirectorySeparatorChar + "Pictures"); defaultAlbum.OnDoubleClick += (sender) => { side.Hide(); Model.FillImageArea(this, imageArea, previewArea, (sender as Album).GetPath()); }; side.AddAlbum(defaultAlbum); ButtonCore btnSideAreaShow = new ButtonCore(); btnSideAreaShow.SetStyle(CustomStyles.GetButtonStyle()); ButtonCore btnOpenFolder = new ButtonCore(); btnOpenFolder.SetStyle(CustomStyles.GetButtonStyle()); ButtonCore btnAddAlbum = new ButtonCore(); btnAddAlbum.SetStyle(CustomStyles.GetButtonStyle()); //adding AddItems( title, layout ); layout.AddItems( vToolbar, splitArea ); splitArea.AssignTopItem(previewArea); splitArea.AssignBottomItem(imageArea); splitArea.SetSplitPosition(300); vToolbar.AddItems( btnSideAreaShow, btnOpenFolder, btnAddAlbum ); btnSideAreaShow.AddItem(new ImageItem(DefaultsService.GetDefaultImage(EmbeddedImage.Lines, EmbeddedImageSize.Size32x32), false)); btnOpenFolder.AddItem(new ImageItem(DefaultsService.GetDefaultImage(EmbeddedImage.Folder, EmbeddedImageSize.Size32x32), false)); btnAddAlbum.AddItem(new ImageItem(DefaultsService.GetDefaultImage(EmbeddedImage.Import, EmbeddedImageSize.Size32x32), false)); //events EventDrop += (sender, args) => { if (side.IsHide) { if (File.GetAttributes(args.Paths[0]).HasFlag(FileAttributes.Directory)) { Model.FillImageArea(this, imageArea, previewArea, args.Paths[0]); } } else { foreach (String path in args.Paths) { if (File.GetAttributes(path).HasFlag(FileAttributes.Directory)) { Album album = new Album(new DirectoryInfo(path).Name, path); side.AddAlbum(album); album.OnDoubleClick += (s) => { side.Hide(); Model.FillImageArea(this, imageArea, previewArea, (s as Album).GetPath()); }; } } } }; btnSideAreaShow.EventMouseClick += (sender, args) => { side.Show(); }; btnOpenFolder.EventMouseClick += (sender, args) => { OpenEntryDialog browse = new OpenEntryDialog("Open Folder:", FileSystemEntryType.Directory, OpenDialogType.Open); browse.OnCloseDialog += () => { Model.FillImageArea(this, imageArea, previewArea, browse.GetResult()); }; browse.Show(this); }; imageArea.EventScrollUp += (sender, args) => { if (args.Mods.HasFlag(KeyMods.Control)) { int w = imageArea.GetCellWidth() + 8; int h = imageArea.GetCellHeight() + 6; if (w > 400) { return; } imageArea.SetCellSize(w, h); } }; imageArea.EventScrollDown += (sender, args) => { if (args.Mods.HasFlag(KeyMods.Control)) { int w = imageArea.GetCellWidth() - 8; int h = imageArea.GetCellHeight() - 6; if (w < 160) { return; } imageArea.SetCellSize(w, h); } }; btnAddAlbum.EventMouseClick += (sender, args) => { OpenEntryDialog browse = new OpenEntryDialog("Open Folder:", FileSystemEntryType.Directory, OpenDialogType.Open); browse.OnCloseDialog += () => { if (browse.GetResult() == null || browse.GetResult() == String.Empty) { return; } Album album = new Album(new DirectoryInfo(browse.GetResult()).Name, browse.GetResult()); side.AddAlbum(album); album.OnDoubleClick += (s) => { side.Hide(); Model.FillImageArea(this, imageArea, previewArea, (s as Album).GetPath()); }; }; browse.Show(this); }; EventOnStart += () => { Model.FillImageArea(this, imageArea, previewArea, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + Path.DirectorySeparatorChar + "Pictures"); }; }