2 Commits

Author SHA1 Message Date
睿 安
9fe2fe5874 text控件:新增光标后插入;新增可控边界 2026-01-27 14:45:32 +08:00
睿 安
1be1ecbbf2 使用双窗口 2026-01-26 18:36:55 +08:00
42 changed files with 672 additions and 106 deletions

View File

@@ -44,4 +44,7 @@ function(add_resource_package TARGET_NAME INPUT_DIR OUTPUT_FILE)
endfunction()
#添加子项目
#add_subdirectory(./demo) # 暂时注释掉,只编译库
option(BUILD_DEMO "Build demo projects" ON)
if(BUILD_DEMO)
add_subdirectory(./demo)
endif()

View File

@@ -177,12 +177,14 @@
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="loginForm.h" />
<ClInclude Include="mainForm.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DemoUi.cpp" />
<ClCompile Include="loginForm.cpp" />
<ClCompile Include="mainForm.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>

View File

@@ -27,6 +27,9 @@
<ClInclude Include="loginForm.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="mainForm.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DemoUi.cpp">
@@ -38,6 +41,9 @@
<ClCompile Include="loginForm.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="mainForm.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="small.ico">

Binary file not shown.

View File

@@ -7,7 +7,6 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
Application app(hInstance);
app.EnableHighDpi();//启用高DPI
//创建登录创建
loginForm loginFrm;
loginFrm.Show();

Binary file not shown.

View File

@@ -1,12 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by DemoUi.rc
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// DemoUi.rc 使用
//
#define IDD_INPUT 102
#define IDC_EDIT1 1000
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD>ֵ
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101

View File

@@ -3,7 +3,6 @@
#include <windows.h>
#include "ezui/Application.h" //app类
#include "EzUI/Window.h" //基础窗口类
#include "EzUI/Button.h" //按钮
@@ -18,4 +17,5 @@
#include "EzUI/TileListView.h"//瓦片列表
#include "EzUI/LayeredWindow.h"//分层窗口类-可以异型透明窗口
#include "ezui/UIManager.h"//ui管理类(使用xml生成控件)
#include "EzUI/Animation.h"

View File

