Thu, 12 Oct 2023 16:03:35 +0200
add icons (WinUI3)
make/vs/testapp/main.c | file | annotate | diff | comparison | revisions | |
ui/winui/button.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/commandbar.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/icons.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/icons.h | file | annotate | diff | comparison | revisions | |
ui/winui/stock.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/stock.h | file | annotate | diff | comparison | revisions | |
ui/winui/toolkit.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/window.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/winui.vcxproj | file | annotate | diff | comparison | revisions | |
ui/winui/winui.vcxproj.filters | file | annotate | diff | comparison | revisions |
--- a/make/vs/testapp/main.c Thu Oct 12 14:09:04 2023 +0200 +++ b/make/vs/testapp/main.c Thu Oct 12 16:03:35 2023 +0200 @@ -275,7 +275,7 @@ ui_menuitem(.label = "Exit"); } - ui_toolbar_item("Test", .label = "Test", .onclick = action_toolbar_button); + ui_toolbar_item("Test", .label = "Home", .icon = "Home", .onclick = action_toolbar_button); ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button); ui_toolbar_toggleitem("Toggle2", .label = "Toggle2", .onchange = action_toolbar_button); ui_toolbar_toggleitem("Toggle3", .label = "Toggle3", .onchange = action_toolbar_button);
--- a/ui/winui/button.cpp Thu Oct 12 14:09:04 2023 +0200 +++ b/ui/winui/button.cpp Thu Oct 12 16:03:35 2023 +0200 @@ -32,6 +32,7 @@ #include "util.h" #include "container.h" +#include "icons.h" #include "../common/object.h" #include "../common/context.h"
--- a/ui/winui/commandbar.cpp Thu Oct 12 14:09:04 2023 +0200 +++ b/ui/winui/commandbar.cpp Thu Oct 12 16:03:35 2023 +0200 @@ -36,6 +36,7 @@ #include "button.h" #include "appmenu.h" +#include "icons.h" using namespace winrt; using namespace Microsoft::UI::Xaml; @@ -131,6 +132,9 @@ button.Label(wlabel); free(wlabel); } + if(item->args.icon) { + button.Icon(ui_get_icon(item->args.icon)); + } // register callback if (item->args.onclick) { @@ -157,6 +161,9 @@ button.Label(wlabel); free(wlabel); } + if (item->args.icon) { + button.Icon(ui_get_icon(item->args.icon)); + } UiVar* var = uic_widget_var(obj->ctx, obj->ctx, nullptr, item->args.varname, UI_VAR_INTEGER); if (var) { @@ -192,6 +199,9 @@ button.Label(wlabel); free(wlabel); } + if (item->args.icon) { + button.Icon(ui_get_icon(item->args.icon)); + } MenuFlyoutItem mi = MenuFlyoutItem();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/icons.cpp Thu Oct 12 16:03:35 2023 +0200 @@ -0,0 +1,254 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "pch.h" + +#include "icons.h" + +#include <stdlib.h> +#include <string.h> + + +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Interop; +using namespace winrt::Windows::Foundation; +using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; + + +std::unordered_map<std::string, Symbol> ui_symbol_icons = { + {"Accept", Symbol::Accept }, + {"Account", Symbol::Account }, + {"Add", Symbol::Add }, + {"AddFriend", Symbol::AddFriend }, + {"Admin", Symbol::Admin }, + {"AlignCenter", Symbol::AlignCenter }, + {"AlignLeft", Symbol::AlignLeft }, + {"AlignRight", Symbol::AlignRight }, + {"AllApps", Symbol::AllApps }, + {"Attach", Symbol::Attach }, + {"AttachCamera", Symbol::AttachCamera }, + {"Audio", Symbol::Audio }, + {"Back", Symbol::Back }, + {"BackToWindow", Symbol::BackToWindow }, + {"BlockContact", Symbol::BlockContact }, + {"Bold", Symbol::Bold }, + {"Bookmarks", Symbol::Bookmarks }, + {"BrowsePhotos", Symbol::BrowsePhotos }, + {"Bullets", Symbol::Bullets }, + {"Calculator", Symbol::Calculator }, + {"Calendar", Symbol::Calendar }, + {"CalendarDay", Symbol::CalendarDay }, + {"CalendarReply", Symbol::CalendarReply }, + {"CalendarWeek", Symbol::CalendarWeek }, + {"Camera", Symbol::Camera }, + {"Cancel", Symbol::Cancel }, + {"Caption", Symbol::Caption }, + {"CellPhone", Symbol::CellPhone }, + {"Character", Symbol::Character }, + {"Clear", Symbol::Clear }, + {"ClearSelection", Symbol::ClearSelection }, + {"Clock", Symbol::Clock }, + {"ClosedCaption", Symbol::ClosedCaption }, + {"ClosePane", Symbol::ClosePane }, + {"Comment", Symbol::Comment }, + {"Contact", Symbol::Contact }, + {"Contact2", Symbol::Contact2 }, + {"ContactInfo", Symbol::ContactInfo }, + {"ContactPresence", Symbol::ContactPresence }, + {"Copy", Symbol::Copy }, + {"Crop", Symbol::Crop }, + {"Cut", Symbol::Cut }, + {"Delete", Symbol::Delete }, + {"Directions", Symbol::Directions }, + {"DisableUpdates", Symbol::DisableUpdates }, + {"DisconnectDrive", Symbol::DisconnectDrive }, + {"Dislike", Symbol::Dislike }, + {"DockBottom", Symbol::DockBottom }, + {"DockLeft", Symbol::DockLeft }, + {"DockRight", Symbol::DockRight }, + {"Document", Symbol::Document }, + {"Download", Symbol::Download }, + {"Edit", Symbol::Edit }, + {"Emoji", Symbol::Emoji }, + {"Emoji2", Symbol::Emoji2 }, + {"Favorite", Symbol::Favorite }, + {"Filter", Symbol::Filter }, + {"Find", Symbol::Find }, + {"Flag", Symbol::Flag }, + {"Folder", Symbol::Folder }, + {"Font", Symbol::Font }, + {"FontColor", Symbol::FontColor }, + {"FontDecrease", Symbol::FontDecrease }, + {"FontIncrease", Symbol::FontIncrease }, + {"FontSize", Symbol::FontSize }, + {"Forward", Symbol::Forward }, + {"FourBars", Symbol::FourBars }, + {"FullScreen", Symbol::FullScreen }, + {"GlobalNavigationButton", Symbol::GlobalNavigationButton }, + {"Globe", Symbol::Globe }, + {"Go", Symbol::Go }, + {"GoToStart", Symbol::GoToStart }, + {"GoToToday", Symbol::GoToToday }, + {"HangUp", Symbol::HangUp }, + {"Help", Symbol::Help }, + {"HideBcc", Symbol::HideBcc }, + {"Highlight", Symbol::Highlight }, + {"Home", Symbol::Home }, + {"Import", Symbol::Import }, + {"ImportAll", Symbol::ImportAll }, + {"Important", Symbol::Important }, + {"Italic", Symbol::Italic }, + {"Keyboard", Symbol::Keyboard }, + {"LeaveChat", Symbol::LeaveChat }, + {"Library", Symbol::Library }, + {"Like", Symbol::Like }, + {"LikeDislike", Symbol::LikeDislike }, + {"Link", Symbol::Link }, + {"List", Symbol::List }, + {"Mail", Symbol::Mail }, + {"MailFilled", Symbol::MailFilled }, + {"MailForward", Symbol::MailForward }, + {"MailReply", Symbol::MailReply }, + {"MailReplyAll", Symbol::MailReplyAll }, + {"Manage", Symbol::Manage }, + {"Map", Symbol::Map }, + {"MapDrive", Symbol::MapDrive }, + {"MapPin", Symbol::MapPin }, + {"Memo", Symbol::Memo }, + {"Message", Symbol::Message }, + {"Microphone", Symbol::Microphone }, + {"More", Symbol::More }, + {"MoveToFolder", Symbol::MoveToFolder }, + {"MusicInfo", Symbol::MusicInfo }, + {"Mute", Symbol::Mute }, + {"NewFolder", Symbol::NewFolder }, + {"NewWindow", Symbol::NewWindow }, + {"Next", Symbol::Next }, + {"OneBar", Symbol::OneBar }, + {"OpenFile", Symbol::OpenFile }, + {"OpenLocal", Symbol::OpenLocal }, + {"OpenPane", Symbol::OpenPane }, + {"OpenWith", Symbol::OpenWith }, + {"Orientation", Symbol::Orientation }, + {"OtherUser", Symbol::OtherUser }, + {"OutlineStar", Symbol::OutlineStar }, + {"Page", Symbol::Page }, + {"Page2", Symbol::Page2 }, + {"Paste", Symbol::Paste }, + {"Pause", Symbol::Pause }, + {"People", Symbol::People }, + {"Permissions", Symbol::Permissions }, + {"Phone", Symbol::Phone }, + {"PhoneBook", Symbol::PhoneBook }, + {"Pictures", Symbol::Pictures }, + {"Pin", Symbol::Pin }, + {"Placeholder", Symbol::Placeholder }, + {"Play", Symbol::Play }, + {"PostUpdate", Symbol::PostUpdate }, + {"Preview", Symbol::Preview }, + {"PreviewLink", Symbol::PreviewLink }, + {"Previous", Symbol::Previous }, + {"Print", Symbol::Print }, + {"Priority", Symbol::Priority }, + {"ProtectedDocument", Symbol::ProtectedDocument }, + {"Read", Symbol::Read }, + {"Redo", Symbol::Redo }, + {"Refresh", Symbol::Refresh }, + {"Remote", Symbol::Remote }, + {"Remove", Symbol::Remove }, + {"Rename", Symbol::Rename }, + {"Repair", Symbol::Repair }, + {"RepeatAll", Symbol::RepeatAll }, + {"RepeatOne", Symbol::RepeatOne }, + {"ReportHacked", Symbol::ReportHacked }, + {"ReShare", Symbol::ReShare }, + {"Rotate", Symbol::Rotate }, + {"RotateCamera", Symbol::RotateCamera }, + {"Save", Symbol::Save }, + {"SaveLocal", Symbol::SaveLocal }, + {"Scan", Symbol::Scan }, + {"SelectAll", Symbol::SelectAll }, + {"Send", Symbol::Send }, + {"SetLockScreen", Symbol::SetLockScreen }, + {"SetTile", Symbol::SetTile }, + {"Setting", Symbol::Setting }, + {"Share", Symbol::Share }, + {"Shop", Symbol::Shop }, + {"ShowBcc", Symbol::ShowBcc }, + {"ShowResults", Symbol::ShowResults }, + {"Shuffle", Symbol::Shuffle }, + {"SlideShow", Symbol::SlideShow }, + {"SolidStar", Symbol::SolidStar }, + {"Sort", Symbol::Sort }, + {"Stop", Symbol::Stop }, + {"StopSlideShow", Symbol::StopSlideShow }, + {"Street", Symbol::Street }, + {"Switch", Symbol::Switch }, + {"SwitchApps", Symbol::SwitchApps }, + {"Sync", Symbol::Sync }, + {"SyncFolder", Symbol::SyncFolder }, + {"Tag", Symbol::Tag }, + {"Target", Symbol::Target }, + {"ThreeBars", Symbol::ThreeBars }, + {"TouchPointer", Symbol::TouchPointer }, + {"Trim", Symbol::Trim }, + {"TwoBars", Symbol::TwoBars }, + {"TwoPage", Symbol::TwoPage }, + {"Underline", Symbol::Underline }, + {"Undo", Symbol::Undo }, + {"UnFavorite", Symbol::UnFavorite }, + {"UnPin", Symbol::UnPin }, + {"UnSyncFolder", Symbol::UnSyncFolder }, + {"Up", Symbol::Up }, + {"Upload", Symbol::Upload }, + {"Video", Symbol::Video }, + {"VideoChat", Symbol::VideoChat }, + {"View", Symbol::View }, + {"ViewAll", Symbol::ViewAll }, + {"Volume", Symbol::Volume }, + {"WebCam", Symbol::WebCam }, + {"World", Symbol::World }, + {"XboxOneConsole", Symbol::XboxOneConsole }, + {"ZeroBars", Symbol::ZeroBars }, + {"Zoom", Symbol::Zoom }, + {"ZoomIn", Symbol::ZoomIn }, + {"ZoomOut", Symbol::ZoomOut } +}; + +winrt::Microsoft::UI::Xaml::Controls::IconElement ui_get_icon(const char* name) { + if (ui_symbol_icons.find(name) == ui_symbol_icons.end()) { + SymbolIcon no_icon = { nullptr }; + return no_icon; + } + + Symbol symbol = ui_symbol_icons[name]; + SymbolIcon icon = SymbolIcon(symbol); + return icon; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/icons.h Thu Oct 12 16:03:35 2023 +0200 @@ -0,0 +1,41 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "../ui/toolkit.h" + +struct UiIcon { + winrt::Microsoft::UI::Xaml::Controls::IconElement icon; +}; + +void ui_init_symbol_icons(); + +void ui_add_symbol_icon(std::string name, winrt::Microsoft::UI::Xaml::Controls::Symbol symbol); + +winrt::Microsoft::UI::Xaml::Controls::IconElement ui_get_icon(const char* name);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/stock.cpp Thu Oct 12 16:03:35 2023 +0200 @@ -0,0 +1,5 @@ + + +#include "pch.h" + +#include "stock.h" \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/stock.h Thu Oct 12 16:03:35 2023 +0200 @@ -0,0 +1,32 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "../ui/stock.h" +
--- a/ui/winui/toolkit.cpp Thu Oct 12 14:09:04 2023 +0200 +++ b/ui/winui/toolkit.cpp Thu Oct 12 16:03:35 2023 +0200 @@ -36,6 +36,8 @@ #include "../common/context.h" #include "../common/toolbar.h" +#include "icons.h" + #include "MainWindow.xaml.h" #include "App.xaml.h"
--- a/ui/winui/window.cpp Thu Oct 12 14:09:04 2023 +0200 +++ b/ui/winui/window.cpp Thu Oct 12 16:03:35 2023 +0200 @@ -43,6 +43,7 @@ #include "MainWindow.xaml.h" + using namespace winrt; using namespace Microsoft::UI::Xaml; using namespace Microsoft::UI::Xaml::Controls;
--- a/ui/winui/winui.vcxproj Thu Oct 12 14:09:04 2023 +0200 +++ b/ui/winui/winui.vcxproj Thu Oct 12 16:03:35 2023 +0200 @@ -131,6 +131,7 @@ <ClInclude Include="button.h" /> <ClInclude Include="commandbar.h" /> <ClInclude Include="container.h" /> + <ClInclude Include="icons.h" /> <ClInclude Include="list.h" /> <ClInclude Include="pch.h" /> <ClInclude Include="App.xaml.h"> @@ -139,6 +140,7 @@ <ClInclude Include="MainWindow.xaml.h"> <DependentUpon>MainWindow.xaml</DependentUpon> </ClInclude> + <ClInclude Include="stock.h" /> <ClInclude Include="table.h" /> <ClInclude Include="text.h" /> <ClInclude Include="toolkit.h" /> @@ -154,6 +156,7 @@ <ClCompile Include="button.cpp" /> <ClCompile Include="commandbar.cpp" /> <ClCompile Include="container.cpp" /> + <ClCompile Include="icons.cpp" /> <ClCompile Include="list.cpp" /> <ClCompile Include="pch.cpp"> <PrecompiledHeader>Create</PrecompiledHeader> @@ -165,6 +168,7 @@ <DependentUpon>MainWindow.xaml</DependentUpon> </ClCompile> <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" /> + <ClCompile Include="stock.cpp" /> <ClCompile Include="table.cpp" /> <ClCompile Include="text.cpp" /> <ClCompile Include="toolkit.cpp" />
--- a/ui/winui/winui.vcxproj.filters Thu Oct 12 14:09:04 2023 +0200 +++ b/ui/winui/winui.vcxproj.filters Thu Oct 12 16:03:35 2023 +0200 @@ -23,6 +23,8 @@ <ClCompile Include="toolkit.cpp" /> <ClCompile Include="util.cpp" /> <ClCompile Include="window.cpp" /> + <ClCompile Include="stock.cpp" /> + <ClCompile Include="icons.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="pch.h" /> @@ -87,6 +89,8 @@ <ClInclude Include="..\ui\window.h"> <Filter>public</Filter> </ClInclude> + <ClInclude Include="stock.h" /> + <ClInclude Include="icons.h" /> </ItemGroup> <ItemGroup> <Image Include="Assets\Wide310x150Logo.scale-200.png">