@@ -1,5 +1,6 @@
#include "pch.h"
#include "pch.h"
#include "loginForm.h"
#include "mainForm.h"
void loginForm::OnNotify(Control* sender, EventArgs& args)
{
@@ -8,22 +9,31 @@ void loginForm::OnNotify(Control* sender, EventArgs& args)
TextBox* editUser = (TextBox*)FindControl("user");
TextBox* editpwd = (TextBox*)FindControl("pwd");
CheckBox* ckbox = (CheckBox*)FindControl("ckbox");
if (!ckbox->GetCheck()) {
::MessageBoxW(Hwnd(), L"<EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD>ѡ!", L"<EFBFBD><EFBFBD>ʾ", MB_OK);
/*if (!ckbox->GetCheck()) {
::MessageBoxW(Hwnd(), L"请阅读协议并勾选!", L"提示", MB_OK);
return;
}
}*/
UIString user = editUser->GetText();
UIString pwd = editpwd->GetText();
if (user == "718987717" && pwd == "123456") {
::MessageBoxW(Hwnd(), L"<EFBFBD><EFBFBD>¼<EFBFBD>ɹ<EFBFBD>!", L"<EFBFBD><EFBFBD>ʾ", MB_OK);
}
else {
::MessageBoxW(Hwnd(), L"<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", L"<EFBFBD><EFBFBD>ʾ", MB_OK);
}
Hide(); // 隐藏登录窗口
static mainForm mainForm;
mainForm.Show(); // 显示主界面
//if (user == "ad" && pwd == "123") {
// ::MessageBoxW(Hwnd(), L"登录成功!", L"提示", MB_OK);
// Hide(); // 隐藏登录窗口
// static mainForm mainForm;
// mainForm.Show(); // 显示主界面
//}
//else {
// ::MessageBoxW(Hwnd(), L"用户名或密码错误!", L"提示", MB_OK);
//}
}
if (sender->Name == "btnExit") {
Application::Exit();
}
// 打开链接
if (!sender->GetAttribute("url").empty()) {
::ShellExecuteA(0, "open", sender->GetAttribute("url").c_str(), "", "", SW_SHOW);
}
@@ -38,7 +48,7 @@ void loginForm::OnClose(bool& close)
loginForm::loginForm() :LayeredWindow(320, 448)
{
umg.LoadXml("res/loginForm.htm");//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>xml<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀؼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
umg.LoadXml("res/loginForm.htm");//加载xml里面的控件与样式
umg.SetupUI(this);
}

View File

@@ -1,21 +1,21 @@
#pragma once
#pragma once
#include "pch.h"
using namespace ezui;
using Form = LayeredWindow; //֧<><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>Ӱ)
//using Form = BorderlessWindow; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޱ߿򴰿<EFBFBD>(<28><><EFBFBD><EFBFBD>Ӱ)
//using Form = Window; //<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
//using Form = LayeredWindow; //支持异形透明窗口(带阴影)
//using Form = BorderlessWindow; //常规无边框窗口(带阴影)
//using Form = Window; //标准窗口(带系统标题栏)
// <EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class loginForm :public Form
// 登陆窗口
class loginForm :public LayeredWindow
{
private:
//ui<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ui管理类
UIManager umg;
protected:
virtual void OnNotify(Control* sender, EventArgs& args)override;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>֪ͨ
virtual void OnClose(bool& close)override;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹرյ<EFBFBD>ʱ<EFBFBD><EFBFBD>
virtual void OnNotify(Control* sender, EventArgs& args)override;//重载事件通知
virtual void OnClose(bool& close)override;//当窗口关闭的时候
public:
loginForm();
virtual ~loginForm();

View File

@@ -0,0 +1,96 @@
#include "pch.h"
#include "mainForm.h"
void mainForm::OnNotify(Control* sender, EventArgs& args)
{
UIString btnName = sender->Name; // 控件id
Event eventType = args.EventType; // 事件类型
switch (eventType)
{
case ezui::OnMouseDown: //鼠标按下
{
if (btnName == "btnExitMain") { //退出
int result = ::MessageBoxW(Hwnd(), L"要退出程序吗?", L"提示", MB_YESNO | MB_ICONQUESTION);
if (result == IDYES)
exit(0);
}
else if (btnName == "btnMinMain") { //最小化
this->ShowMinimized();
}
else if (btnName == "btnMaxMain") { //最大化|还原
if (this->IsMaximized()) {
this->ShowNormal();
// 修改控件文字
Button* btnMax = (Button*)FindControl("btnMaxMain");
btnMax->SetText(L"🗖");
}
else {
this->ShowMaximized();
// 修改控件文字
Button* btnMax = (Button*)FindControl("btnMaxMain");
btnMax->SetText(L"🗗");
}
}
else if (btnName == "btnAdmin") { //到管理页面 获取 mainTab 设置页面为0
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
mainTab->SetPageIndex(0);
mainTab->Invalidate();
}
else if (btnName == "btnTools") { //到工具页面 获取 mainTab 设置页面为1
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
mainTab->SetPageIndex(1);
mainTab->Invalidate();
}
else if (btnName == "btnAdminConnect") { //管理页面的连接按钮按下,先获取 btnAdminConnect 按钮,设置为不可用,修改文字为“连接中...”
Button* btnAdminConnect = (Button*)FindControl("btnAdminConnect");
btnAdminConnect->SetText(L"🔄");
btnAdminConnect->Style.BackColor = Color(0, 185, 107);
}
else if (btnName == "btnAdminTemp") { //管理页面的测试按钮
TextBox* textAdmin = (TextBox*)FindControl("textAdminOutput"); //获取输出框
//textAdmin->Insert(L"\n测试成功", true);
if (textAdmin) {
textAdmin->Insert(L"\n测试成功!",true);
}
}
}
break;
case ezui::OnMouseDoubleClick: //鼠标双击
{
//if (btnName == "titleMain") { //标题布局
// if (this->IsMaximized()) {
// this->ShowNormal();
// }
// else {
// this->ShowMaximized();
// }
//}
}
break;
default:
break;
}
if (args.EventType == Event::OnMouseDown) {
}
__super::OnNotify(sender, args);
}
void mainForm::OnClose(bool& close)
{
Application::Exit();
}
mainForm::mainForm() :LayeredWindow(1000, 750)
{
SetResizable(true); // 启用窗口大小调整
SetMiniSize(Size(600, 450)); // 设置最小尺寸
umg.LoadXml("res/mainForm.htm");//加载xml里面的控件与样式
umg.SetupUI(this);
}
mainForm::~mainForm()
{
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "pch.h"
using namespace ezui;
// 主窗口
class mainForm :public LayeredWindow
{
private:
//ui管理类
UIManager umg;
protected:
virtual void OnNotify(Control* sender, EventArgs& args)override;//重载事件通知
virtual void OnClose(bool& close)override;//当窗口关闭的时候
public:
mainForm();
virtual ~mainForm();
};

View File

@@ -1 +1 @@
#include "pch.h"
#include "pch.h"

View File

@@ -1,2 +1,2 @@
#pragma once
#pragma once
#include "framework.h"

View File

@@ -39,12 +39,17 @@ namespace ezui {
std::wstring m_placeholder;//placeholder懂得都懂 (在没有文字的情况下显示的文字)
std::wstring m_passwordChar;
bool m_readOnly = false;//是否只读
// 内边距(四边独立)
int m_padLeft = 6;
int m_padTop = 4;
int m_padRight = 6;
int m_padBottom = 4;
public:
//文字对其方式(针对单行输入框有效)
TextAlign TextAlign = TextAlign::MiddleLeft;
private:
void Init();
void InsertUnicode(const std::wstring& str);//插入unicode文字内部使用
void InsertUnicode(const std::wstring& str, bool isEnd = false);//插入unicode文字内部使用
bool DeleteRange();//删除选中内容
bool GetSelectedRange(int* outPos, int* outCount);//获取当前被选中的区域 返回下标和个数
bool Copy();//复制到剪切板
@@ -69,18 +74,24 @@ namespace ezui {
virtual void OnKillFocus(const KillFocusEventArgs& arg) override;
virtual void OnLayout();
void Offset(int moveY);
// 支持 TextBox 自身扩展样式属性padding 系列)
virtual bool ApplyStyleProperty(const UIString& key, const UIString& value) override;
public:
std::function<void(const UIString&)> TextChanged = NULL;
public:
TextBox(Object* parentObject = NULL);
virtual ~TextBox();
// 设置内边距 (兼容旧接口:水平=px, 垂直=py)
void SetPadding(int px, int py);
// 设置四边
void SetPadding4(int left, int top, int right, int bottom);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
//获取焦点所在光标位置
virtual Rect GetCareRect()override;
//分析字符串
void Analysis();
//在当前光标中插入文字
void Insert(const UIString& str);
void Insert(const UIString& str, bool isEnd = false);
//获取输入框文字
const UIString GetText();
//获取滚动条

View File

@@ -24,6 +24,7 @@ file(GLOB src ./ResPackage/*.*)
add_executable(ResPackage WIN32 ${src} )
target_include_directories(ResPackage PRIVATE ${include})
target_link_libraries(ResPackage PRIVATE EzUI)
set_property(TARGET ResPackage PROPERTY FOLDER "demo")
#仿QQ登录界面

BIN
demo/QQ/QQ.APS Normal file

Binary file not shown.

195
demo/QQ/QQ.vcxproj Normal file
View File

@@ -0,0 +1,195 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}</ProjectGuid>
<RootNamespace>QQ</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>EZUI_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>EZUI_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>EZUI_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>EZUI_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="loginForm.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="mainForm.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="loginForm.h" />
<ClInclude Include="mainForm.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="QQ.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="res\head.png" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="loginForm.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="mainForm.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="loginForm.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="mainForm.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="QQ.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\head.png">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
</Project>

4
demo/QQ/QQ.vcxproj.user Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@@ -1,4 +1,5 @@
#include "loginForm.h"
#include "loginForm.h"
#include "mainForm.h"
LoginForm::LoginForm() :LayeredWindow(320, 448)
{
@@ -19,7 +20,10 @@ void LoginForm::OnNotify(Control* sender, EventArgs& args)
UIString user = editUser->GetText();
UIString pwd = editpwd->GetText();
if (user == "718987717" && pwd == "123456") {
::MessageBox(Hwnd(), L"登录成功!", L"提示", MB_OK);
// 登录成功,跳转到主界面
Hide(); // 隐藏登录窗口
static MainForm mainForm;
mainForm.Show(); // 显示主界面
}
else {
::MessageBox(Hwnd(), L"用户名或密码错误!", L"提示", MB_OK);

View File

@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "ezui/Application.h" //app类
#include "EzUI/Window.h" //基础窗口类
#include "EzUI/Button.h" //按钮
@@ -14,7 +14,6 @@
#include "EzUI/LayeredWindow.h"//分层窗口类-可以异型透明窗口
#include "ezui/UIManager.h"//ui管理类(使用xml生成控件)
#pragma comment(lib,"ezui.lib")
using namespace ezui;
using Form = LayeredWindow; //支持异形透明窗口(带阴影)

38
demo/QQ/mainForm.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include "mainForm.h"
void MainForm::OnNotify(Control* sender, EventArgs& args)
{
if (args.EventType == Event::OnMouseDown) {
if (sender->Name == "btnMin") {
SendMessage(Hwnd(), WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
else if (sender->Name == "btnMax") {
if (IsZoomed(Hwnd())) {
SendMessage(Hwnd(), WM_SYSCOMMAND, SC_RESTORE, 0);
}
else {
SendMessage(Hwnd(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
else if (sender->Name == "btnClose") {
Close();
}
}
__super::OnNotify(sender, args);
}
void MainForm::OnClose(bool& close)
{
Application::Exit();
}
MainForm::MainForm() : LayeredWindow(800, 600)
{
SetText(L"QQ主界面");
umg.LoadXml("res/mainForm.htm");
umg.SetupUI(this);
}
MainForm::~MainForm()
{
}

35
demo/QQ/mainForm.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include "ezui/Application.h" //app类
#include "EzUI/Window.h" //基础窗口类
#include "EzUI/Button.h" //按钮
#include "EzUI/TextBox.h" //文本框
#include "EzUI/CheckBox.h" //复选框
#include "EzUI/PictureBox.h" //图片控件
#include "EzUI/TabLayout.h" //选项卡控件
#include "EzUI/VLayout.h" //垂直布局
#include "EzUI/HLayout.h"//水平布局
#include "EzUI/VListView.h"//垂直带滚动条列表
#include "EzUI/HListView.h"//水平带滚动条列表
#include "EzUI/TileListView.h"//瓦片列表
#include "EzUI/LayeredWindow.h"//分层窗口类-可以异型透明窗口
#include "ezui/UIManager.h"//ui管理类(使用xml生成控件)
#include "EzUI/LayeredWindow.h"
#include "EzUI/Label.h"
#include "EzUI/VLayout.h"
#include "EzUI/HLayout.h"
#include "EzUI/UIManager.h"
using namespace ezui;
// 主界面
class MainForm : public LayeredWindow
{
private:
UIManager umg;
protected:
virtual void OnNotify(Control* sender, EventArgs& args) override;
virtual void OnClose(bool& close) override;
public:
MainForm();
virtual ~MainForm();
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 772 KiB

After

Width:  |  Height:  |  Size: 244 KiB

18
demo/QQ/res/mainForm.htm Normal file
View File

@@ -0,0 +1,18 @@
<vlayout id="mainLayout" action="move">
<!-- 标题栏 -->
<hbox height="20" margin-top="5" action="move">
<spacer></spacer>
<!-- 退出按钮 -->
<button id="btnExitMain" size="20,20" style="background-image: url(res/close.png)"></button>
<spacer width="10"></spacer>
</hbox>
</vlayout>
<style>
#mainLayout {
background-color: #E8F0FF;
font-size: 14px;
}
</style>

Binary file not shown.

View File

@@ -39,12 +39,17 @@ namespace ezui {
std::wstring m_placeholder;//placeholder懂得都懂 (在没有文字的情况下显示的文字)
std::wstring m_passwordChar;
bool m_readOnly = false;//是否只读
// 内边距(四边独立)
int m_padLeft = 6;
int m_padTop = 4;
int m_padRight = 6;
int m_padBottom = 4;
public:
//文字对其方式(针对单行输入框有效)
TextAlign TextAlign = TextAlign::MiddleLeft;
private:
void Init();
void InsertUnicode(const std::wstring& str);//插入unicode文字内部使用
void InsertUnicode(const std::wstring& str, bool isEnd = false);//插入unicode文字内部使用
bool DeleteRange();//删除选中内容
bool GetSelectedRange(int* outPos, int* outCount);//获取当前被选中的区域 返回下标和个数
bool Copy();//复制到剪切板
@@ -69,18 +74,24 @@ namespace ezui {
virtual void OnKillFocus(const KillFocusEventArgs& arg) override;
virtual void OnLayout();
void Offset(int moveY);
// 支持 TextBox 自身扩展样式属性padding 系列)
virtual bool ApplyStyleProperty(const UIString& key, const UIString& value) override;
public:
std::function<void(const UIString&)> TextChanged = NULL;
public:
TextBox(Object* parentObject = NULL);
virtual ~TextBox();
// 设置内边距 (兼容旧接口:水平=px, 垂直=py)
void SetPadding(int px, int py);
// 设置四边
void SetPadding4(int left, int top, int right, int bottom);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
//获取焦点所在光标位置
virtual Rect GetCareRect()override;
//分析字符串
void Analysis();
//在当前光标中插入文字
void Insert(const UIString& str);
void Insert(const UIString& str, bool isEnd = false);
//获取输入框文字
const UIString GetText();
//获取滚动条

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -44,6 +44,45 @@ namespace ezui {
__super::OnRemove();
m_timer->Stop();
}
void TextBox::SetPadding(int px, int py) {
// 兼容旧接口:水平=px 垂直=py
SetPadding4(px, py, px, py);
}
void TextBox::SetPadding4(int left, int top, int right, int bottom) {
left = std::max(0, left); top = std::max(0, top); right = std::max(0, right); bottom = std::max(0, bottom);
if (m_padLeft != left || m_padTop != top || m_padRight != right || m_padBottom != bottom) {
m_padLeft = left; m_padTop = top; m_padRight = right; m_padBottom = bottom;
Analysis();
Invalidate();
}
}
bool TextBox::ApplyStyleProperty(const UIString& key, const UIString& value) {
// 先让基类尝试
if (__super::ApplyStyleProperty(key, value)) return true;
auto parseInt = [](const UIString& v)->int {
UIString tmp = v; ui_text::Replace(&tmp, "px", ""); tmp = tmp.trim();
return std::atoi(tmp.c_str());
};
// 新增:四边独立 & 兼容旧属性
if (key == "padding-left") { SetPadding4(parseInt(value), m_padTop, m_padRight, m_padBottom); return true; }
if (key == "padding-right") { SetPadding4(m_padLeft, m_padTop, parseInt(value), m_padBottom); return true; }
if (key == "padding-top") { SetPadding4(m_padLeft, parseInt(value), m_padRight, m_padBottom); return true; }
if (key == "padding-bottom") { SetPadding4(m_padLeft, m_padTop, m_padRight, parseInt(value)); return true; }
if (key == "padding-x") { int p = parseInt(value); SetPadding4(p, m_padTop, p, m_padBottom); return true; }
if (key == "padding-y") { int p = parseInt(value); SetPadding4(m_padLeft, p, m_padRight, p); return true; }
if (key == "padding") {
UIString v = value; ui_text::Replace(&v, " ", ","); auto arr = v.split(",");
if (arr.size() == 1) { int p = parseInt(arr[0]); SetPadding4(p, p, p, p); return true; }
if (arr.size() == 2) { // 兼容旧语义:水平 垂直
int px = parseInt(arr[0]); int py = parseInt(arr[1]); SetPadding4(px, py, px, py); return true; }
if (arr.size() == 3) { // CSS: top horizontal bottom
int pTop = parseInt(arr[0]); int pH = parseInt(arr[1]); int pBottom = parseInt(arr[2]); SetPadding4(pH, pTop, pH, pBottom); return true; }
if (arr.size() == 4) { // top right bottom left
int pTop = parseInt(arr[0]); int pRight = parseInt(arr[1]); int pBottom = parseInt(arr[2]); int pLeft = parseInt(arr[3]); SetPadding4(pLeft, pTop, pRight, pBottom); return true; }
return true; // 不合法也拦截
}
return false;
}
void TextBox::SetAutoWidth(bool flag)
{
//需要屏蔽
@@ -81,35 +120,29 @@ namespace ezui {
point2 = m_textLayout->HitTestTextPosition(m_A_TextPos, m_A_isTrailingHit);
point1 = m_textLayout->HitTestTextPosition(m_B_TextPos, m_B_isTrailingHit);
}
// 中心偏移用于 hit test 保证在行内
float offsetY = m_textLayout->GetFontHeight() / 2.0f;
point1.Y += offsetY;
point2.Y += offsetY;
// 获取每行矩形
// 为了稳定行判定,对基线 Y 加一个行高一半偏移放到行中部
float sampleY1 = point1.Y + m_textLayout->GetFontHeight() / 2.0f;
float sampleY2 = point2.Y + m_textLayout->GetFontHeight() / 2.0f;
auto lineRects = m_textLayout->GetLineRects();
for (auto& lr : lineRects) {
// 首行
if (point1.Y >= lr.Y && point1.Y <= lr.Y + lr.Height) {
if (point2.Y <= lr.Y + lr.Height) {
// 同一行
float width = std::max(0.0f, float(point2.X - point1.X));
bool firstLine = (sampleY1 >= lr.Y && sampleY1 < lr.Y + lr.Height + 0.5f);
bool lastLine = (sampleY2 >= lr.Y && sampleY2 < lr.Y + lr.Height + 0.5f);
if (firstLine && lastLine) { // 同一行
float leftX = point1.X;
float rightX = point2.X;
if (rightX < leftX) std::swap(leftX, rightX);
float width = std::max(0.0f, rightX - leftX);
m_selectRects.push_back(Rect(leftX, lr.Y, width, lr.Height));
}
else if (firstLine) { // 首行:到行尾
float width = std::max(0.0f, (lr.X + lr.Width) - point1.X);
m_selectRects.push_back(Rect(point1.X, lr.Y, width, lr.Height));
}
else {
// 跨行首行 从 point1 到行末
float width = std::max(0.0f, lr.X + lr.Width - point1.X);
m_selectRects.push_back(Rect(point1.X, lr.Y, width, lr.Height));
}
}
// 末行
else if (point2.Y >= lr.Y && point2.Y <= lr.Y + lr.Height) {
else if (lastLine) { // 末行:从行首
float width = std::max(0.0f, point2.X - lr.X);
m_selectRects.push_back(Rect(lr.X, lr.Y, width, lr.Height));
}
// 中间整行
else if (point1.Y < lr.Y && point2.Y > lr.Y + lr.Height) {
else if (sampleY1 < lr.Y && sampleY2 >= lr.Y + lr.Height) { // 中间整行
m_selectRects.push_back(lr);
}
}
@@ -166,12 +199,13 @@ namespace ezui {
}
return false;
}
void TextBox::InsertUnicode(const std::wstring& str) {
void TextBox::InsertUnicode(const std::wstring& str, bool isEnd) {
DeleteRange();//先删除是否有选中的区域
if (m_textPos < 0)m_textPos = 0;
if (m_textPos < 0) m_textPos = 0; // 处理光标位置
if (m_textPos > (int)m_text.size()) {
m_textPos = m_text.size();
}
if (isEnd) m_textPos = m_text.size(); // 是否让光标移到末尾
m_text.insert(m_textPos, str);
m_textPos += str.size();
if (TextChanged) {
@@ -336,35 +370,45 @@ namespace ezui {
*drawText = m_text;
}
// 可用绘制宽高(考虑内边距)
int innerW = std::max(0, Width() - (m_padLeft + m_padRight));
int innerH = std::max(0, Height() - (m_padTop + m_padBottom));
if (!m_multiLine) {//单行编辑框
m_font->Get()->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
bool bAlignLeft = (int(this->TextAlign) & int(HAlign::Left));
float width = bAlignLeft ? EZUI_FLOAT_MAX : Width();
m_textLayout = new TextLayout(*drawText, *m_font, SizeF{ width,(float)Height() }, this->TextAlign);
float width = bAlignLeft ? EZUI_FLOAT_MAX : (float)innerW;
m_textLayout = new TextLayout(*drawText, *m_font, SizeF{ width,(float)innerH }, this->TextAlign);
m_fontBox = m_textLayout->GetFontBox();
if (m_fontBox.Width < this->Width()) {
if (m_fontBox.Width < innerW) {
m_scrollX = 0;
}
if (!bAlignLeft && m_fontBox.Width > this->Width()) {
if (!bAlignLeft && m_fontBox.Width > innerW) {
ezui::TextAlign tmp = this->TextAlign;
tmp = ezui::TextAlign((int)tmp & ~(int)HAlign::Center);
tmp = ezui::TextAlign((int)tmp & ~(int)HAlign::Right);
tmp = ezui::TextAlign((int)tmp | (int)HAlign::Left);
m_textLayout->SetTextAlign(tmp);
}
if (m_fontBox.Width > this->Width() && m_scrollX + m_fontBox.Width < this->Width()) {
m_scrollX = this->Width() - m_fontBox.Width;
if (m_fontBox.Width > innerW && m_scrollX + m_fontBox.Width < innerW) {
m_scrollX = innerW - m_fontBox.Width;
}
}
else {//多行编辑框
m_font->Get()->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP);
m_textLayout = new TextLayout(*drawText, *m_font, SizeF{ (float)Width(),EZUI_FLOAT_MAX }, TextAlign::TopLeft);
m_textLayout = new TextLayout(*drawText, *m_font, SizeF{ (float)innerW, EZUI_FLOAT_MAX }, TextAlign::TopLeft);
m_fontBox = m_textLayout->GetFontBox();
}
if (drawText != &this->m_text) {
delete drawText;
}
// 内容尺寸:多行时加入 padding 以保证最后一行不被裁掉,单行保持原逻辑
if (m_multiLine) {
this->SetContentSize({ m_fontBox.Width + m_padLeft + m_padRight, m_fontBox.Height + m_padTop + m_padBottom });
}
else {
this->SetContentSize({ m_fontBox.Width , m_fontBox.Height });
}
if (m_multiLine) {
this->GetScrollBar()->RefreshScroll();
}
@@ -388,14 +432,26 @@ namespace ezui {
m_careRect.Width = 1 * this->GetScale();
if (!m_multiLine) {
//使光标一直在输入框内
int drawX = m_careRect.X + m_scrollX;
if (drawX < 0) {//光标在最左侧
m_scrollX -= drawX;
// 使光标保持在可视内区(考虑 padding
int innerW = std::max(0, Width() - (m_padLeft + m_padRight));
int caretDrawX = m_careRect.X + m_scrollX; // 布局坐标 + 滚动
if (caretDrawX < 0) { // 左越界
m_scrollX -= caretDrawX;
}
if (drawX > Width()) {//光标在最右侧
int ofssetX = (Width() - drawX);
m_scrollX += ofssetX;
if (caretDrawX > innerW) { // 右越界
int offsetX = innerW - caretDrawX;
m_scrollX += offsetX;
}
}
else { // 多行:处理垂直滚动保持光标可见
int innerH = std::max(0, Height() - (m_padTop + m_padBottom));
int caretDrawY = m_careRect.Y + m_scrollY; // 仅布局+滚动
if (caretDrawY < 0) {
m_scrollY -= caretDrawY;
}
int caretBottom = caretDrawY + m_careRect.Height;
if (caretBottom > innerH) {
m_scrollY -= (caretBottom - innerH);
}
}
@@ -432,18 +488,19 @@ namespace ezui {
{
__super::OnMouseWheel(arg);
if (!m_multiLine) {//单行
int innerW = std::max(0, Width() - (m_padLeft + m_padRight));
int textWidth = m_fontBox.Width;
if (arg.ZDelta > 0 && textWidth > Width()) {
if (arg.ZDelta > 0 && textWidth > innerW) {
m_scrollX += std::abs(arg.ZDelta) * 0.5;
if (m_scrollX > 0) {
m_scrollX = 0;
}
Invalidate();
}
else if (arg.ZDelta<0 && textWidth>Width()) {
else if (arg.ZDelta<0 && textWidth>innerW) {
m_scrollX -= std::abs(arg.ZDelta) * 0.5;
if (-m_scrollX + Width() > textWidth) {
m_scrollX = -(textWidth - Width());
if (-m_scrollX + innerW > textWidth) {
m_scrollX = -(textWidth - innerW);
}
Invalidate();
}
@@ -479,9 +536,10 @@ namespace ezui {
}
Point TextBox::ConvertPoint(const Point& pt) {
int _x = -m_scrollX;
int _y = -m_scrollY;
return Point{ pt.X + _x,pt.Y + _y };
// 将控件坐标转换为文本布局坐标:去掉滚动与内边距偏移
int _x = -m_scrollX - m_padLeft;
int _y = -m_scrollY - m_padTop;
return Point{ pt.X + _x, pt.Y + _y };
}
void TextBox::OnMouseMove(const MouseEventArgs& arg)
@@ -498,23 +556,24 @@ namespace ezui {
BuildSelectedRect();
if (!m_multiLine) {//单行
//当鼠标往左侧移动
// 计算去掉左 padding 的鼠标相对文本区域坐标
int innerW = std::max(0, Width() - (m_padLeft + m_padRight));
int textWidth = m_fontBox.Width;
if (m_lastX > point.X) {
int localX = point.X - m_padLeft; // 鼠标在文本可编辑区域内的 X
if (m_lastX > point.X) { // 向左拖
m_lastX = point.X;
if (textWidth > Width() && m_scrollX < 0 && point.X < 0) {
if (textWidth > innerW && m_scrollX < 0 && localX < 0) {
m_scrollX += 3;
Invalidate();
return;
}
}
//当鼠标往右侧移动
if (m_lastX < point.X) {
if (m_lastX < point.X) { // 向右拖
m_lastX = point.X;
if (textWidth > Width() && point.X > Width()) {
if (textWidth > innerW && localX > innerW) {
m_scrollX -= 3;
if (-m_scrollX + Width() > textWidth) {
m_scrollX = -(textWidth - Width());
if (-m_scrollX + innerW > textWidth) {
m_scrollX = -(textWidth - innerW);
}
Invalidate();
return;
@@ -593,19 +652,24 @@ namespace ezui {
Rect TextBox::GetCareRect()
{
Rect rect(m_careRect);
rect.X += m_scrollX;//偏移
rect.Y += m_scrollY;
rect.X += m_scrollX + m_padLeft; // 滚动 + padding
rect.Y += m_scrollY + m_padTop;
return rect;
}
void TextBox::Insert(const UIString& str)
void TextBox::Insert(const UIString& str, bool isEnd)
{
InsertUnicode(str.unicode());
InsertUnicode(str.unicode(), isEnd);
Analysis();//分析字符串
}
void TextBox::SetAttribute(const UIString& key, const UIString& value) {
__super::SetAttribute(key, value);
do
{
if (key == "padding" || key == "padding-x" || key == "padding-y") {
// 走统一样式解析,直接调用 ApplyStyleProperty
ApplyStyleProperty(key, value);
break;
}
if (key == "valign") {
this->TextAlign = ezui::TextAlign((int)this->TextAlign & ~(int)VAlign::Top);
this->TextAlign = ezui::TextAlign((int)this->TextAlign & ~(int)VAlign::Mid);
@@ -688,7 +752,8 @@ namespace ezui {
Color placeholderColor = fontColor;
placeholderColor.SetA(fontColor.GetA() * 0.6);
e.Graphics.SetColor(placeholderColor);
e.Graphics.DrawString(m_placeholder, RectF(0, 0, (float)Width(), (float)Height()), m_multiLine ? TextAlign::TopLeft : this->TextAlign);
RectF ph((float)m_padLeft, (float)m_padTop, (float)Width() - (float)(m_padLeft + m_padRight), (float)Height() - (float)(m_padTop + m_padBottom));
e.Graphics.DrawString(m_placeholder, ph, m_multiLine ? TextAlign::TopLeft : this->TextAlign);
}
}
@@ -699,8 +764,8 @@ namespace ezui {
for (auto& it : m_selectRects) {
if (!it.IsEmptyArea()) {
RectF rect(it);
rect.X += m_scrollX;//偏移
rect.Y += m_scrollY;
rect.X += m_scrollX + m_padLeft; // 加上内边距
rect.Y += m_scrollY + m_padTop;
e.Graphics.FillRectangle(rect);
}
}
@@ -708,17 +773,17 @@ namespace ezui {
if (m_textLayout) {
e.Graphics.SetColor(fontColor);
e.Graphics.DrawTextLayout(*m_textLayout, PointF{ (float)m_scrollX, (float)m_scrollY });
PointF base{ (float)m_scrollX + (float)m_padLeft, (float)m_scrollY + (float)m_padTop };
e.Graphics.DrawTextLayout(*m_textLayout, base);
}
if (!m_careRect.IsEmptyArea() && m_focus) {
if (m_bCareShow) {
RectF rect(m_careRect.X, m_careRect.Y, m_careRect.Width, m_careRect.Height);
RectF rect(m_careRect.X + m_padLeft, m_careRect.Y + m_padTop, m_careRect.Width, m_careRect.Height);
rect.X += m_scrollX;//偏移
rect.Y += m_scrollY;
if (ezui::IsFloatEqual(rect.X, this->Width())) {
//如果光标刚好在边框末尾
rect.X = this->Width() - rect.Width;
rect.X = this->Width() - rect.Width; //末尾微调
}
rect.Width = rect.Width * this->GetScale();
e.Graphics.SetColor(fontColor);